asn1helpers: Add helper to convert u8/u16 to OCTET_STRING
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 @@
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);