From cf1406735ccbfa898066b34854dc7441e178c1c5 Mon Sep 17 00:00:00 2001 From: leitner Date: Tue, 15 Apr 2014 20:36:50 +0000 Subject: [PATCH] much shorter way to do the same thing --- scan/scan_asn1dertag.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/scan/scan_asn1dertag.c b/scan/scan_asn1dertag.c index 7c5e7c1..a003d14 100644 --- a/scan/scan_asn1dertag.c +++ b/scan/scan_asn1dertag.c @@ -2,25 +2,10 @@ size_t scan_asn1dertag(const char* src,size_t len,unsigned long long* length) { size_t n; - unsigned long long l; - unsigned int bits=0; - if (len==0) return 0; - { - unsigned int k=src[0]&0x7f; - if (!(src[0]&0x80)) { - *length=k; - return 1; - } - if (!(l=k)) return 0; // non-minimal encoding - while (k) { // count bits in leading byte - ++bits; - k>>=1; - } - bits=sizeof(l)*8-bits; - } - for (n=1; n>(sizeof(l)*8-7)) return 0; // catch integer overflow l=(l<<7) | (src[n]&0x7f); if (!(src[n]&0x80)) { *length=l; @@ -29,3 +14,4 @@ size_t scan_asn1dertag(const char* src,size_t len,unsigned long long* length) { } return 0; } +