diff --git a/include/polarssl/asn1write.h b/include/polarssl/asn1write.h index 6e4a25798..9b98afe2e 100644 --- a/include/polarssl/asn1write.h +++ b/include/polarssl/asn1write.h @@ -52,6 +52,8 @@ 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 ); +int asn1_write_raw_buffer( unsigned char **p, unsigned char *start, + const unsigned char *buf, size_t size ); #ifdef __cplusplus } diff --git a/library/asn1write.c b/library/asn1write.c index fc85bf990..f08e105d2 100644 --- a/library/asn1write.c +++ b/library/asn1write.c @@ -272,7 +272,7 @@ int asn1_write_octet_string( unsigned char **p, unsigned char *start, int ret; size_t len = 0; - if( *p - start < (int) size + 1 ) + if( *p - start < (int) size ) return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); len = size; @@ -285,4 +285,19 @@ int asn1_write_octet_string( unsigned char **p, unsigned char *start, return( len ); } +int asn1_write_raw_buffer( unsigned char **p, unsigned char *start, + const unsigned char *buf, size_t size ) +{ + size_t len = 0; + + if( *p - start < (int) size ) + return( POLARSSL_ERR_ASN1_BUF_TOO_SMALL ); + + len = size; + (*p) -= len; + memcpy( *p, buf, len ); + + return( len ); +} + #endif