summaryrefslogtreecommitdiffstats
path: root/fmt_asn1intpayload.c
diff options
context:
space:
mode:
Diffstat (limited to 'fmt_asn1intpayload.c')
-rw-r--r--fmt_asn1intpayload.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/fmt_asn1intpayload.c b/fmt_asn1intpayload.c
new file mode 100644
index 0000000..15e71ca
--- /dev/null
+++ b/fmt_asn1intpayload.c
@@ -0,0 +1,20 @@
+#include "asn1.h"
+
+size_t fmt_asn1intpayload(char* dest,unsigned long l) {
+ size_t needed=sizeof l,i,fixup;
+ for (i=1; i<needed; ++i) {
+ if (!(l>>(i*8)))
+ break;
+ }
+ fixup=(l>>((i-1)*8))&0x80 ? 1 : 0;
+ if (dest) {
+ size_t j=i;
+ if (fixup) *dest++=0;
+ while (j) {
+ --j;
+ *dest=(l>>(j*8))&0xff;
+ ++dest;
+ }
+ }
+ return i+fixup;
+}