summaryrefslogtreecommitdiffstats
path: root/scan_asn1BITSTRING.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_asn1BITSTRING.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_asn1BITSTRING.c')
-rw-r--r--scan_asn1BITSTRING.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/scan_asn1BITSTRING.c b/scan_asn1BITSTRING.c
new file mode 100644
index 0000000..b42901a
--- /dev/null
+++ b/scan_asn1BITSTRING.c
@@ -0,0 +1,27 @@
+#include "asn1.h"
+
+size_t scan_asn1BITSTRING(const char* src,const char* max,const char** s,size_t* l) {
+ size_t tmp;
+ unsigned long tag;
+ enum asn1_tagclass tc;
+ enum asn1_tagtype tt;
+ if ((tmp=scan_asn1string(src,max,&tc,&tt,&tag,s,l)))
+ if (tc==UNIVERSAL && tt==PRIMITIVE && tag==BIT_STRING) {
+ unsigned char lastbyte;
+ if (*l==0 || /* length must be at least 1 because for bit strings, the first octet contains the number of unused bits in the last octet */
+ (unsigned char)(**s)>7) /* the number of unused bits in the last octet must not be negative and can be at most 7 */
+ return 0;
+ /* these are DER checks */
+ /* can't have unused bits if the length is 0 */
+ if (*l==1 && **s)
+ return 0;
+ /* now check if the unused bits are 0 */
+ lastbyte=(*s)[*l+1];
+ if (lastbyte & (0xff >> (8-**s)))
+ return 0;
+ *l=(*l-1)*8-(unsigned char)(**s);
+ ++*s;
+ return tmp;
+ }
+ return 0;
+}