00001
00027 #ifndef POLARSSL_ASN1_H
00028 #define POLARSSL_ASN1_H
00029
00030 #include "config.h"
00031
00032 #if defined(POLARSSL_BIGNUM_C)
00033 #include "bignum.h"
00034 #endif
00035
00036 #include <string.h>
00037
00050 #define POLARSSL_ERR_ASN1_OUT_OF_DATA -0x0060
00051 #define POLARSSL_ERR_ASN1_UNEXPECTED_TAG -0x0062
00052 #define POLARSSL_ERR_ASN1_INVALID_LENGTH -0x0064
00053 #define POLARSSL_ERR_ASN1_LENGTH_MISMATCH -0x0066
00054 #define POLARSSL_ERR_ASN1_INVALID_DATA -0x0068
00055 #define POLARSSL_ERR_ASN1_MALLOC_FAILED -0x006A
00056 #define POLARSSL_ERR_ASN1_BUF_TOO_SMALL -0x006C
00058
00059
00071 #define ASN1_BOOLEAN 0x01
00072 #define ASN1_INTEGER 0x02
00073 #define ASN1_BIT_STRING 0x03
00074 #define ASN1_OCTET_STRING 0x04
00075 #define ASN1_NULL 0x05
00076 #define ASN1_OID 0x06
00077 #define ASN1_UTF8_STRING 0x0C
00078 #define ASN1_SEQUENCE 0x10
00079 #define ASN1_SET 0x11
00080 #define ASN1_PRINTABLE_STRING 0x13
00081 #define ASN1_T61_STRING 0x14
00082 #define ASN1_IA5_STRING 0x16
00083 #define ASN1_UTC_TIME 0x17
00084 #define ASN1_GENERALIZED_TIME 0x18
00085 #define ASN1_UNIVERSAL_STRING 0x1C
00086 #define ASN1_BMP_STRING 0x1E
00087 #define ASN1_PRIMITIVE 0x00
00088 #define ASN1_CONSTRUCTED 0x20
00089 #define ASN1_CONTEXT_SPECIFIC 0x80
00090
00091
00092
00094 #define OID_SIZE(x) (sizeof(x) - 1)
00095
00100 #define OID_CMP(oid_str, oid_buf) \
00101 ( ( OID_SIZE(oid_str) == (oid_buf)->len ) && \
00102 memcmp( (oid_str), (oid_buf)->p, (oid_buf)->len) == 0 )
00103
00104 #ifdef __cplusplus
00105 extern "C" {
00106 #endif
00107
00116 typedef struct _asn1_buf
00117 {
00118 int tag;
00119 size_t len;
00120 unsigned char *p;
00121 }
00122 asn1_buf;
00123
00127 typedef struct _asn1_bitstring
00128 {
00129 size_t len;
00130 unsigned char unused_bits;
00131 unsigned char *p;
00132 }
00133 asn1_bitstring;
00134
00138 typedef struct _asn1_sequence
00139 {
00140 asn1_buf buf;
00141 struct _asn1_sequence *next;
00142 }
00143 asn1_sequence;
00144
00148 typedef struct _asn1_named_data
00149 {
00150 asn1_buf oid;
00151 asn1_buf val;
00152 struct _asn1_named_data *next;
00153 }
00154 asn1_named_data;
00155
00168 int asn1_get_len( unsigned char **p,
00169 const unsigned char *end,
00170 size_t *len );
00171
00184 int asn1_get_tag( unsigned char **p,
00185 const unsigned char *end,
00186 size_t *len, int tag );
00187
00198 int asn1_get_bool( unsigned char **p,
00199 const unsigned char *end,
00200 int *val );
00201
00212 int asn1_get_int( unsigned char **p,
00213 const unsigned char *end,
00214 int *val );
00215
00226 int asn1_get_bitstring( unsigned char **p, const unsigned char *end,
00227 asn1_bitstring *bs);
00228
00240 int asn1_get_bitstring_null( unsigned char **p, const unsigned char *end,
00241 size_t *len );
00242
00254 int asn1_get_sequence_of( unsigned char **p,
00255 const unsigned char *end,
00256 asn1_sequence *cur,
00257 int tag);
00258
00259 #if defined(POLARSSL_BIGNUM_C)
00260
00270 int asn1_get_mpi( unsigned char **p,
00271 const unsigned char *end,
00272 mpi *X );
00273 #endif
00274
00287 int asn1_get_alg( unsigned char **p,
00288 const unsigned char *end,
00289 asn1_buf *alg, asn1_buf *params );
00290
00303 int asn1_get_alg_null( unsigned char **p,
00304 const unsigned char *end,
00305 asn1_buf *alg );
00306
00317 asn1_named_data *asn1_find_named_data( asn1_named_data *list,
00318 const char *oid, size_t len );
00319
00325 void asn1_free_named_data( asn1_named_data *entry );
00326
00333 void asn1_free_named_data_list( asn1_named_data **head );
00334
00335 #ifdef __cplusplus
00336 }
00337 #endif
00338
00339 #endif