1 /*****************************************************************************
3 # Copyright 2019 AT&T Intellectual Property *
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 *
9 # http://www.apache.org/licenses/LICENSE-2.0 *
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. *
17 ******************************************************************************/
20 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
21 * Redistribution and modifications are permitted subject to BSD license.
23 #ifndef _OCTET_STRING_H_
24 #define _OCTET_STRING_H_
26 #include <asn_application.h>
32 typedef struct OCTET_STRING {
33 uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */
34 size_t size; /* Size of the buffer */
36 asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
39 extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING;
40 extern asn_TYPE_operation_t asn_OP_OCTET_STRING;
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;
61 #define OCTET_STRING_constraint asn_generic_no_constraint
62 #define OCTET_STRING_decode_xer OCTET_STRING_decode_xer_hex
64 /******************************
65 * Handy conversion routines. *
66 ******************************/
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
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.
77 int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size);
79 /* Handy conversion from the C string into the OCTET STRING. */
80 #define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1)
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
87 OCTET_STRING_t *OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td,
88 const char *str, int size);
90 /****************************
91 * Internally useful stuff. *
92 ****************************/
94 typedef struct asn_OCTET_STRING_specifics_s {
96 * Target structure description.
98 unsigned struct_size; /* Size of the structure */
99 unsigned ctx_offset; /* Offset of the asn_struct_ctx_t member */
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) */
108 } asn_OCTET_STRING_specifics_t;
110 extern asn_OCTET_STRING_specifics_t asn_SPC_OCTET_STRING_specs;
112 size_t OCTET_STRING_random_length_constrained(
113 const asn_TYPE_descriptor_t *, const asn_encoding_constraints_t *,
120 #endif /* _OCTET_STRING_H_ */