vlm | fa67ddc | 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 | |
| 8 | #include <constr_TYPE.h> |
| 9 | |
| 10 | typedef struct OCTET_STRING { |
| 11 | uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */ |
| 12 | int size; /* Size of the buffer */ |
| 13 | |
| 14 | ber_dec_ctx_t _ber_dec_ctx; /* Parsing across buffer boundaries */ |
| 15 | } OCTET_STRING_t; |
| 16 | |
| 17 | extern asn1_TYPE_descriptor_t asn1_DEF_OCTET_STRING; |
| 18 | |
| 19 | ber_type_decoder_f OCTET_STRING_decode_ber; |
| 20 | der_type_encoder_f OCTET_STRING_encode_der; |
| 21 | asn_struct_print_f OCTET_STRING_print; |
| 22 | asn_struct_print_f OCTET_STRING_print_ascii; |
| 23 | asn_struct_free_f OCTET_STRING_free; |
| 24 | |
| 25 | /*********************************** |
| 26 | * Some handy conversion routines. * |
| 27 | ***********************************/ |
| 28 | |
| 29 | /* |
| 30 | * This function clears the previous value of the OCTET STRING (if any) |
| 31 | * and then allocates a new memory and makes s point to the newly allocated |
| 32 | * memory. If size = -1, the size of the original string will be determined |
| 33 | * using strlen(str). |
| 34 | * If str equals to NULL, the function will silently clear the |
| 35 | * current contents of the OCTET STRING. |
| 36 | * Returns 0 if it was possible to perform operation, -1 otherwise. |
| 37 | */ |
| 38 | int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size); |
| 39 | |
| 40 | /* |
| 41 | * Allocate and fill the new OCTET STRING and return a pointer to the newly |
| 42 | * allocated object. NULL is permitted in str: the function will just allocate |
| 43 | * empty OCTET STRING. |
| 44 | */ |
| 45 | OCTET_STRING_t *OCTET_STRING_new_fromBuf(const char *str, int size); |
| 46 | |
| 47 | /* Handy conversion from the C string into the OCTET STRING. */ |
| 48 | #define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1); |
| 49 | #define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1); |
| 50 | |
| 51 | #endif /* _OCTET_STRING_H_ */ |