diff options
author | Daniel Willmann <dwillmann@sysmocom.de> | 2015-11-27 17:53:19 +0100 |
---|---|---|
committer | Daniel Willmann <dwillmann@sysmocom.de> | 2015-11-27 17:53:19 +0100 |
commit | e3adf0edc3c0070337a85e448481c10f477c8d9c (patch) | |
tree | 018d244844275f7bf3b377c07751dff19c3ecfdc | |
parent | ea4c088e780a974b88acde66e16f9beb1aaf5adc (diff) |
asn1helpers: Fix asn1str_to_uX functions
The values are stored big-endian so convert them
-rw-r--r-- | src/asn1helpers.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/asn1helpers.c b/src/asn1helpers.c index e59d5a9..d04298f 100644 --- a/src/asn1helpers.c +++ b/src/asn1helpers.c @@ -55,7 +55,7 @@ int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n) uint16_t asn1str_to_u16(const OCTET_STRING_t *in) { OSMO_ASSERT(in && in->size >= sizeof(uint16_t)); - return *(uint16_t *)in->buf; + return ntohs(*(uint16_t *)in->buf); } uint8_t asn1str_to_u8(const OCTET_STRING_t *in) @@ -66,12 +66,14 @@ uint8_t asn1str_to_u8(const OCTET_STRING_t *in) uint32_t asn1bitstr_to_u32(const BIT_STRING_t *in) { - uint32_t ret = 0; + OSMO_ASSERT(in && in->size >= sizeof(uint32_t) && in->bits_unused == 0); - if (in->size < 4) - return 0; + return ntohl(*(uint32_t *)in->buf); +} - ret = *(uint32_t *)in->buf; +uint32_t asn1bitstr_to_u24(const BIT_STRING_t *in) +{ + OSMO_ASSERT(in && in->size >= 3 && in->bits_unused == 0); - return ret; + return *(uint32_t *)in->buf; } |