28 #if defined(POLARSSL_ASN1_WRITE_C)
32 #if defined(POLARSSL_MEMORY_C)
36 #define polarssl_malloc malloc
37 #define polarssl_free free
40 int asn1_write_len(
unsigned char **p,
unsigned char *start,
size_t len )
47 *--(*p) = (
unsigned char) len;
56 *--(*p) = (
unsigned char) len;
67 *--(*p) = ( len / 256 ) % 256;
73 int asn1_write_tag(
unsigned char **p,
unsigned char *start,
unsigned char tag )
84 const unsigned char *buf,
size_t size )
88 if( *p - start < (
int) size )
93 memcpy( *p, buf, len );
98 #if defined(POLARSSL_BIGNUM_C)
108 if( *p - start < (
int) len )
117 if ( X->
s ==1 && **p & 0x80 )
147 const char *
oid,
size_t oid_len )
153 (
const unsigned char *) oid, oid_len ) );
161 const char *oid,
size_t oid_len,
181 int asn1_write_bool(
unsigned char **p,
unsigned char *start,
int boolean )
189 *--(*p) = (boolean) ? 1 : 0;
213 if ( val > 0 && **p & 0x80 )
229 const char *text,
size_t text_len )
235 (
const unsigned char *) text, text_len ) );
244 const char *text,
size_t text_len )
250 (
const unsigned char *) text, text_len ) );
259 const unsigned char *buf,
size_t bits )
262 size_t len = 0, size;
264 size = ( bits / 8 ) + ( ( bits % 8 ) ? 1 : 0 );
268 if( *p - start < (
int) size + 1 )
273 memcpy( *p, buf, size );
277 *--(*p) = (
unsigned char) (size * 8 - bits);
286 const unsigned char *buf,
size_t size )
300 const char *oid,
size_t oid_len,
301 const unsigned char *val,
317 if( cur->
oid.
p == NULL )
325 if( cur->
val.
p == NULL )
332 memcpy( cur->
oid.
p, oid, oid_len );
337 else if( cur->
val.
len < val_len )
346 if( cur->
val.
p == NULL )
355 memcpy( cur->
val.
p, val, val_len );
#define ASN1_PRINTABLE_STRING
int asn1_write_octet_string(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t size)
Write an octet string tag (ASN1_OCTET_STRING) and value in ASN.1 format Note: function works backward...
int asn1_write_ia5_string(unsigned char **p, unsigned char *start, const char *text, size_t text_len)
Write an IA5 string tag (ASN1_IA5_STRING) and value in ASN.1 format Note: function works backwards in...
void *(* polarssl_malloc)(size_t len)
asn1_named_data * asn1_store_named_data(asn1_named_data **list, const char *oid, size_t oid_len, const unsigned char *val, size_t val_len)
Create or find a specific named_data entry for writing in a sequence or list based on the OID...
#define POLARSSL_ERR_ASN1_BUF_TOO_SMALL
Buffer too small when writing ASN.1 data structure.
Configuration options (set of defines)
int asn1_write_len(unsigned char **p, unsigned char *start, size_t len)
Write a length field in ASN.1 format Note: function works backwards in data buffer.
int asn1_write_printable_string(unsigned char **p, unsigned char *start, const char *text, size_t text_len)
Write a printable string tag (ASN1_PRINTABLE_STRING) and value in ASN.1 format Note: function works b...
asn1_buf val
The named value.
asn1_buf oid
The object identifier.
int asn1_write_raw_buffer(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t size)
Write raw buffer data Note: function works backwards in data buffer.
void(* polarssl_free)(void *ptr)
unsigned char * p
ASN1 data, e.g.
int asn1_write_null(unsigned char **p, unsigned char *start)
Write a NULL tag (ASN1_NULL) with zero data in ASN.1 format Note: function works backwards in data bu...
int asn1_write_mpi(unsigned char **p, unsigned char *start, mpi *X)
Write a big number (ASN1_INTEGER) in ASN.1 format Note: function works backwards in data buffer...
int asn1_write_bitstring(unsigned char **p, unsigned char *start, const unsigned char *buf, size_t bits)
Write a bitstring tag (ASN1_BIT_STRING) and value in ASN.1 format Note: function works backwards in d...
int asn1_write_int(unsigned char **p, unsigned char *start, int val)
Write an int tag (ASN1_INTEGER) and value in ASN.1 format Note: function works backwards in data buff...
Container for a sequence or list of 'named' ASN.1 data items.
size_t len
ASN1 length, e.g.
#define ASN1_CHK_ADD(g, f)
int asn1_write_algorithm_identifier(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len, size_t par_len)
Write an AlgorithmIdentifier sequence in ASN.1 format Note: function works backwards in data buffer...
size_t mpi_size(const mpi *X)
Return the total size in bytes.
int asn1_write_bool(unsigned char **p, unsigned char *start, int boolean)
Write a boolean tag (ASN1_BOOLEAN) and value in ASN.1 format Note: function works backwards in data b...
int mpi_write_binary(const mpi *X, unsigned char *buf, size_t buflen)
Export X into unsigned binary data, big endian.
asn1_named_data * asn1_find_named_data(asn1_named_data *list, const char *oid, size_t len)
Find a specific named_data entry in a sequence or list based on the OID.
struct _asn1_named_data * next
The next entry in the sequence.
ASN.1 buffer writing functionality.
int asn1_write_oid(unsigned char **p, unsigned char *start, const char *oid, size_t oid_len)
Write an OID tag (ASN1_OID) and data in ASN.1 format Note: function works backwards in data buffer...
#define ASN1_OCTET_STRING
int asn1_write_tag(unsigned char **p, unsigned char *start, unsigned char tag)
Write a ASN.1 tag in ASN.1 format Note: function works backwards in data buffer.