1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-09-04 03:22:10 +03:00

Improving readability of x509_crt and x509write_crt

Signed-off-by: pespacek <peter.spacek@silabs.com>
This commit is contained in:
pespacek
2022-02-28 11:49:54 +01:00
committed by pespacek
parent 3015148ae6
commit d924e55944
2 changed files with 24 additions and 25 deletions

View File

@@ -2378,7 +2378,7 @@ static int x509_crt_verifycrl( mbedtls_x509_crt *crt, mbedtls_x509_crt *ca,
#if defined(MBEDTLS_USE_PSA_CRYPTO) #if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_algorithm = mbedtls_psa_translate_md( crl_list->sig_md ); psa_algorithm = mbedtls_psa_translate_md( crl_list->sig_md );
if(psa_hash_compute( psa_algorithm, if( psa_hash_compute( psa_algorithm,
crl_list->tbs.p, crl_list->tbs.p,
crl_list->tbs.len, crl_list->tbs.len,
hash, hash,
@@ -2403,7 +2403,6 @@ static int x509_crt_verifycrl( mbedtls_x509_crt *crt, mbedtls_x509_crt *ca,
} }
#endif /* MBEDTLS_USE_PSA_CRYPTO */ #endif /* MBEDTLS_USE_PSA_CRYPTO */
if( x509_profile_check_key( profile, &ca->pk ) != 0 ) if( x509_profile_check_key( profile, &ca->pk ) != 0 )
flags |= MBEDTLS_X509_BADCERT_BAD_KEY; flags |= MBEDTLS_X509_BADCERT_BAD_KEY;

View File

@@ -187,7 +187,8 @@ static int mbedtls_x509write_crt_set_key_identifier( mbedtls_x509write_cert
#endif /* MBEDTLS_USE_PSA_CRYPTO */ #endif /* MBEDTLS_USE_PSA_CRYPTO */
memset( buf, 0, sizeof(buf) ); memset( buf, 0, sizeof(buf) );
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_pk_write_pubkey( &c, MBEDTLS_ASN1_CHK_ADD( len,
mbedtls_pk_write_pubkey( &c,
buf, buf,
is_ca ? is_ca ?
ctx->issuer_key : ctx->issuer_key :
@@ -216,8 +217,7 @@ static int mbedtls_x509write_crt_set_key_identifier( mbedtls_x509write_cert
len = 20; len = 20;
MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) ); MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_len( &c, buf, len ) );
MBEDTLS_ASN1_CHK_ADD( len, MBEDTLS_ASN1_CHK_ADD( len, mbedtls_asn1_write_tag( &c, buf, tag ) );
mbedtls_asn1_write_tag( &c, buf, tag ) );
if( is_ca ) // writes AuthorityKeyIdentifier sequence if( is_ca ) // writes AuthorityKeyIdentifier sequence
{ {
@@ -228,17 +228,17 @@ static int mbedtls_x509write_crt_set_key_identifier( mbedtls_x509write_cert
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONSTRUCTED |
MBEDTLS_ASN1_SEQUENCE ) ); MBEDTLS_ASN1_SEQUENCE ) );
} }
return mbedtls_x509write_crt_set_extension(
ctx, if( is_ca )
is_ca ? MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER : return mbedtls_x509write_crt_set_extension( ctx,
MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER,
MBEDTLS_OID_SIZE( MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER ),
0, buf + sizeof(buf) - len, len );
return mbedtls_x509write_crt_set_extension( ctx,
MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER, MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER,
is_ca ? MBEDTLS_OID_SIZE( MBEDTLS_OID_SIZE( MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER ),
MBEDTLS_OID_AUTHORITY_KEY_IDENTIFIER ) : 0, buf + sizeof(buf) - len, len );
MBEDTLS_OID_SIZE(
MBEDTLS_OID_SUBJECT_KEY_IDENTIFIER ),
0,
buf + sizeof( buf ) - len,
len );
} }
int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ctx ) int mbedtls_x509write_crt_set_subject_key_identifier( mbedtls_x509write_cert *ctx )