2012-02-07 17:02:40 +00:00
|
|
|
#include "fmt.h"
|
|
|
|
|
|
|
|
/* write int in least amount of bytes, return number of bytes */
|
|
|
|
/* as used in ASN.1 DER tag */
|
|
|
|
size_t fmt_asn1dertag(char* dest,unsigned long long l) {
|
|
|
|
/* encoding is either l%128 or (0x80+number of bytes,bytes) */
|
|
|
|
size_t n=0,i;
|
|
|
|
unsigned long long t;
|
|
|
|
for (t=l, n=1; t>0x7f; t>>=7) ++n;
|
|
|
|
for (i=0; i<n; ++i) {
|
2014-03-14 00:25:09 +00:00
|
|
|
if (dest) dest[n-i-1]=(char)(((i!=0)<<7) | (char)(l&0x7f));
|
2012-02-07 17:02:40 +00:00
|
|
|
l>>=7;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|