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 | |
| 10 | typedef struct OCTET_STRING { |
| 11 | uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */ |
| 12 | int size; /* Size of the buffer */ |
| 13 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 14 | asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 15 | } OCTET_STRING_t; |
| 16 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 17 | extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 18 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 19 | asn_struct_free_f OCTET_STRING_free; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | asn_struct_print_f OCTET_STRING_print; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 21 | asn_struct_print_f OCTET_STRING_print_utf8; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 22 | ber_type_decoder_f OCTET_STRING_decode_ber; |
| 23 | der_type_encoder_f OCTET_STRING_encode_der; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 24 | xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */ |
| 25 | xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */ |
| 26 | xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 27 | xer_type_encoder_f OCTET_STRING_encode_xer; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 28 | xer_type_encoder_f OCTET_STRING_encode_xer_utf8; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 29 | |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 30 | /****************************** |
| 31 | * Handy conversion routines. * |
| 32 | ******************************/ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 33 | |
| 34 | /* |
| 35 | * This function clears the previous value of the OCTET STRING (if any) |
Lev Walkin | a737f3b | 2004-09-02 12:11:47 +0000 | [diff] [blame] | 36 | * 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 Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 38 | * 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 | */ |
| 43 | int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size); |
| 44 | |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 45 | /* 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 Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 48 | /* |
| 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 Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 53 | OCTET_STRING_t *OCTET_STRING_new_fromBuf(asn_TYPE_descriptor_t *td, |
| 54 | const char *str, int size); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 55 | |
Lev Walkin | bbd9325 | 2004-10-12 05:57:23 +0000 | [diff] [blame] | 56 | /**************************** |
| 57 | * Internally useful stuff. * |
| 58 | ****************************/ |
| 59 | |
| 60 | typedef 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 Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 69 | |
| 70 | #endif /* _OCTET_STRING_H_ */ |