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 --- fmt_asn1bitstring.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 fmt_asn1bitstring.c (limited to 'fmt_asn1bitstring.c') diff --git a/fmt_asn1bitstring.c b/fmt_asn1bitstring.c new file mode 100644 index 0000000..18df19d --- /dev/null +++ b/fmt_asn1bitstring.c @@ -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; +} -- cgit v1.2.3-55-g7522