Determine whether CRT is initialized or not through raw data pointer
Previously, `mbedtls_x509_crt_der_internal()` used the `version` field
(which is `0` after initialization but strictly greater than 0 once a
CRT has successfully been parsed) to determine whether an
`mbedtls_x509_crt` instance had already been setup.
Preparating for the removal of `version` from the structure, this
commit modifies the code to instead peek at the raw data pointer,
which is NULL as long as the CRT structure hasn't been setup with a CRT,
and will be kept in the new CRT structure.
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 8ac7dd4..9aef69a 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -2955,7 +2955,7 @@
#endif
crt = ssl->conf->ca_chain;
- while( crt != NULL && crt->version != 0 )
+ while( crt != NULL && crt->raw.p != NULL )
{
dn_size = crt->subject_raw.len;
diff --git a/library/x509_crt.c b/library/x509_crt.c
index 63823d3..060c015 100644
--- a/library/x509_crt.c
+++ b/library/x509_crt.c
@@ -1321,7 +1321,7 @@
if( crt == NULL || buf == NULL )
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
- while( crt->version != 0 && crt->next != NULL )
+ while( crt->raw.p != NULL && crt->next != NULL )
{
prev = crt;
crt = crt->next;
@@ -1330,7 +1330,7 @@
/*
* Add new certificate on the end of the chain if needed.
*/
- if( crt->version != 0 && crt->next == NULL )
+ if( crt->raw.p != NULL && crt->next == NULL )
{
crt->next = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) );