Refactor the VERIFY_AND_SET_OID macro to simplify so it works on older C compilers like Visual Studio.

This commit is contained in:
David Garske
2018-02-07 12:17:03 -08:00
parent d78e45dbb6
commit 4a6bb20ba6

55
wolfcrypt/src/asn.c Normal file → Executable file
View File

@ -6177,26 +6177,16 @@ int DecodePolicyOID(char *out, word32 outSz, byte *in, word32 inSz)
/* Macro to check if bit is set, if not sets and return success. /* Macro to check if bit is set, if not sets and return success.
Otherwise returns failure */ Otherwise returns failure */
/* Macro required here because bit-field operation */
#ifndef WOLFSSL_NO_ASN_STRICT #ifndef WOLFSSL_NO_ASN_STRICT
#define VERIFY_AND_SET_OID(bit) \ #define VERIFY_AND_SET_OID(bit) \
({ \ if (bit == 0) \
int bitvalid; \
if (bit == 0) { \
bit = 1; \ bit = 1; \
bitvalid = 0; /* success */ \ else \
} \ return ASN_OBJECT_ID_E;
else { \
bitvalid = -1; /* fail */ \
} \
bitvalid; \
})
#else #else
/* With no strict defined, the verify is skipped */ /* With no strict defined, the verify is skipped */
#define VERIFY_AND_SET_OID(bit) \ #define VERIFY_AND_SET_OID(bit) bit = 1;
({ \
bit = 1; \
0; /* success */ \
})
#endif #endif
static int DecodeCertExtensions(DecodedCert* cert) static int DecodeCertExtensions(DecodedCert* cert)
@ -6205,7 +6195,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
* index. It is works starting with the recorded extensions pointer. * index. It is works starting with the recorded extensions pointer.
*/ */
{ {
int ret; int ret = 0;
word32 idx = 0; word32 idx = 0;
int sz = cert->extensionsSz; int sz = cert->extensionsSz;
byte* input = cert->extensions; byte* input = cert->extensions;
@ -6267,8 +6257,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
switch (oid) { switch (oid) {
case BASIC_CA_OID: case BASIC_CA_OID:
if (VERIFY_AND_SET_OID(cert->extBasicConstSet)) VERIFY_AND_SET_OID(cert->extBasicConstSet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extBasicConstCrit = critical; cert->extBasicConstCrit = critical;
#endif #endif
@ -6277,8 +6266,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
break; break;
case CRL_DIST_OID: case CRL_DIST_OID:
if (VERIFY_AND_SET_OID(cert->extCRLdistSet)) VERIFY_AND_SET_OID(cert->extCRLdistSet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extCRLdistCrit = critical; cert->extCRLdistCrit = critical;
#endif #endif
@ -6287,8 +6275,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
break; break;
case AUTH_INFO_OID: case AUTH_INFO_OID:
if (VERIFY_AND_SET_OID(cert->extAuthInfoSet)) VERIFY_AND_SET_OID(cert->extAuthInfoSet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extAuthInfoCrit = critical; cert->extAuthInfoCrit = critical;
#endif #endif
@ -6297,8 +6284,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
break; break;
case ALT_NAMES_OID: case ALT_NAMES_OID:
if (VERIFY_AND_SET_OID(cert->extSubjAltNameSet)) VERIFY_AND_SET_OID(cert->extSubjAltNameSet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extSubjAltNameCrit = critical; cert->extSubjAltNameCrit = critical;
#endif #endif
@ -6308,8 +6294,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
break; break;
case AUTH_KEY_OID: case AUTH_KEY_OID:
if (VERIFY_AND_SET_OID(cert->extAuthKeyIdSet)) VERIFY_AND_SET_OID(cert->extAuthKeyIdSet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extAuthKeyIdCrit = critical; cert->extAuthKeyIdCrit = critical;
#endif #endif
@ -6318,8 +6303,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
break; break;
case SUBJ_KEY_OID: case SUBJ_KEY_OID:
if (VERIFY_AND_SET_OID(cert->extSubjKeyIdSet)) VERIFY_AND_SET_OID(cert->extSubjKeyIdSet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extSubjKeyIdCrit = critical; cert->extSubjKeyIdCrit = critical;
#endif #endif
@ -6341,8 +6325,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
case CERT_POLICY_OID: case CERT_POLICY_OID:
#ifdef WOLFSSL_SEP #ifdef WOLFSSL_SEP
if (VERIFY_AND_SET_OID(cert->extCertPolicySet)) VERIFY_AND_SET_OID(cert->extCertPolicySet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extCertPolicyCrit = critical; cert->extCertPolicyCrit = critical;
#endif #endif
@ -6357,8 +6340,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
break; break;
case KEY_USAGE_OID: case KEY_USAGE_OID:
if (VERIFY_AND_SET_OID(cert->extKeyUsageSet)) VERIFY_AND_SET_OID(cert->extKeyUsageSet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extKeyUsageCrit = critical; cert->extKeyUsageCrit = critical;
#endif #endif
@ -6367,8 +6349,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
break; break;
case EXT_KEY_USAGE_OID: case EXT_KEY_USAGE_OID:
if (VERIFY_AND_SET_OID(cert->extExtKeyUsageSet)) VERIFY_AND_SET_OID(cert->extExtKeyUsageSet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extExtKeyUsageCrit = critical; cert->extExtKeyUsageCrit = critical;
#endif #endif
@ -6387,8 +6368,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
return ASN_NAME_INVALID_E; return ASN_NAME_INVALID_E;
} }
#endif #endif
if (VERIFY_AND_SET_OID(cert->extNameConstraintSet)) VERIFY_AND_SET_OID(cert->extNameConstraintSet);
return ASN_OBJECT_ID_E;
#ifdef OPENSSL_EXTRA #ifdef OPENSSL_EXTRA
cert->extNameConstraintCrit = critical; cert->extNameConstraintCrit = critical;
#endif #endif
@ -6398,8 +6378,7 @@ static int DecodeCertExtensions(DecodedCert* cert)
#endif /* IGNORE_NAME_CONSTRAINTS */ #endif /* IGNORE_NAME_CONSTRAINTS */
case INHIBIT_ANY_OID: case INHIBIT_ANY_OID:
if (VERIFY_AND_SET_OID(cert->inhibitAnyOidSet)) VERIFY_AND_SET_OID(cert->inhibitAnyOidSet);
return ASN_OBJECT_ID_E;
WOLFSSL_MSG("Inhibit anyPolicy extension not supported yet."); WOLFSSL_MSG("Inhibit anyPolicy extension not supported yet.");
break; break;