From 0bb126123983237ae578d14857777d0af0818105 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Tue, 6 Oct 2015 22:08:54 +0200 Subject: 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. --- src/asn1helpers.c | 7 +++++++ src/asn1helpers.h | 1 + 2 files changed, 8 insertions(+) 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); -- cgit v1.2.3