summaryrefslogblamecommitdiffstats
path: root/fmt_asn1tag.c
blob: b2bd1a0eea7cc11742529fe13c8ba0f832948213 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15














                                                                                           
#include "asn1.h"

/* write int in least amount of bytes, return number of bytes */
/* as used in ASN.1 tags */
size_t fmt_asn1tag(char* dest,enum asn1_tagclass tc,enum asn1_tagtype tt,unsigned long l) {
  /* encoding is either l%128 or (0x1f,...) */
  if (l<0x1f) {
    if (dest) *dest=(int)tc+(int)tt+(l&0x1f);
    return 1;
  }
  if (dest) {
    *dest=(int)tc+(int)tt+0x1f; ++dest;
  }
  return fmt_asn1tagint(dest,l)+1;
}