diff options
author | davidben <davidben@chromium.org> | 2016-03-01 15:47:47 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-01 23:48:37 +0000 |
commit | 7dad2a3ec1c5eada75bdd6af49a17c85113814e8 (patch) | |
tree | d8d4121ba870fc4f6554ba562353604a8718fc7d /crypto/ec_private_key_nss.cc | |
parent | a4967ca6f74d502d20bf5f99b85d04b155351158 (diff) | |
download | chromium_src-7dad2a3ec1c5eada75bdd6af49a17c85113814e8.zip chromium_src-7dad2a3ec1c5eada75bdd6af49a17c85113814e8.tar.gz chromium_src-7dad2a3ec1c5eada75bdd6af49a17c85113814e8.tar.bz2 |
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}
Diffstat (limited to 'crypto/ec_private_key_nss.cc')
-rw-r--r-- | crypto/ec_private_key_nss.cc | 23 |
1 files changed, 12 insertions, 11 deletions
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 @@ extern "C" { 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 @@ static bool ReadAttribute(SECKEYPrivateKey* key, 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 @@ bool ECPrivateKey::ExportRawPublicKey(std::string* output) { 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) {} |