From bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sat, 15 Mar 2014 01:49:50 +0100 Subject: Lean and mean initial commit Not much functionality yet --- scan_asn1tag.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 scan_asn1tag.c (limited to 'scan_asn1tag.c') diff --git a/scan_asn1tag.c b/scan_asn1tag.c new file mode 100644 index 0000000..acf0c57 --- /dev/null +++ b/scan_asn1tag.c @@ -0,0 +1,17 @@ +#include "asn1.h" + +size_t scan_asn1tag(const char* src,const char* max,enum asn1_tagclass* tc,enum asn1_tagtype* tt,unsigned long* tag) { + if (max<=src) return 0; + *tc=(*src&0xC0); + *tt=(*src&0x20); +/* The lower 5 bits are the tag, unless it's 0x1f, in which case the + * next bytes are the tag: always take the lower 7 bits; the last byte + * in the sequence is marked by a cleared high bit */ + if ((*src & 0x1f) == 0x1f) { + size_t res=scan_asn1tagint(src+1,max,tag); + return res+!!res; /* add 1 unless it's 0, then leave 0 */ + } else { + *tag=*src&0x1f; + return 1; + } +} -- cgit v1.2.3-55-g7522