summaryrefslogtreecommitdiffstats
path: root/fmt_asn1bitstring.c
blob: 18df19d05906e20f242b3604392fbe19ef7ed368 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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;
}