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