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 );