mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 15:55:37 +01:00
Added asn1_write_bitstring() and asn1_write_octet_string()
This commit is contained in:
parent
ef0ba55a78
commit
598e450538
@ -48,6 +48,10 @@ int asn1_write_printable_string( unsigned char **p, unsigned char *start,
|
||||
char *text );
|
||||
int asn1_write_ia5_string( unsigned char **p, unsigned char *start,
|
||||
char *text );
|
||||
int asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
||||
const unsigned char *buf, size_t bits );
|
||||
int asn1_write_octet_string( unsigned char **p, unsigned char *start,
|
||||
const unsigned char *buf, size_t size );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -216,9 +216,9 @@ int asn1_write_printable_string( unsigned char **p, unsigned char *start,
|
||||
|
||||
return( len );
|
||||
}
|
||||
|
||||
|
||||
int asn1_write_ia5_string( unsigned char **p, unsigned char *start,
|
||||
char *text )
|
||||
char *text )
|
||||
{
|
||||
int ret;
|
||||
size_t len = 0;
|
||||
@ -238,6 +238,51 @@ int asn1_write_ia5_string( unsigned char **p, unsigned char *start,
|
||||
|
||||
return( len );
|
||||
}
|
||||
|
||||
|
||||
int asn1_write_bitstring( unsigned char **p, unsigned char *start,
|
||||
const unsigned char *buf, size_t bits )
|
||||
{
|
||||
int ret;
|
||||
size_t len = 0, size;
|
||||
|
||||
size = ( bits / 8 ) + ( ( bits % 8 ) ? 1 : 0 );
|
||||
|
||||
// Calculate byte length
|
||||
//
|
||||
if( *p - start < (int) size + 1 )
|
||||
return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
|
||||
|
||||
len = size + 1;
|
||||
(*p) -= size;
|
||||
memcpy( *p, buf, size );
|
||||
|
||||
// Write unused bits
|
||||
//
|
||||
*--(*p) = size * 8 - bits;
|
||||
|
||||
ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
|
||||
ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_BIT_STRING ) );
|
||||
|
||||
return( 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;
|
||||
|
||||
if( *p - start < (int) size + 1 )
|
||||
return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL );
|
||||
|
||||
len = size;
|
||||
(*p) -= len;
|
||||
memcpy( *p, buf, len );
|
||||
|
||||
ASN1_CHK_ADD( len, asn1_write_len( p, start, len ) );
|
||||
ASN1_CHK_ADD( len, asn1_write_tag( p, start, ASN1_OCTET_STRING ) );
|
||||
|
||||
return( len );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user