make asn1bitstr_to_u32() work for sub-32bit bit-strings

IF the ASN1 Bit-string is only 24 bits or even less long,
we might still want to retrieve it as an uint32_t.
This commit is contained in:
Harald Welte 2015-10-06 22:08:10 +02:00
parent 77847ad020
commit 4dd16b9643
1 changed files with 10 additions and 2 deletions

View File

@ -59,6 +59,14 @@ uint8_t asn1str_to_u8(const OCTET_STRING_t *in)
uint32_t asn1bitstr_to_u32(const BIT_STRING_t *in)
{
OSMO_ASSERT(in && in->size >= sizeof(uint32_t));
return *(uint32_t *)in->buf;
uint32_t ret = 0;
int i;
for (i = 0; i < 4; i++) {
if (in->size < i)
break;
ret <<= 8;
ret |= in->buf[i];
}
return ret;
}