Skip to content

Commit 8cd9af3

Browse files
committed
Peer review fixes
1 parent 99c0894 commit 8cd9af3

1 file changed

Lines changed: 25 additions & 21 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9377,14 +9377,15 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
93779377
if (rsa == NULL)
93789378
return MEMORY_E;
93799379

9380-
wc_InitRsaKey(rsa, heap);
9381-
if (wc_RsaPrivateKeyDecode(key, &tmpIdx, rsa, keySz) == 0) {
9382-
*algoID = RSAk;
9383-
}
9384-
else {
9385-
WOLFSSL_MSG("Not RSA DER key");
9380+
if (wc_InitRsaKey(rsa, heap) == 0) {
9381+
if (wc_RsaPrivateKeyDecode(key, &tmpIdx, rsa, keySz) == 0) {
9382+
*algoID = RSAk;
9383+
}
9384+
else {
9385+
WOLFSSL_MSG("Not RSA DER key");
9386+
}
9387+
wc_FreeRsaKey(rsa);
93869388
}
9387-
wc_FreeRsaKey(rsa);
93889389
XFREE(rsa, heap, DYNAMIC_TYPE_TMP_BUFFER);
93899390
}
93909391
#endif /* !NO_RSA && !NO_ASN_CRYPT */
@@ -9395,22 +9396,23 @@ int wc_GetKeyOID(byte* key, word32 keySz, const byte** curveOID, word32* oidSz,
93959396
return MEMORY_E;
93969397

93979398
tmpIdx = 0;
9398-
wc_ecc_init_ex(ecc, heap, INVALID_DEVID);
9399-
if (wc_EccPrivateKeyDecode(key, &tmpIdx, ecc, keySz) == 0) {
9400-
*algoID = ECDSAk;
9401-
9402-
/* now find oid */
9403-
if (wc_ecc_get_oid(ecc->dp->oidSum, curveOID, oidSz) < 0) {
9404-
WOLFSSL_MSG("Error getting ECC curve OID");
9405-
wc_ecc_free(ecc);
9406-
XFREE(ecc, heap, DYNAMIC_TYPE_TMP_BUFFER);
9407-
return BAD_FUNC_ARG;
9399+
if (wc_ecc_init_ex(ecc, heap, INVALID_DEVID) == 0) {
9400+
if (wc_EccPrivateKeyDecode(key, &tmpIdx, ecc, keySz) == 0) {
9401+
*algoID = ECDSAk;
9402+
9403+
/* now find oid */
9404+
if (wc_ecc_get_oid(ecc->dp->oidSum, curveOID, oidSz) < 0) {
9405+
WOLFSSL_MSG("Error getting ECC curve OID");
9406+
wc_ecc_free(ecc);
9407+
XFREE(ecc, heap, DYNAMIC_TYPE_TMP_BUFFER);
9408+
return BAD_FUNC_ARG;
9409+
}
94089410
}
9411+
else {
9412+
WOLFSSL_MSG("Not ECC DER key either");
9413+
}
9414+
wc_ecc_free(ecc);
94099415
}
9410-
else {
9411-
WOLFSSL_MSG("Not ECC DER key either");
9412-
}
9413-
wc_ecc_free(ecc);
94149416
XFREE(ecc, heap, DYNAMIC_TYPE_TMP_BUFFER);
94159417
}
94169418
#endif /* HAVE_ECC && !NO_ASN_CRYPT */
@@ -37323,3 +37325,5 @@ const byte* AsnHashesGetHash(const AsnHashes* hashes, int hashAlg, int* size)
3732337325

3732437326

3732537327
#endif /* WOLFSSL_SEP */
37328+
37329+
#undef ERROR_OUT

0 commit comments

Comments
 (0)