Harald Welte | 43ab79f | 2018-10-03 23:34:21 +0200 | [diff] [blame] | 1 | /*- |
| 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 | |
| 8 | #include <asn_application.h> |
| 9 | |
| 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
| 14 | typedef struct OCTET_STRING { |
| 15 | uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */ |
| 16 | int size; /* Size of the buffer */ |
| 17 | |
| 18 | asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */ |
| 19 | } OCTET_STRING_t; |
| 20 | |
| 21 | extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING; |
| 22 | |
| 23 | asn_struct_free_f OCTET_STRING_free; |
| 24 | asn_struct_print_f OCTET_STRING_print; |
| 25 | asn_struct_print_f OCTET_STRING_print_utf8; |
| 26 | ber_type_decoder_f OCTET_STRING_decode_ber; |
| 27 | der_type_encoder_f OCTET_STRING_encode_der; |
| 28 | xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */ |
| 29 | xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */ |
| 30 | xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */ |
| 31 | xer_type_encoder_f OCTET_STRING_encode_xer; |
| 32 | xer_type_encoder_f OCTET_STRING_encode_xer_utf8; |
| 33 | per_type_decoder_f OCTET_STRING_decode_uper; |
| 34 | per_type_encoder_f OCTET_STRING_encode_uper; |
| 35 | per_type_decoder_f OCTET_STRING_decode_aper; |
| 36 | per_type_encoder_f OCTET_STRING_encode_aper; |
| 37 | |
| 38 | /****************************** |
| 39 | * Handy conversion routines. * |
| 40 | ******************************/ |
| 41 | |
| 42 | /* |
| 43 | * This function clears the previous value of the OCTET STRING (if any) |
| 44 | * and then allocates a new memory with the specified content (str/size). |
| 45 | * If size = -1, the size of the original string will be determined |
| 46 | * using strlen(str). |
| 47 | * If str equals to NULL, the function will silently clear the |
| 48 | * current contents of the OCTET STRING. |
| 49 | * Returns 0 if it was possible to perform operation, -1 otherwise. |
| 50 | */ |
| 51 | int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size); |
| 52 | |
| 53 | /* Handy conversion from the C string into the OCTET STRING. */ |
| 54 | #define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1) |
| 55 | |
| 56 | /* |
| 57 | * Allocate and fill the new OCTET STRING and return a pointer to the newly |
| 58 | * allocated object. NULL is permitted in str: the function will just allocate |
| 59 | * empty OCTET STRING. |
| 60 | */ |
| 61 | OCTET_STRING_t *OCTET_STRING_new_fromBuf(asn_TYPE_descriptor_t *td, |
| 62 | const char *str, int size); |
| 63 | |
| 64 | /**************************** |
| 65 | * Internally useful stuff. * |
| 66 | ****************************/ |
| 67 | |
| 68 | typedef const struct asn_OCTET_STRING_specifics_s { |
| 69 | /* |
| 70 | * Target structure description. |
| 71 | */ |
| 72 | int struct_size; /* Size of the structure */ |
| 73 | int ctx_offset; /* Offset of the asn_struct_ctx_t member */ |
| 74 | |
| 75 | enum asn_OS_Subvariant { |
| 76 | ASN_OSUBV_ANY, /* The open type (ANY) */ |
| 77 | ASN_OSUBV_BIT, /* BIT STRING */ |
| 78 | ASN_OSUBV_STR, /* String types, not {BMP,Universal}String */ |
| 79 | ASN_OSUBV_U16, /* 16-bit character (BMPString) */ |
| 80 | ASN_OSUBV_U32 /* 32-bit character (UniversalString) */ |
| 81 | } subvariant; |
| 82 | } asn_OCTET_STRING_specifics_t; |
| 83 | |
| 84 | #ifdef __cplusplus |
| 85 | } |
| 86 | #endif |
| 87 | |
| 88 | #endif /* _OCTET_STRING_H_ */ |