PolarSSL v1.1.4
asn1.h
Go to the documentation of this file.
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                      -0x0014  
00051 #define POLARSSL_ERR_ASN1_UNEXPECTED_TAG                   -0x0016  
00052 #define POLARSSL_ERR_ASN1_INVALID_LENGTH                   -0x0018  
00053 #define POLARSSL_ERR_ASN1_LENGTH_MISMATCH                  -0x001A  
00054 #define POLARSSL_ERR_ASN1_INVALID_DATA                     -0x001C  
00055 #define POLARSSL_ERR_ASN1_MALLOC_FAILED                    -0x001E  
00056 /* \} name */
00057 
00069 #define ASN1_BOOLEAN                 0x01
00070 #define ASN1_INTEGER                 0x02
00071 #define ASN1_BIT_STRING              0x03
00072 #define ASN1_OCTET_STRING            0x04
00073 #define ASN1_NULL                    0x05
00074 #define ASN1_OID                     0x06
00075 #define ASN1_UTF8_STRING             0x0C
00076 #define ASN1_SEQUENCE                0x10
00077 #define ASN1_SET                     0x11
00078 #define ASN1_PRINTABLE_STRING        0x13
00079 #define ASN1_T61_STRING              0x14
00080 #define ASN1_IA5_STRING              0x16
00081 #define ASN1_UTC_TIME                0x17
00082 #define ASN1_GENERALIZED_TIME        0x18
00083 #define ASN1_UNIVERSAL_STRING        0x1C
00084 #define ASN1_BMP_STRING              0x1E
00085 #define ASN1_PRIMITIVE               0x00
00086 #define ASN1_CONSTRUCTED             0x20
00087 #define ASN1_CONTEXT_SPECIFIC        0x80
00088 /* \} name */
00089 /* \} addtogroup asn1_module */
00090 
00092 #define OID_SIZE(x) (sizeof(x) - 1)
00093 
00094 #ifdef __cplusplus
00095 extern "C" {
00096 #endif
00097 
00106 typedef struct _asn1_buf
00107 {
00108     int tag;                
00109     size_t len;             
00110     unsigned char *p;       
00111 }
00112 asn1_buf;
00113 
00117 typedef struct _asn1_bitstring
00118 {
00119     size_t len;                 
00120     unsigned char unused_bits;  
00121     unsigned char *p;           
00122 }
00123 asn1_bitstring;
00124 
00128 typedef struct _asn1_sequence
00129 {
00130     asn1_buf buf;                   
00131     struct _asn1_sequence *next;    
00132 }
00133 asn1_sequence;
00134 
00147 int asn1_get_len( unsigned char **p,
00148                   const unsigned char *end,
00149                   size_t *len );
00150 
00163 int asn1_get_tag( unsigned char **p,
00164                   const unsigned char *end,
00165                   size_t *len, int tag );
00166 
00177 int asn1_get_bool( unsigned char **p,
00178                    const unsigned char *end,
00179                    int *val );
00180 
00191 int asn1_get_int( unsigned char **p,
00192                   const unsigned char *end,
00193                   int *val );
00194 
00205 int asn1_get_bitstring( unsigned char **p, const unsigned char *end,
00206                         asn1_bitstring *bs);
00207 
00219 int asn1_get_sequence_of( unsigned char **p,
00220                           const unsigned char *end,
00221                           asn1_sequence *cur,
00222                           int tag);
00223 
00224 #if defined(POLARSSL_BIGNUM_C)
00225 
00235 int asn1_get_mpi( unsigned char **p,
00236                   const unsigned char *end,
00237                   mpi *X );
00238 #endif
00239 
00240 #ifdef __cplusplus
00241 }
00242 #endif
00243 
00244 #endif /* asn1.h */