| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/rsa_private_key.h" | 5 #include "crypto/rsa_private_key.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 ASSERT_TRUE(keypair2->ExportPrivateKey(&output2)); | 438 ASSERT_TRUE(keypair2->ExportPrivateKey(&output2)); |
| 439 | 439 |
| 440 ASSERT_EQ(input1.size(), output1.size()); | 440 ASSERT_EQ(input1.size(), output1.size()); |
| 441 ASSERT_EQ(input2.size(), output2.size()); | 441 ASSERT_EQ(input2.size(), output2.size()); |
| 442 ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(), | 442 ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(), |
| 443 input1.size())); | 443 input1.size())); |
| 444 ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(), | 444 ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(), |
| 445 input2.size())); | 445 input2.size())); |
| 446 } | 446 } |
| 447 | 447 |
| 448 // The following test can run if either USE_NSS or USE_OPENSSL is defined, but | 448 // The following test can run if either USE_NSS_CERTS or USE_OPENSSL is defined, |
| 449 // not otherwise (since it uses crypto::RSAPrivateKey::CreateFromKey). | 449 // but not otherwise (since it uses crypto::RSAPrivateKey::CreateFromKey). |
| 450 #if defined(USE_NSS) || defined(USE_OPENSSL) | 450 #if defined(USE_NSS_CERTS) || defined(USE_OPENSSL) |
| 451 TEST(RSAPrivateKeyUnitTest, CreateFromKeyTest) { | 451 TEST(RSAPrivateKeyUnitTest, CreateFromKeyTest) { |
| 452 scoped_ptr<crypto::RSAPrivateKey> key_pair( | 452 scoped_ptr<crypto::RSAPrivateKey> key_pair( |
| 453 crypto::RSAPrivateKey::Create(256)); | 453 crypto::RSAPrivateKey::Create(256)); |
| 454 | 454 |
| 455 scoped_ptr<crypto::RSAPrivateKey> key_copy( | 455 scoped_ptr<crypto::RSAPrivateKey> key_copy( |
| 456 crypto::RSAPrivateKey::CreateFromKey(key_pair->key())); | 456 crypto::RSAPrivateKey::CreateFromKey(key_pair->key())); |
| 457 ASSERT_TRUE(key_copy.get()); | 457 ASSERT_TRUE(key_copy.get()); |
| 458 | 458 |
| 459 std::vector<uint8> privkey; | 459 std::vector<uint8> privkey; |
| 460 std::vector<uint8> pubkey; | 460 std::vector<uint8> pubkey; |
| 461 ASSERT_TRUE(key_pair->ExportPrivateKey(&privkey)); | 461 ASSERT_TRUE(key_pair->ExportPrivateKey(&privkey)); |
| 462 ASSERT_TRUE(key_pair->ExportPublicKey(&pubkey)); | 462 ASSERT_TRUE(key_pair->ExportPublicKey(&pubkey)); |
| 463 | 463 |
| 464 std::vector<uint8> privkey_copy; | 464 std::vector<uint8> privkey_copy; |
| 465 std::vector<uint8> pubkey_copy; | 465 std::vector<uint8> pubkey_copy; |
| 466 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); | 466 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); |
| 467 ASSERT_TRUE(key_copy->ExportPublicKey(&pubkey_copy)); | 467 ASSERT_TRUE(key_copy->ExportPublicKey(&pubkey_copy)); |
| 468 | 468 |
| 469 ASSERT_EQ(privkey, privkey_copy); | 469 ASSERT_EQ(privkey, privkey_copy); |
| 470 ASSERT_EQ(pubkey, pubkey_copy); | 470 ASSERT_EQ(pubkey, pubkey_copy); |
| 471 } | 471 } |
| 472 #endif | 472 #endif |
| 473 | 473 |
| OLD | NEW |