Cut down on usage of deprecated APIs in //crypto.
SSL_library_init is deprecated. It's CRYPTO_library_init. Switch from the
legacy ASN.1 APIs to the new parsers where feasible.
ECPrivateKey::CreateFromEncryptedPrivateKeyInfo is left alone for now as we
still need a new version of those APIs.
This also adds a scoper for CBB for use in later CLs.
BUG=499653
Review URL: https://codereview.chromium.org/1739403002
Cr-Commit-Position: refs/heads/master@{#378610}
diff --git a/crypto/ec_private_key_nss.cc b/crypto/ec_private_key_nss.cc
index b65de95..989b7ad 100644
--- a/crypto/ec_private_key_nss.cc
+++ b/crypto/ec_private_key_nss.cc
@@ -26,10 +26,9 @@
namespace {
-// Copied from rsa_private_key_nss.cc.
-static bool ReadAttribute(SECKEYPrivateKey* key,
- CK_ATTRIBUTE_TYPE type,
- std::vector<uint8_t>* output) {
+static bool AppendAttribute(SECKEYPrivateKey* key,
+ CK_ATTRIBUTE_TYPE type,
+ std::vector<uint8_t>* output) {
SECItem item;
SECStatus rv;
rv = PK11_ReadRawAttribute(PK11_TypePrivKey, key, type, &item);
@@ -38,7 +37,7 @@
return false;
}
- output->assign(item.data, item.data + item.len);
+ output->insert(output->end(), item.data, item.data + item.len);
SECITEM_FreeItem(&item, PR_FALSE);
return true;
}
@@ -311,12 +310,14 @@
return true;
}
-bool ECPrivateKey::ExportValue(std::vector<uint8_t>* output) {
- return ReadAttribute(key_, CKA_VALUE, output);
-}
-
-bool ECPrivateKey::ExportECParams(std::vector<uint8_t>* output) {
- return ReadAttribute(key_, CKA_EC_PARAMS, output);
+bool ECPrivateKey::ExportValueForTesting(std::vector<uint8_t>* output) {
+ // This serialization format is purely for testing equality, so just
+ // concatenate the raw private key (always 32 bytes for P-256) with the
+ // parameters.
+ output->clear();
+ return AppendAttribute(key_, CKA_VALUE, output) &&
+ output->size() == 32 &&
+ AppendAttribute(key_, CKA_EC_PARAMS, output);
}
ECPrivateKey::ECPrivateKey() : key_(NULL), public_key_(NULL) {}