Index: crypto/ec_private_key_nss.cc |
diff --git a/crypto/ec_private_key_nss.cc b/crypto/ec_private_key_nss.cc |
index b65de955aa3265f43248e44ed39c2cc82cf29c2c..989b7ade2025996b329adfc115cbabd3515fc743 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) {} |