add oid and bitstring parsing and formatting to "generic" format string

routines, test them in t10.c
This commit is contained in:
leitner
2011-04-28 21:33:10 +00:00
parent e04ca78ff8
commit dae3ea8024
12 changed files with 181 additions and 50 deletions

19
fmt_asn1bitstring.c Normal file
View File

@@ -0,0 +1,19 @@
#include "asn1.h"
#include "byte.h"
/* like fmt_asn1string, but l is in BITS, not BYTES */
size_t fmt_asn1bitstring(char* dest,enum asn1_tagclass tc,enum asn1_tagtype tt,enum asn1_tag tag,const char* c,size_t l) {
size_t len;
size_t actuallen;
if (l>(size_t)-100) return (size_t)-1;
actuallen=1+(l+7)/8; /* add one octet to specify the unused bits in the last octet, and calculate octets needed */
len=fmt_asn1transparent(dest,tc,tt,tag,actuallen);
if (dest) {
if (l)
dest[len]=7-((l-1)%8);
else
dest[len]=0;
byte_copy(dest+len+1,actuallen-1,c);
}
return len+actuallen;
}