]> git.karo-electronics.de Git - karo-tx-linux.git/commit
X.509: Add an ASN.1 decoder
authorDavid Howells <dhowells@redhat.com>
Mon, 24 Sep 2012 16:11:16 +0000 (17:11 +0100)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 28 Sep 2012 05:14:55 +0000 (14:44 +0930)
commit788380fa26a6243e21285d58f26a20cdbd5d5cbf
tree64a169248187fc3207ee7d5b126e9103e2730d40
parent54ddd23d78bacad3a8b94c656576a1da0bbd9cde
X.509: Add an ASN.1 decoder

Add an ASN.1 BER/DER/CER decoder.  This uses the bytecode from the ASN.1
compiler in the previous patch to inform it as to what to expect to find in the
encoded byte stream.  The output from the compiler also tells it what functions
to call on what tags, thus allowing the caller to retrieve information.

The decoder is called as follows:

int asn1_decoder(const struct asn1_decoder *decoder,
 void *context,
 const unsigned char *data,
 size_t datalen);

The decoder argument points to the bytecode from the ASN.1 compiler.  context
is the caller's context and is passed to the action functions.  data and
datalen define the byte stream to be decoded.

Note that the decoder is currently limited to datalen being less than 64K.
This reduces the amount of stack space used by the decoder because ASN.1 is a
nested construct.  Similarly, the decoder is limited to a maximum of 10 levels
of constructed data outside of a leaf node also in an effort to keep stack
usage down.

These restrictions can be raised if necessary.

Signed-off-by: David Howells <dhowells@redhat.com>
include/linux/asn1_decoder.h [new file with mode: 0644]
lib/Makefile
lib/asn1_decoder.c [new file with mode: 0644]