Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [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 | |
Lev Walkin | 11c3e17 | 2004-09-24 21:00:50 +0000 | [diff] [blame] | 8 | #include <asn_application.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 14 | typedef struct OCTET_STRING { |
| 15 | uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */ |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 16 | size_t size; /* Size of the buffer */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 17 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 18 | asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 19 | } OCTET_STRING_t; |
| 20 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 21 | extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 22 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 23 | asn_struct_free_f OCTET_STRING_free; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 24 | asn_struct_print_f OCTET_STRING_print; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 25 | asn_struct_print_f OCTET_STRING_print_utf8; |
Lev Walkin | cd2f48e | 2017-08-10 02:14:59 -0700 | [diff] [blame] | 26 | asn_struct_compare_f OCTET_STRING_compare; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 27 | ber_type_decoder_f OCTET_STRING_decode_ber; |
| 28 | der_type_encoder_f OCTET_STRING_encode_der; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 29 | xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */ |
| 30 | xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */ |
| 31 | xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 32 | xer_type_encoder_f OCTET_STRING_encode_xer; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 33 | xer_type_encoder_f OCTET_STRING_encode_xer_utf8; |
Lev Walkin | 1d76f3c | 2017-07-25 07:58:05 -0700 | [diff] [blame] | 34 | oer_type_decoder_f OCTET_STRING_decode_oer; |
| 35 | oer_type_encoder_f OCTET_STRING_encode_oer; |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 36 | per_type_decoder_f OCTET_STRING_decode_uper; |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 37 | per_type_encoder_f OCTET_STRING_encode_uper; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 38 | |
Bi-Ruei, Chiu | 1fa31c9 | 2016-05-16 13:50:09 +0800 | [diff] [blame] | 39 | #define OCTET_STRING_constraint asn_generic_no_constraint |
| 40 | #define OCTET_STRING_decode_xer OCTET_STRING_decode_xer_hex |
| 41 | |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 42 | /****************************** |
| 43 | * Handy conversion routines. * |
| 44 | ******************************/ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * This function clears the previous value of the OCTET STRING (if any) |
Lev Walkin | d404427 | 2006-03-17 18:34:10 +0000 | [diff] [blame] | 48 | * and then allocates a new memory with the specified content (str/size). |
Lev Walkin | a737f3b | 2004-09-02 12:11:47 +0000 | [diff] [blame] | 49 | * If size = -1, the size of the original string will be determined |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 50 | * using strlen(str). |
| 51 | * If str equals to NULL, the function will silently clear the |
| 52 | * current contents of the OCTET STRING. |
| 53 | * Returns 0 if it was possible to perform operation, -1 otherwise. |
| 54 | */ |
| 55 | int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size); |
| 56 | |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 57 | /* Handy conversion from the C string into the OCTET STRING. */ |
Lev Walkin | 6ac0406 | 2005-04-18 05:41:08 +0000 | [diff] [blame] | 58 | #define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1) |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 59 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 60 | /* |
| 61 | * Allocate and fill the new OCTET STRING and return a pointer to the newly |
| 62 | * allocated object. NULL is permitted in str: the function will just allocate |
| 63 | * empty OCTET STRING. |
| 64 | */ |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 65 | OCTET_STRING_t *OCTET_STRING_new_fromBuf(asn_TYPE_descriptor_t *td, |
| 66 | const char *str, int size); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 67 | |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 68 | /**************************** |
| 69 | * Internally useful stuff. * |
| 70 | ****************************/ |
| 71 | |
Wim Lewis | fb6344e | 2014-07-28 12:16:01 -0700 | [diff] [blame] | 72 | typedef const struct asn_OCTET_STRING_specifics_s { |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 73 | /* |
| 74 | * Target structure description. |
| 75 | */ |
| 76 | int struct_size; /* Size of the structure */ |
| 77 | int ctx_offset; /* Offset of the asn_struct_ctx_t member */ |
| 78 | |
Lev Walkin | 3a4689a | 2006-11-24 11:20:27 +0000 | [diff] [blame] | 79 | enum asn_OS_Subvariant { |
| 80 | ASN_OSUBV_ANY, /* The open type (ANY) */ |
| 81 | ASN_OSUBV_BIT, /* BIT STRING */ |
| 82 | ASN_OSUBV_STR, /* String types, not {BMP,Universal}String */ |
| 83 | ASN_OSUBV_U16, /* 16-bit character (BMPString) */ |
| 84 | ASN_OSUBV_U32 /* 32-bit character (UniversalString) */ |
| 85 | } subvariant; |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 86 | } asn_OCTET_STRING_specifics_t; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 87 | |
Bi-Ruei, Chiu | 1fa31c9 | 2016-05-16 13:50:09 +0800 | [diff] [blame] | 88 | extern asn_OCTET_STRING_specifics_t asn_SPC_OCTET_STRING_specs; |
| 89 | |
Lev Walkin | 21b41ac | 2005-07-24 09:03:44 +0000 | [diff] [blame] | 90 | #ifdef __cplusplus |
| 91 | } |
| 92 | #endif |
| 93 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 94 | #endif /* _OCTET_STRING_H_ */ |