Return error first if the returned status is not ok

[ Merge of http://go/wvgerrit/148249 ]

Bug: 224375138
Test: GtsMediaDrmTests
Change-Id: I10f0c1bc28342d6cd5ae7d373ef554321bb6d3c8
This commit is contained in:
Rahul Frias
2022-03-21 14:43:54 -07:00
parent b07523f4c6
commit 587516dfa2

View File

@@ -1447,8 +1447,13 @@ CdmResponseType CryptoSession::GetBootCertificateChain(
&additional_signature_length); &additional_signature_length);
}); });
} }
return MapOEMCryptoResult(sts, GET_BOOT_CERTIFICATE_CHAIN_ERROR, if (sts != OEMCrypto_SUCCESS) {
"GetBootCertificateChain"); return MapOEMCryptoResult(sts, GET_BOOT_CERTIFICATE_CHAIN_ERROR,
"GetBootCertificateChain");
}
bcc->resize(bcc_length);
additional_signature->resize(additional_signature_length);
return NO_ERROR;
} }
CdmResponseType CryptoSession::GenerateCertificateKeyPair( CdmResponseType CryptoSession::GenerateCertificateKeyPair(
@@ -1494,6 +1499,11 @@ CdmResponseType CryptoSession::GenerateCertificateKeyPair(
&wrapped_private_key_length, &oemcrypto_key_type), &wrapped_private_key_length, &oemcrypto_key_type),
metrics_, oemcrypto_generate_certificate_key_pair_, status); metrics_, oemcrypto_generate_certificate_key_pair_, status);
}); });
if (status != OEMCrypto_SUCCESS) {
return MapOEMCryptoResult(status, GENERATE_CERTIFICATE_KEY_PAIR_ERROR,
"GenerateCertificateKeyPair");
}
public_key->resize(public_key_length); public_key->resize(public_key_length);
public_key_signature->resize(public_key_signature_length); public_key_signature->resize(public_key_signature_length);
wrapped_private_key->resize(wrapped_private_key_length); wrapped_private_key->resize(wrapped_private_key_length);
@@ -1505,13 +1515,10 @@ CdmResponseType CryptoSession::GenerateCertificateKeyPair(
} else { } else {
LOGE("Unexpected key type returned from GenerateCertificateKeyPair: %d", LOGE("Unexpected key type returned from GenerateCertificateKeyPair: %d",
static_cast<int>(oemcrypto_key_type)); static_cast<int>(oemcrypto_key_type));
return MapOEMCryptoResult(status, return GENERATE_CERTIFICATE_KEY_PAIR_UNKNOWN_TYPE_ERROR;
GENERATE_CERTIFICATE_KEY_PAIR_UNKNOWN_TYPE_ERROR,
"GenerateCertificateKeyPair");
} }
return MapOEMCryptoResult(status, GENERATE_CERTIFICATE_KEY_PAIR_ERROR, return NO_ERROR;
"GenerateCertificateKeyPair");
} }
CdmResponseType CryptoSession::LoadOemCertificatePrivateKey( CdmResponseType CryptoSession::LoadOemCertificatePrivateKey(
@@ -1539,7 +1546,9 @@ CdmResponseType CryptoSession::LoadOemCertificatePrivateKey(
// Private. // Private.
CdmResponseType CryptoSession::SelectKey(const std::string& key_id, CdmResponseType CryptoSession::SelectKey(const std::string& key_id,
CdmCipherMode cipher_mode) { CdmCipherMode cipher_mode) {
RETURN_IF_NOT_OPEN(CRYPTO_SESSION_NOT_OPEN);
const OEMCryptoResult sts = WithOecSessionLock("SelectKey", [&] { const OEMCryptoResult sts = WithOecSessionLock("SelectKey", [&] {
RETURN_IF_NULL(key_session_, OEMCrypto_ERROR_INVALID_SESSION);
return key_session_->SelectKey(key_id, cipher_mode); return key_session_->SelectKey(key_id, cipher_mode);
}); });