mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-24 15:40:03 +00:00
ASN1 tests: Match "Empty INTEGER" with the actual library behavior
mbedtls_asn1_get_int() and mbedtls_asn1_get_mpi() behave differently on an empty INTEGER (0200). Don't change the library behavior for now because this might break interoperability in some applications. Write a test function that matches the library behavior.
This commit is contained in:
parent
03c165e1e1
commit
321adb297c
@ -164,8 +164,7 @@ Not BOOLEAN
|
||||
get_boolean:"020101":0:MBEDTLS_ERR_ASN1_UNEXPECTED_TAG
|
||||
|
||||
Empty INTEGER
|
||||
depends_on:SUPPORT_NEGATIVE_INTEGERS
|
||||
get_integer:"0200":"":MBEDTLS_ERR_ASN1_INVALID_LENGTH
|
||||
empty_integer:"0200"
|
||||
|
||||
INTEGER 0
|
||||
get_integer:"020100":"0":0
|
||||
|
@ -250,6 +250,41 @@ void get_boolean( const data_t *input,
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void empty_integer( const data_t *input )
|
||||
{
|
||||
unsigned char *p;
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
mbedtls_mpi actual_mpi;
|
||||
#endif
|
||||
int val;
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
mbedtls_mpi_init( & actual_mpi );
|
||||
#endif
|
||||
|
||||
/* An INTEGER with no content is not valid. */
|
||||
p = input->x;
|
||||
TEST_EQUAL( mbedtls_asn1_get_int( &p, input->x + input->len, &val ),
|
||||
MBEDTLS_ERR_ASN1_INVALID_LENGTH );
|
||||
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
/* INTEGERs are sometimes abused as bitstrings, so the library accepts
|
||||
* an INTEGER with empty content and gives it the value 0. */
|
||||
p = input->x;
|
||||
TEST_EQUAL( mbedtls_asn1_get_mpi( &p, input->x + input->len, &actual_mpi ),
|
||||
0 );
|
||||
TEST_EQUAL( mbedtls_mpi_cmp_int( &actual_mpi, 0 ), 0 );
|
||||
#endif
|
||||
|
||||
exit:
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
mbedtls_mpi_free( &actual_mpi );
|
||||
#endif
|
||||
/*empty cleanup in some configurations*/ ;
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void get_integer( const data_t *input,
|
||||
const char *expected_hex, int expected_result )
|
||||
|
Loading…
x
Reference in New Issue
Block a user