aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDaniel Willmann <dwillmann@sysmocom.de>2015-12-07 17:18:56 +0100
committerDaniel Willmann <dwillmann@sysmocom.de>2015-12-07 17:18:56 +0100
commitf3685c2a131756feb8c4f502e9d162aeaa9eb2fb (patch)
tree7c6042c1effa456dc5a10d79e0ae28120950c86a /src
parent4aeef6c3c4c4aaf52ce894c840e2db4f1ca65a10 (diff)
asn1helpers: Add helper to convert u8/u16 to OCTET_STRING
Diffstat (limited to 'src')
-rw-r--r--src/asn1helpers.c13
-rw-r--r--src/asn1helpers.h2
2 files changed, 15 insertions, 0 deletions
diff --git a/src/asn1helpers.c b/src/asn1helpers.c
index 38907e1..f6378e6 100644
--- a/src/asn1helpers.c
+++ b/src/asn1helpers.c
@@ -41,6 +41,19 @@ void asn1_u24_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in)
bitstr->bits_unused = 0;
}
+void asn1_u16_to_str(OCTET_STRING_t *str, uint16_t *buf, uint16_t in)
+{
+ *buf = htons(in);
+ str->buf = (uint8_t *) buf;
+ str->size = sizeof(uint16_t);
+}
+
+void asn1_u8_to_str(OCTET_STRING_t *str, uint8_t *buf, uint8_t in)
+{
+ *buf = in;
+ str->buf = buf;
+ str->size = sizeof(uint8_t);
+}
int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n)
{
diff --git a/src/asn1helpers.h b/src/asn1helpers.h
index cb558da..124df79 100644
--- a/src/asn1helpers.h
+++ b/src/asn1helpers.h
@@ -7,6 +7,8 @@
void asn1_u32_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in);
void asn1_u24_to_bitstring(BIT_STRING_t *bitstr, uint32_t *buf, uint32_t in);
+void asn1_u16_to_str(OCTET_STRING_t *str, uint16_t *buf, uint16_t in);
+void asn1_u8_to_str(OCTET_STRING_t *str, uint8_t *buf, uint8_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);