static int x509_write_extension( unsigned char **p, unsigned char *start, asn1_named_data *ext ) { int ret; size_t len = 0; ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, ext->val.p + 1, ext->val.len - 1 ) ); ASN1_CHK_ADD( len, asn1_write_len( p, start, ext->val.len - 1 ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_OCTET_STRING ) ); if( ext->val.p[0] != 0 ) { ASN1_CHK_ADD( len, asn1_write_bool( p, start, 1 ) ); } ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, ext->oid.p, ext->oid.len ) ); ASN1_CHK_ADD( len, asn1_write_len( p, start, ext->oid.len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_OID ) ); ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ); return( (int) len ); }
static int x509_write_time( unsigned char **p, unsigned char *start, const char *time, size_t size ) { int ret; size_t len = 0; /* * write ASN1_UTC_TIME if year < 2050 (2 bytes shorter) */ if( time[0] == '2' && time[1] == '0' && time [2] < '5' ) { ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, (const unsigned char *) time + 2, size - 2 ) ); ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_UTC_TIME ) ); } else { ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, (const unsigned char *) time, size ) ); ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_GENERALIZED_TIME ) ); } return( (int) len ); }
int asn1_write_octet_string( unsigned char **p, unsigned char *start, const unsigned char *buf, size_t size ) { int ret; size_t len = 0; ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, buf, size ) ); ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_OCTET_STRING ) ); return( (int) len ); }
int asn1_write_oid( unsigned char **p, unsigned char *start, const char *oid, size_t oid_len ) { int ret; size_t len = 0; ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, (const unsigned char *) oid, oid_len ) ); ASN1_CHK_ADD( len , asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len , asn1_write_tag( p, start, ASN1_OID ) ); return( (int) len ); }
int asn1_write_ia5_string( unsigned char **p, unsigned char *start, const char *text, size_t text_len ) { int ret; size_t len = 0; ASN1_CHK_ADD( len, asn1_write_raw_buffer( p, start, (const unsigned char *) text, text_len ) ); ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) ); ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_IA5_STRING ) ); return( (int) len ); }