aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2016-02-02 16:38:40 +0100
committerDaniel Willmann <daniel@totalueberwachung.de>2016-02-16 12:10:36 +0100
commit95a112f75ab7154e375d9c407f233f95c826f2f3 (patch)
tree4b403fbd5278272246b4437ea1e43809bc1f83a6 /src
parent2d4f2bd91ce5724c9f1c3916dfa5b21c8f6e7fbc (diff)
Add helper functions for uint32_t in octet strings
Diffstat (limited to 'src')
-rw-r--r--src/asn1helpers.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/asn1helpers.c b/src/asn1helpers.c
index 25f4af4..638cdb6 100644
--- a/src/asn1helpers.c
+++ b/src/asn1helpers.c
@@ -90,6 +90,13 @@ int BIT_STRING_fromBuf(BIT_STRING_t *st, const uint8_t *str, unsigned int bit_le
return 0;
}
+void asn1_u32_to_str(OCTET_STRING_t *str, uint32_t *buf, uint32_t in)
+{
+ *buf = htonl(in);
+ str->buf = (uint8_t *) buf;
+ str->size = sizeof(uint32_t);
+}
+
void asn1_u16_to_str(OCTET_STRING_t *str, uint16_t *buf, uint16_t in)
{
*buf = htons(in);
@@ -117,6 +124,12 @@ int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n)
return cpylen;
}
+uint32_t asn1str_to_u32(const OCTET_STRING_t *in)
+{
+ OSMO_ASSERT(in && in->size == sizeof(uint32_t));
+ return ntohl(*(uint32_t *)in->buf);
+}
+
uint16_t asn1str_to_u16(const OCTET_STRING_t *in)
{
OSMO_ASSERT(in && in->size == sizeof(uint16_t));