Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
450 B

  1. #include "fmt.h"
  2. /* write int in least amount of bytes, return number of bytes */
  3. /* as used in ASN.1 DER tag */
  4. size_t fmt_asn1dertag(char* dest,unsigned long long l) {
  5. /* high bit says if more bytes are coming, lower 7 bits are payload; big endian */
  6. size_t n=0,i;
  7. unsigned long long t;
  8. for (t=l, n=1; t>0x7f; t>>=7) ++n;
  9. for (i=0; i<n; ++i) {
  10. if (dest) dest[n-i-1]=(char)(((i!=0)<<7) | (char)(l&0x7f));
  11. l>>=7;
  12. }
  13. return i;
  14. }