blob: 10816358e7806b234b58de5c4da7d69c28381218 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001/*-
2 * Copyright (c) 2003 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
Lev Walkin11c3e172004-09-24 21:00:50 +00008#include <asn_application.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00009
10typedef struct OCTET_STRING {
11 uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */
12 int size; /* Size of the buffer */
13
Lev Walkin5e033762004-09-29 13:26:15 +000014 asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
Lev Walkinf15320b2004-06-03 03:38:44 +000015} OCTET_STRING_t;
16
Lev Walkin5e033762004-09-29 13:26:15 +000017extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING;
Lev Walkinf15320b2004-06-03 03:38:44 +000018
Lev Walkina9cc46e2004-09-22 16:06:28 +000019asn_struct_free_f OCTET_STRING_free;
Lev Walkinf15320b2004-06-03 03:38:44 +000020asn_struct_print_f OCTET_STRING_print;
Lev Walkindc06f6b2004-10-20 15:50:55 +000021asn_struct_print_f OCTET_STRING_print_utf8;
Lev Walkina9cc46e2004-09-22 16:06:28 +000022ber_type_decoder_f OCTET_STRING_decode_ber;
23der_type_encoder_f OCTET_STRING_encode_der;
Lev Walkindc06f6b2004-10-20 15:50:55 +000024xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */
25xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */
26xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */
Lev Walkina9cc46e2004-09-22 16:06:28 +000027xer_type_encoder_f OCTET_STRING_encode_xer;
Lev Walkindc06f6b2004-10-20 15:50:55 +000028xer_type_encoder_f OCTET_STRING_encode_xer_utf8;
Lev Walkinf15320b2004-06-03 03:38:44 +000029
Lev Walkinbbd93252004-10-12 05:57:23 +000030/******************************
31 * Handy conversion routines. *
32 ******************************/
Lev Walkinf15320b2004-06-03 03:38:44 +000033
34/*
35 * This function clears the previous value of the OCTET STRING (if any)
Lev Walkina737f3b2004-09-02 12:11:47 +000036 * and then allocates a new memory and returns a pointer to it.
37 * If size = -1, the size of the original string will be determined
Lev Walkinf15320b2004-06-03 03:38:44 +000038 * using strlen(str).
39 * If str equals to NULL, the function will silently clear the
40 * current contents of the OCTET STRING.
41 * Returns 0 if it was possible to perform operation, -1 otherwise.
42 */
43int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size);
44
Lev Walkinbbd93252004-10-12 05:57:23 +000045/* Handy conversion from the C string into the OCTET STRING. */
46#define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1);
47
Lev Walkinf15320b2004-06-03 03:38:44 +000048/*
49 * Allocate and fill the new OCTET STRING and return a pointer to the newly
50 * allocated object. NULL is permitted in str: the function will just allocate
51 * empty OCTET STRING.
52 */
Lev Walkinbbd93252004-10-12 05:57:23 +000053OCTET_STRING_t *OCTET_STRING_new_fromBuf(asn_TYPE_descriptor_t *td,
54 const char *str, int size);
Lev Walkinf15320b2004-06-03 03:38:44 +000055
Lev Walkinbbd93252004-10-12 05:57:23 +000056/****************************
57 * Internally useful stuff. *
58 ****************************/
59
60typedef struct asn_OCTET_STRING_specifics_s {
61 /*
62 * Target structure description.
63 */
64 int struct_size; /* Size of the structure */
65 int ctx_offset; /* Offset of the asn_struct_ctx_t member */
66
67 int subvariant; /* {0,1,2} for O-S, BIT STRING or ANY */
68} asn_OCTET_STRING_specifics_t;
Lev Walkinf15320b2004-06-03 03:38:44 +000069
70#endif /* _OCTET_STRING_H_ */