aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-10-06 22:08:54 +0200
committerHarald Welte <laforge@gnumonks.org>2015-10-06 22:08:54 +0200
commit0bb126123983237ae578d14857777d0af0818105 (patch)
tree2cd1d5a0dddc7ecb4d2a873e26e029e964d81bb3
parent4dd16b96438585997940ce7a472e37782cb516e3 (diff)
add asn1_u24_to_bitstring()
Sometimes we have a native uint32_t, but we don't want to encode it to a 4-byte long ASN1 BITSTRING, but rather to one that is only 24 bits.
-rw-r--r--src/asn1helpers.c7
-rw-r--r--src/asn1helpers.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/src/asn1helpers.c b/src/asn1helpers.c
index 3082ddc..3225223 100644
--- a/src/asn1helpers.c
+++ b/src/asn1helpers.c
@@ -31,6 +31,13 @@ void asn1_u32_to_bitstring(BIT_STRING_t *bitstr, uint32_t *in)
bitstr->bits_unused = 0;
}
+void asn1_u24_to_bitstring(BIT_STRING_t *bitstr, uint32_t *in)
+{
+ bitstr->buf = (uint8_t *) in;
+ bitstr->size = 24/8;
+ bitstr->bits_unused = 0;
+}
+
int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n)
{
diff --git a/src/asn1helpers.h b/src/asn1helpers.h
index 75b00e2..17d0d89 100644
--- a/src/asn1helpers.h
+++ b/src/asn1helpers.h
@@ -6,6 +6,7 @@
#include "OCTET_STRING.h"
void asn1_u32_to_bitstring(BIT_STRING_t *bitstr, uint32_t *in);
+void asn1_u24_to_bitstring(BIT_STRING_t *bitstr, uint32_t *in);
int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n);
uint16_t asn1str_to_u16(const OCTET_STRING_t *in);
uint8_t asn1str_to_u8(const OCTET_STRING_t *in);