migration of code from ffasn1c to asn1c + asn1tostruct.py
diff --git a/src/asn1helpers.c b/src/asn1helpers.c
index fe886e3..436afa5 100644
--- a/src/asn1helpers.c
+++ b/src/asn1helpers.c
@@ -1,19 +1,45 @@
#include <string.h>
-#include <asn1defs.h>
+#include <osmocom/core/utils.h>
#include "asn1helpers.h"
-int asn1_strncpy(char *out, const ASN1String *in, size_t n)
+void asn1_u32_to_bitstring(BIT_STRING_t *bitstr, uint32_t *in)
+{
+ bitstr->buf = (uint8_t *) in;
+ bitstr->size = sizeof(uint32_t);
+ bitstr->bits_unused = 0;
+}
+
+
+int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n)
{
size_t cpylen = n;
- if (in->len < cpylen)
- cpylen = in->len;
+ if (in->size < cpylen)
+ cpylen = in->size;
strncpy(out, (char *)in->buf, cpylen);
out[n-1] = '\0';
return cpylen;
}
+
+uint16_t asn1str_to_u16(const OCTET_STRING_t *in)
+{
+ OSMO_ASSERT(in && in->size >= sizeof(uint16_t));
+ return *(uint16_t *)in->buf;
+}
+
+uint8_t asn1str_to_u8(const OCTET_STRING_t *in)
+{
+ OSMO_ASSERT(in && in->size >= sizeof(uint8_t));
+ return *(uint8_t *)in->buf;
+}
+
+uint32_t asn1bitstr_to_u32(const BIT_STRING_t *in)
+{
+ OSMO_ASSERT(in && in->size >= sizeof(uint32_t));
+ return *(uint32_t *)in->buf;
+}