Moving in e2sim originally from it/test/simulators
[sim/e2-interface.git] / e2sim / ASN1c / OCTET_STRING.h
1 /*****************************************************************************
2 #                                                                            *
3 # Copyright 2019 AT&T Intellectual Property                                  *
4 #                                                                            *
5 # Licensed under the Apache License, Version 2.0 (the "License");            *
6 # you may not use this file except in compliance with the License.           *
7 # You may obtain a copy of the License at                                    *
8 #                                                                            *
9 #      http://www.apache.org/licenses/LICENSE-2.0                            *
10 #                                                                            *
11 # Unless required by applicable law or agreed to in writing, software        *
12 # distributed under the License is distributed on an "AS IS" BASIS,          *
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
14 # See the License for the specific language governing permissions and        *
15 # limitations under the License.                                             *
16 #                                                                            *
17 ******************************************************************************/
18
19 /*-
20  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21  * Redistribution and modifications are permitted subject to BSD license.
22  */
23 #ifndef _OCTET_STRING_H_
24 #define _OCTET_STRING_H_
25
26 #include <asn_application.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 typedef struct OCTET_STRING {
33         uint8_t *buf;   /* Buffer with consecutive OCTET_STRING bits */
34         size_t size;    /* Size of the buffer */
35
36         asn_struct_ctx_t _asn_ctx;      /* Parsing across buffer boundaries */
37 } OCTET_STRING_t;
38
39 extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING;
40 extern asn_TYPE_operation_t asn_OP_OCTET_STRING;
41
42 asn_struct_free_f OCTET_STRING_free;
43 asn_struct_print_f OCTET_STRING_print;
44 asn_struct_print_f OCTET_STRING_print_utf8;
45 asn_struct_compare_f OCTET_STRING_compare;
46 ber_type_decoder_f OCTET_STRING_decode_ber;
47 der_type_encoder_f OCTET_STRING_encode_der;
48 xer_type_decoder_f OCTET_STRING_decode_xer_hex;         /* Hexadecimal */
49 xer_type_decoder_f OCTET_STRING_decode_xer_binary;      /* 01010111010 */
50 xer_type_decoder_f OCTET_STRING_decode_xer_utf8;        /* ASCII/UTF-8 */
51 xer_type_encoder_f OCTET_STRING_encode_xer;
52 xer_type_encoder_f OCTET_STRING_encode_xer_utf8;
53 oer_type_decoder_f OCTET_STRING_decode_oer;
54 oer_type_encoder_f OCTET_STRING_encode_oer;
55 per_type_decoder_f OCTET_STRING_decode_uper;
56 per_type_encoder_f OCTET_STRING_encode_uper;
57 per_type_decoder_f OCTET_STRING_decode_aper;
58 per_type_encoder_f OCTET_STRING_encode_aper;
59 asn_random_fill_f  OCTET_STRING_random_fill;
60
61 #define OCTET_STRING_constraint  asn_generic_no_constraint
62 #define OCTET_STRING_decode_xer  OCTET_STRING_decode_xer_hex
63
64 /******************************
65  * Handy conversion routines. *
66  ******************************/
67
68 /*
69  * This function clears the previous value of the OCTET STRING (if any)
70  * and then allocates a new memory with the specified content (str/size).
71  * If size = -1, the size of the original string will be determined
72  * using strlen(str).
73  * If str equals to NULL, the function will silently clear the
74  * current contents of the OCTET STRING.
75  * Returns 0 if it was possible to perform operation, -1 otherwise.
76  */
77 int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size);
78
79 /* Handy conversion from the C string into the OCTET STRING. */
80 #define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1)
81
82 /*
83  * Allocate and fill the new OCTET STRING and return a pointer to the newly
84  * allocated object. NULL is permitted in str: the function will just allocate
85  * empty OCTET STRING.
86  */
87 OCTET_STRING_t *OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td,
88                                          const char *str, int size);
89
90 /****************************
91  * Internally useful stuff. *
92  ****************************/
93
94 typedef struct asn_OCTET_STRING_specifics_s {
95     /*
96      * Target structure description.
97      */
98     unsigned struct_size;   /* Size of the structure */
99     unsigned ctx_offset;    /* Offset of the asn_struct_ctx_t member */
100
101     enum asn_OS_Subvariant {
102         ASN_OSUBV_ANY, /* The open type (ANY) */
103         ASN_OSUBV_BIT, /* BIT STRING */
104         ASN_OSUBV_STR, /* String types, not {BMP,Universal}String  */
105         ASN_OSUBV_U16, /* 16-bit character (BMPString) */
106         ASN_OSUBV_U32  /* 32-bit character (UniversalString) */
107     } subvariant;
108 } asn_OCTET_STRING_specifics_t;
109
110 extern asn_OCTET_STRING_specifics_t asn_SPC_OCTET_STRING_specs;
111
112 size_t OCTET_STRING_random_length_constrained(
113     const asn_TYPE_descriptor_t *, const asn_encoding_constraints_t *,
114     size_t max_length);
115
116 #ifdef __cplusplus
117 }
118 #endif
119
120 #endif  /* _OCTET_STRING_H_ */