blob: c2f8baed1de82a657e72e2051c7fd98f69a3f4b7 [file] [log] [blame]
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001/*-
2 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _OCTET_STRING_H_
6#define _OCTET_STRING_H_
7
8#include <asn_application.h>
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14typedef struct OCTET_STRING {
15 uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */
16 size_t size; /* Size of the buffer */
17
18 asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
19} OCTET_STRING_t;
20
21extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING;
22extern asn_TYPE_operation_t asn_OP_OCTET_STRING;
23
24asn_struct_free_f OCTET_STRING_free;
25asn_struct_print_f OCTET_STRING_print;
26asn_struct_print_f OCTET_STRING_print_utf8;
27asn_struct_compare_f OCTET_STRING_compare;
28ber_type_decoder_f OCTET_STRING_decode_ber;
29der_type_encoder_f OCTET_STRING_encode_der;
30xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */
31xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */
32xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */
33xer_type_encoder_f OCTET_STRING_encode_xer;
34xer_type_encoder_f OCTET_STRING_encode_xer_utf8;
35oer_type_decoder_f OCTET_STRING_decode_oer;
36oer_type_encoder_f OCTET_STRING_encode_oer;
37per_type_decoder_f OCTET_STRING_decode_uper;
38per_type_encoder_f OCTET_STRING_encode_uper;
39per_type_decoder_f OCTET_STRING_decode_aper;
40per_type_encoder_f OCTET_STRING_encode_aper;
41asn_random_fill_f OCTET_STRING_random_fill;
42
43#define OCTET_STRING_constraint asn_generic_no_constraint
44#define OCTET_STRING_decode_xer OCTET_STRING_decode_xer_hex
45
46/******************************
47 * Handy conversion routines. *
48 ******************************/
49
50/*
51 * This function clears the previous value of the OCTET STRING (if any)
52 * and then allocates a new memory with the specified content (str/size).
53 * If size = -1, the size of the original string will be determined
54 * using strlen(str).
55 * If str equals to NULL, the function will silently clear the
56 * current contents of the OCTET STRING.
57 * Returns 0 if it was possible to perform operation, -1 otherwise.
58 */
59int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size);
60
61/* Handy conversion from the C string into the OCTET STRING. */
62#define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1)
63
64/*
65 * Allocate and fill the new OCTET STRING and return a pointer to the newly
66 * allocated object. NULL is permitted in str: the function will just allocate
67 * empty OCTET STRING.
68 */
69OCTET_STRING_t *OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td,
70 const char *str, int size);
71
72/****************************
73 * Internally useful stuff. *
74 ****************************/
75
76typedef struct asn_OCTET_STRING_specifics_s {
77 /*
78 * Target structure description.
79 */
80 unsigned struct_size; /* Size of the structure */
81 unsigned ctx_offset; /* Offset of the asn_struct_ctx_t member */
82
83 enum asn_OS_Subvariant {
84 ASN_OSUBV_ANY, /* The open type (ANY) */
85 ASN_OSUBV_BIT, /* BIT STRING */
86 ASN_OSUBV_STR, /* String types, not {BMP,Universal}String */
87 ASN_OSUBV_U16, /* 16-bit character (BMPString) */
88 ASN_OSUBV_U32 /* 32-bit character (UniversalString) */
89 } subvariant;
90} asn_OCTET_STRING_specifics_t;
91
92extern asn_OCTET_STRING_specifics_t asn_SPC_OCTET_STRING_specs;
93
94size_t OCTET_STRING_random_length_constrained(
95 const asn_TYPE_descriptor_t *, const asn_encoding_constraints_t *,
96 size_t max_length);
97
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* _OCTET_STRING_H_ */