summaryrefslogtreecommitdiffstats
path: root/scan_asn1tag.c
diff options
context:
space:
mode:
authorSimon Rettberg2014-03-15 01:49:50 +0100
committerSimon Rettberg2014-03-15 01:49:50 +0100
commitbedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad (patch)
treec7d1995a09f6ed0c4e6873252e957d72f5d07d07 /scan_asn1tag.c
downloadldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.gz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.xz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.zip
Lean and mean initial commit
Not much functionality yet
Diffstat (limited to 'scan_asn1tag.c')
-rw-r--r--scan_asn1tag.c17
1 files changed, 17 insertions, 0 deletions
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;
+ }
+}