Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1206)

Unified Diff: crypto/ec_private_key_unittest.cc

Issue 1739403002: Cut down on usage of deprecated APIs in //crypto. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: grumble grumble string vector char uint8_t grumble Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crypto/ec_private_key_openssl.cc ('k') | crypto/ec_signature_creator_openssl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/ec_private_key_unittest.cc
diff --git a/crypto/ec_private_key_unittest.cc b/crypto/ec_private_key_unittest.cc
index 57af82ec6222f16015099a606c8264c9fef4064b..27d5ecbaaef58fc5a3605e8df90094c5f815225a 100644
--- a/crypto/ec_private_key_unittest.cc
+++ b/crypto/ec_private_key_unittest.cc
@@ -26,12 +26,8 @@ TEST(ECPrivateKeyUnitTest, InitRandomTest) {
std::vector<uint8_t> key1value;
std::vector<uint8_t> key2value;
- std::vector<uint8_t> key1params;
- std::vector<uint8_t> key2params;
- EXPECT_TRUE(keypair1->ExportValue(&key1value));
- EXPECT_TRUE(keypair2->ExportValue(&key2value));
- EXPECT_TRUE(keypair1->ExportECParams(&key1params));
- EXPECT_TRUE(keypair2->ExportECParams(&key2params));
+ EXPECT_TRUE(keypair1->ExportValueForTesting(&key1value));
+ EXPECT_TRUE(keypair2->ExportValueForTesting(&key2value));
std::vector<uint8_t> privkey1;
std::vector<uint8_t> privkey2;
@@ -57,17 +53,11 @@ TEST(ECPrivateKeyUnitTest, InitRandomTest) {
std::vector<uint8_t> key3value;
std::vector<uint8_t> key4value;
- std::vector<uint8_t> key3params;
- std::vector<uint8_t> key4params;
- EXPECT_TRUE(keypair3->ExportValue(&key3value));
- EXPECT_TRUE(keypair4->ExportValue(&key4value));
- EXPECT_TRUE(keypair3->ExportECParams(&key3params));
- EXPECT_TRUE(keypair4->ExportECParams(&key4params));
+ EXPECT_TRUE(keypair3->ExportValueForTesting(&key3value));
+ EXPECT_TRUE(keypair4->ExportValueForTesting(&key4value));
EXPECT_EQ(key1value, key3value);
EXPECT_EQ(key2value, key4value);
- EXPECT_EQ(key1params, key3params);
- EXPECT_EQ(key2params, key4params);
std::vector<uint8_t> pubkey3;
std::vector<uint8_t> pubkey4;
@@ -92,16 +82,10 @@ TEST(ECPrivateKeyUnitTest, Copy) {
std::vector<uint8_t> key1value;
std::vector<uint8_t> key2value;
- EXPECT_TRUE(keypair1->ExportValue(&key1value));
- EXPECT_TRUE(keypair2->ExportValue(&key2value));
+ EXPECT_TRUE(keypair1->ExportValueForTesting(&key1value));
+ EXPECT_TRUE(keypair2->ExportValueForTesting(&key2value));
EXPECT_EQ(key1value, key2value);
- std::vector<uint8_t> key1params;
- std::vector<uint8_t> key2params;
- EXPECT_TRUE(keypair1->ExportECParams(&key1params));
- EXPECT_TRUE(keypair2->ExportECParams(&key2params));
- EXPECT_EQ(key1params, key2params);
-
std::vector<uint8_t> pubkey1;
std::vector<uint8_t> pubkey2;
EXPECT_TRUE(keypair1->ExportPublicKey(&pubkey1));
@@ -136,7 +120,7 @@ TEST(ECPrivateKeyUnitTest, BadPasswordTest) {
}
TEST(ECPrivateKeyUnitTest, LoadNSSKeyTest) {
- static const unsigned char nss_key[] = {
+ static const uint8_t kNSSKey[] = {
0x30, 0x81, 0xb8, 0x30, 0x23, 0x06, 0x0a, 0x2a, 0x86, 0x48, 0x86, 0xf7,
0x0d, 0x01, 0x0c, 0x01, 0x03, 0x30, 0x15, 0x04, 0x10, 0x3f, 0xac, 0xe9,
0x38, 0xdb, 0x40, 0x6b, 0x26, 0x89, 0x09, 0x73, 0x18, 0x8d, 0x7f, 0x1c,
@@ -152,8 +136,9 @@ TEST(ECPrivateKeyUnitTest, LoadNSSKeyTest) {
0x2b, 0x3f, 0x53, 0xe5, 0x39, 0x54, 0x77, 0xe1, 0x1d, 0xe6, 0x81, 0x92,
0x58, 0x82, 0x14, 0xfb, 0x47, 0x85, 0x3c, 0xc3, 0xdf, 0xdd, 0xcc, 0x79,
0x9f, 0x41, 0x83, 0x72, 0xf2, 0x0a, 0xe9, 0xe1, 0x2c, 0x12, 0xb0, 0xb0,
- 0x0a, 0xb2, 0x1d, 0xca, 0x15, 0xb2, 0xca};
- static const unsigned char nss_pub_key[] = {
+ 0x0a, 0xb2, 0x1d, 0xca, 0x15, 0xb2, 0xca,
+ };
+ static const uint8_t kNSSPublicKey[] = {
0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
0x42, 0x00, 0x04, 0x85, 0x92, 0x9e, 0x95, 0x5c, 0x6b, 0x9e, 0xd6, 0x1e,
@@ -161,21 +146,20 @@ TEST(ECPrivateKeyUnitTest, LoadNSSKeyTest) {
0x15, 0x37, 0x6a, 0xe9, 0xaa, 0x0b, 0x34, 0x03, 0xfd, 0xca, 0x83, 0x0f,
0xd7, 0x5c, 0x5d, 0xc5, 0x53, 0x6e, 0xe5, 0xa9, 0x33, 0xd5, 0xcc, 0xab,
0x53, 0x78, 0xdd, 0xd6, 0x12, 0x3a, 0x5e, 0xeb, 0xbf, 0xdf, 0x16, 0xd3,
- 0x2c, 0x3b, 0xe8, 0xdb, 0x19, 0xfc, 0x5e};
+ 0x2c, 0x3b, 0xe8, 0xdb, 0x19, 0xfc, 0x5e,
+ };
scoped_ptr<crypto::ECPrivateKey> keypair_nss(
crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
- "", std::vector<uint8_t>(nss_key, nss_key + arraysize(nss_key)),
- std::vector<uint8_t>(nss_pub_key,
- nss_pub_key + arraysize(nss_pub_key))));
+ "", std::vector<uint8_t>(std::begin(kNSSKey), std::end(kNSSKey)),
+ std::vector<uint8_t>(std::begin(kNSSPublicKey),
+ std::end(kNSSPublicKey))));
EXPECT_TRUE(keypair_nss.get());
}
-// Although the plan is to transition from OpenSSL to NSS, ensure NSS can import
-// OpenSSL's format so that it is possible to rollback.
TEST(ECPrivateKeyUnitTest, LoadOpenSSLKeyTest) {
- static const unsigned char openssl_key[] = {
+ static const uint8_t kOpenSSLKey[] = {
0x30, 0x81, 0xb0, 0x30, 0x1b, 0x06, 0x0a, 0x2a, 0x86, 0x48, 0x86, 0xf7,
0x0d, 0x01, 0x0c, 0x01, 0x03, 0x30, 0x0d, 0x04, 0x08, 0xb2, 0xfe, 0x68,
0xc2, 0xea, 0x0f, 0x10, 0x9c, 0x02, 0x01, 0x01, 0x04, 0x81, 0x90, 0xe2,
@@ -190,8 +174,9 @@ TEST(ECPrivateKeyUnitTest, LoadOpenSSLKeyTest) {
0x19, 0xbd, 0x31, 0xa7, 0x85, 0x47, 0xb3, 0xe9, 0xb3, 0x50, 0x3c, 0xc9,
0x32, 0x37, 0x1a, 0x93, 0x78, 0x48, 0x78, 0x82, 0xde, 0xad, 0x5c, 0xf2,
0xcf, 0xf2, 0xbb, 0x2c, 0x44, 0x05, 0x7f, 0x4a, 0xf9, 0xb1, 0x2b, 0xdd,
- 0x49, 0xf6, 0x7e, 0xd0, 0x42, 0xaa, 0x14, 0x3c, 0x24, 0x77, 0xb4};
- static const unsigned char openssl_pub_key[] = {
+ 0x49, 0xf6, 0x7e, 0xd0, 0x42, 0xaa, 0x14, 0x3c, 0x24, 0x77, 0xb4,
+ };
+ static const uint8_t kOpenSSLPublicKey[] = {
0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
0x42, 0x00, 0x04, 0xb9, 0xda, 0x0d, 0x71, 0x60, 0xb3, 0x63, 0x28, 0x22,
@@ -199,16 +184,37 @@ TEST(ECPrivateKeyUnitTest, LoadOpenSSLKeyTest) {
0xf6, 0xdb, 0xc4, 0xfe, 0x0b, 0x5d, 0xe1, 0x11, 0x39, 0x49, 0xa6, 0x50,
0xa8, 0xe3, 0x4a, 0xc0, 0x40, 0x88, 0xb8, 0x38, 0x3f, 0x56, 0xfb, 0x33,
0x8d, 0xd4, 0x64, 0x91, 0xd6, 0x15, 0x77, 0x42, 0x27, 0xc5, 0xaa, 0x44,
- 0xff, 0xab, 0x4d, 0xb5, 0x7e, 0x25, 0x3d};
+ 0xff, 0xab, 0x4d, 0xb5, 0x7e, 0x25, 0x3d,
+ };
+ static const uint8_t kOpenSSLRawPublicKey[] = {
+ 0xb9, 0xda, 0x0d, 0x71, 0x60, 0xb3, 0x63, 0x28, 0x22, 0x67, 0xe7,
+ 0xe0, 0xa3, 0xf8, 0x00, 0x8e, 0x4c, 0x89, 0xed, 0x31, 0x34, 0xf6,
+ 0xdb, 0xc4, 0xfe, 0x0b, 0x5d, 0xe1, 0x11, 0x39, 0x49, 0xa6, 0x50,
+ 0xa8, 0xe3, 0x4a, 0xc0, 0x40, 0x88, 0xb8, 0x38, 0x3f, 0x56, 0xfb,
+ 0x33, 0x8d, 0xd4, 0x64, 0x91, 0xd6, 0x15, 0x77, 0x42, 0x27, 0xc5,
+ 0xaa, 0x44, 0xff, 0xab, 0x4d, 0xb5, 0x7e, 0x25, 0x3d,
+ };
scoped_ptr<crypto::ECPrivateKey> keypair_openssl(
crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
- "", std::vector<uint8_t>(openssl_key,
- openssl_key + arraysize(openssl_key)),
- std::vector<uint8_t>(openssl_pub_key,
- openssl_pub_key + arraysize(openssl_pub_key))));
+ "",
+ std::vector<uint8_t>(std::begin(kOpenSSLKey), std::end(kOpenSSLKey)),
+ std::vector<uint8_t>(std::begin(kOpenSSLPublicKey),
+ std::end(kOpenSSLPublicKey))));
EXPECT_TRUE(keypair_openssl.get());
+
+ std::vector<uint8_t> public_key;
+ EXPECT_TRUE(keypair_openssl->ExportPublicKey(&public_key));
+ EXPECT_EQ(std::vector<uint8_t>(std::begin(kOpenSSLPublicKey),
+ std::end(kOpenSSLPublicKey)),
+ public_key);
+
+ std::string raw_public_key;
+ EXPECT_TRUE(keypair_openssl->ExportRawPublicKey(&raw_public_key));
+ EXPECT_EQ(std::string(reinterpret_cast<const char*>(kOpenSSLRawPublicKey),
+ arraysize(kOpenSSLRawPublicKey)),
+ raw_public_key);
}
// The Android code writes out Channel IDs differently from the NSS
@@ -216,7 +222,7 @@ TEST(ECPrivateKeyUnitTest, LoadOpenSSLKeyTest) {
// should support either.
#if defined(USE_OPENSSL)
TEST(ECPrivateKeyUnitTest, LoadOldOpenSSLKeyTest) {
- static const unsigned char openssl_key[] = {
+ static const uint8_t kOpenSSLKey[] = {
0x30, 0x82, 0x01, 0xa1, 0x30, 0x1b, 0x06, 0x0a, 0x2a, 0x86, 0x48, 0x86,
0xf7, 0x0d, 0x01, 0x0c, 0x01, 0x03, 0x30, 0x0d, 0x04, 0x08, 0x86, 0xaa,
0xd7, 0xdf, 0x3b, 0x91, 0x97, 0x60, 0x02, 0x01, 0x01, 0x04, 0x82, 0x01,
@@ -252,8 +258,9 @@ TEST(ECPrivateKeyUnitTest, LoadOldOpenSSLKeyTest) {
0xf6, 0x61, 0x63, 0x0b, 0xfb, 0x42, 0xfd, 0x52, 0xf4, 0xc4, 0x35, 0x0c,
0xc2, 0xc1, 0x55, 0x22, 0x42, 0x2f, 0x13, 0x7d, 0x93, 0x27, 0xc8, 0x11,
0x35, 0xc5, 0xe3, 0xc5, 0xaa, 0x15, 0x3c, 0xac, 0x30, 0xbc, 0x45, 0x16,
- 0xed};
- static const unsigned char openssl_pub_key[] = {
+ 0xed,
+ };
+ static const uint8_t kOpenSSLPublicKey[] = {
0x30, 0x82, 0x01, 0x4b, 0x30, 0x82, 0x01, 0x03, 0x06, 0x07, 0x2a, 0x86,
0x48, 0xce, 0x3d, 0x02, 0x01, 0x30, 0x81, 0xf7, 0x02, 0x01, 0x01, 0x30,
0x2c, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01, 0x02, 0x21,
@@ -281,14 +288,15 @@ TEST(ECPrivateKeyUnitTest, LoadOldOpenSSLKeyTest) {
0x4a, 0xe7, 0x20, 0xcb, 0x90, 0xa0, 0x1f, 0x18, 0x18, 0x72, 0xb5, 0x21,
0x88, 0x38, 0xc0, 0xdb, 0xba, 0xf6, 0x99, 0xd8, 0xa5, 0x3b, 0x83, 0xe9,
0xe3, 0xd5, 0x61, 0x99, 0x73, 0x42, 0xc6, 0x6c, 0xe8, 0x0a, 0x95, 0x40,
- 0x41, 0x3b, 0x0d, 0x10, 0xa7, 0x4a, 0x93, 0xdb, 0x5a, 0xe7, 0xec};
+ 0x41, 0x3b, 0x0d, 0x10, 0xa7, 0x4a, 0x93, 0xdb, 0x5a, 0xe7, 0xec,
+ };
scoped_ptr<crypto::ECPrivateKey> keypair_openssl(
crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
- "", std::vector<uint8_t>(openssl_key,
- openssl_key + arraysize(openssl_key)),
- std::vector<uint8_t>(openssl_pub_key,
- openssl_pub_key + arraysize(openssl_pub_key))));
+ "",
+ std::vector<uint8_t>(std::begin(kOpenSSLKey), std::end(kOpenSSLKey)),
+ std::vector<uint8_t>(std::begin(kOpenSSLPublicKey),
+ std::end(kOpenSSLPublicKey))));
EXPECT_TRUE(keypair_openssl.get());
}
« no previous file with comments | « crypto/ec_private_key_openssl.cc ('k') | crypto/ec_signature_creator_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698