asn1helpers: Add helper to convert u8/u16 to OCTET_STRING

This commit is contained in:
Daniel Willmann 2015-12-07 17:18:56 +01:00
parent 4aeef6c3c4
commit f3685c2a13
2 changed files with 15 additions and 0 deletions

View File

@ -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)
{

View File

@ -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);