blob: 436afa51cea7a43d4d3ac804bb29c45ae3f77499 [file] [log] [blame]
Harald Welte30afef32015-08-30 12:28:29 +02001
2#include <string.h>
3
Harald Welte27f9c4a2015-08-30 22:47:18 +02004#include <osmocom/core/utils.h>
Harald Welte30afef32015-08-30 12:28:29 +02005
6#include "asn1helpers.h"
7
Harald Welte27f9c4a2015-08-30 22:47:18 +02008void asn1_u32_to_bitstring(BIT_STRING_t *bitstr, uint32_t *in)
9{
10 bitstr->buf = (uint8_t *) in;
11 bitstr->size = sizeof(uint32_t);
12 bitstr->bits_unused = 0;
13}
14
15
16int asn1_strncpy(char *out, const OCTET_STRING_t *in, size_t n)
Harald Welte30afef32015-08-30 12:28:29 +020017{
18 size_t cpylen = n;
19
Harald Welte27f9c4a2015-08-30 22:47:18 +020020 if (in->size < cpylen)
21 cpylen = in->size;
Harald Welte30afef32015-08-30 12:28:29 +020022
23 strncpy(out, (char *)in->buf, cpylen);
24 out[n-1] = '\0';
25
26 return cpylen;
27}
Harald Welte27f9c4a2015-08-30 22:47:18 +020028
29uint16_t asn1str_to_u16(const OCTET_STRING_t *in)
30{
31 OSMO_ASSERT(in && in->size >= sizeof(uint16_t));
32 return *(uint16_t *)in->buf;
33}
34
35uint8_t asn1str_to_u8(const OCTET_STRING_t *in)
36{
37 OSMO_ASSERT(in && in->size >= sizeof(uint8_t));
38 return *(uint8_t *)in->buf;
39}
40
41uint32_t asn1bitstr_to_u32(const BIT_STRING_t *in)
42{
43 OSMO_ASSERT(in && in->size >= sizeof(uint32_t));
44 return *(uint32_t *)in->buf;
45}