blob: bb06dc62d4a60eb14e30cc7aff46181111c7be6e [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
Lev Walkin20696a42017-10-17 21:27:33 -07002 * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkinf15320b2004-06-03 03:38:44 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
5#ifndef _OCTET_STRING_H_
6#define _OCTET_STRING_H_
7
Lev Walkin11c3e172004-09-24 21:00:50 +00008#include <asn_application.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00009
Lev Walkin21b41ac2005-07-24 09:03:44 +000010#ifdef __cplusplus
11extern "C" {
12#endif
13
Lev Walkinf15320b2004-06-03 03:38:44 +000014typedef struct OCTET_STRING {
15 uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */
Lev Walkin494fb702017-08-07 20:07:00 -070016 size_t size; /* Size of the buffer */
Lev Walkinf15320b2004-06-03 03:38:44 +000017
Lev Walkin5e033762004-09-29 13:26:15 +000018 asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
Lev Walkinf15320b2004-06-03 03:38:44 +000019} OCTET_STRING_t;
20
Lev Walkin5e033762004-09-29 13:26:15 +000021extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING;
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080022extern asn_TYPE_operation_t asn_OP_OCTET_STRING;
Lev Walkinf15320b2004-06-03 03:38:44 +000023
Lev Walkina9cc46e2004-09-22 16:06:28 +000024asn_struct_free_f OCTET_STRING_free;
Lev Walkinf15320b2004-06-03 03:38:44 +000025asn_struct_print_f OCTET_STRING_print;
Lev Walkindc06f6b2004-10-20 15:50:55 +000026asn_struct_print_f OCTET_STRING_print_utf8;
Lev Walkincd2f48e2017-08-10 02:14:59 -070027asn_struct_compare_f OCTET_STRING_compare;
Lev Walkina9cc46e2004-09-22 16:06:28 +000028ber_type_decoder_f OCTET_STRING_decode_ber;
29der_type_encoder_f OCTET_STRING_encode_der;
Lev Walkindc06f6b2004-10-20 15:50:55 +000030xer_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 */
Lev Walkina9cc46e2004-09-22 16:06:28 +000033xer_type_encoder_f OCTET_STRING_encode_xer;
Lev Walkindc06f6b2004-10-20 15:50:55 +000034xer_type_encoder_f OCTET_STRING_encode_xer_utf8;
Lev Walkin1d76f3c2017-07-25 07:58:05 -070035oer_type_decoder_f OCTET_STRING_decode_oer;
36oer_type_encoder_f OCTET_STRING_encode_oer;
Lev Walkin59b176e2005-11-26 11:25:14 +000037per_type_decoder_f OCTET_STRING_decode_uper;
Lev Walkin523de9e2006-08-18 01:34:18 +000038per_type_encoder_f OCTET_STRING_encode_uper;
Lev Walkina5972be2017-09-29 23:15:58 -070039asn_random_fill_f OCTET_STRING_random_fill;
Lev Walkinf15320b2004-06-03 03:38:44 +000040
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080041#define OCTET_STRING_constraint asn_generic_no_constraint
42#define OCTET_STRING_decode_xer OCTET_STRING_decode_xer_hex
43
Lev Walkinbbd93252004-10-12 05:57:23 +000044/******************************
45 * Handy conversion routines. *
46 ******************************/
Lev Walkinf15320b2004-06-03 03:38:44 +000047
48/*
49 * This function clears the previous value of the OCTET STRING (if any)
Lev Walkind4044272006-03-17 18:34:10 +000050 * and then allocates a new memory with the specified content (str/size).
Lev Walkina737f3b2004-09-02 12:11:47 +000051 * If size = -1, the size of the original string will be determined
Lev Walkinf15320b2004-06-03 03:38:44 +000052 * using strlen(str).
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.
56 */
57int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size);
58
Lev Walkinbbd93252004-10-12 05:57:23 +000059/* Handy conversion from the C string into the OCTET STRING. */
Lev Walkin6ac04062005-04-18 05:41:08 +000060#define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1)
Lev Walkinbbd93252004-10-12 05:57:23 +000061
Lev Walkinf15320b2004-06-03 03:38:44 +000062/*
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
65 * empty OCTET STRING.
66 */
Lev Walkina5972be2017-09-29 23:15:58 -070067OCTET_STRING_t *OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td,
68 const char *str, int size);
Lev Walkinf15320b2004-06-03 03:38:44 +000069
Lev Walkinbbd93252004-10-12 05:57:23 +000070/****************************
71 * Internally useful stuff. *
72 ****************************/
73
Lev Walkind84f6032017-10-03 16:33:59 -070074typedef struct asn_OCTET_STRING_specifics_s {
Lev Walkin19e12b52017-10-18 16:30:05 -070075 /*
76 * Target structure description.
77 */
78 unsigned struct_size; /* Size of the structure */
79 unsigned ctx_offset; /* Offset of the asn_struct_ctx_t member */
Lev Walkinbbd93252004-10-12 05:57:23 +000080
Lev Walkin19e12b52017-10-18 16:30:05 -070081 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) */
87 } subvariant;
Lev Walkinbbd93252004-10-12 05:57:23 +000088} asn_OCTET_STRING_specifics_t;
Lev Walkinf15320b2004-06-03 03:38:44 +000089
Bi-Ruei, Chiu1fa31c92016-05-16 13:50:09 +080090extern asn_OCTET_STRING_specifics_t asn_SPC_OCTET_STRING_specs;
91
Lev Walkin349b3402017-10-14 00:23:09 -070092size_t OCTET_STRING_random_length_constrained(
93 const asn_TYPE_descriptor_t *, const asn_encoding_constraints_t *,
94 size_t max_length);
95
Lev Walkin21b41ac2005-07-24 09:03:44 +000096#ifdef __cplusplus
97}
98#endif
99
Lev Walkinf15320b2004-06-03 03:38:44 +0000100#endif /* _OCTET_STRING_H_ */