| 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_CERTS or USE_OPENSSL is defined, | |
| 449 // but not otherwise (since it uses crypto::RSAPrivateKey::CreateFromKey). | |
| 450 #if defined(USE_NSS_CERTS) || defined(USE_OPENSSL) | |
| 451 TEST(RSAPrivateKeyUnitTest, CreateFromKeyTest) { | 448 TEST(RSAPrivateKeyUnitTest, CreateFromKeyTest) { |
| 452 scoped_ptr<crypto::RSAPrivateKey> key_pair( | 449 scoped_ptr<crypto::RSAPrivateKey> key_pair( |
| 453 crypto::RSAPrivateKey::Create(256)); | 450 crypto::RSAPrivateKey::Create(256)); |
| 454 | 451 |
| 455 scoped_ptr<crypto::RSAPrivateKey> key_copy( | 452 scoped_ptr<crypto::RSAPrivateKey> key_copy( |
| 456 crypto::RSAPrivateKey::CreateFromKey(key_pair->key())); | 453 crypto::RSAPrivateKey::CreateFromKey(key_pair->key())); |
| 457 ASSERT_TRUE(key_copy.get()); | 454 ASSERT_TRUE(key_copy.get()); |
| 458 | 455 |
| 459 std::vector<uint8> privkey; | 456 std::vector<uint8> privkey; |
| 460 std::vector<uint8> pubkey; | 457 std::vector<uint8> pubkey; |
| 461 ASSERT_TRUE(key_pair->ExportPrivateKey(&privkey)); | 458 ASSERT_TRUE(key_pair->ExportPrivateKey(&privkey)); |
| 462 ASSERT_TRUE(key_pair->ExportPublicKey(&pubkey)); | 459 ASSERT_TRUE(key_pair->ExportPublicKey(&pubkey)); |
| 463 | 460 |
| 464 std::vector<uint8> privkey_copy; | 461 std::vector<uint8> privkey_copy; |
| 465 std::vector<uint8> pubkey_copy; | 462 std::vector<uint8> pubkey_copy; |
| 466 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); | 463 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); |
| 467 ASSERT_TRUE(key_copy->ExportPublicKey(&pubkey_copy)); | 464 ASSERT_TRUE(key_copy->ExportPublicKey(&pubkey_copy)); |
| 468 | 465 |
| 469 ASSERT_EQ(privkey, privkey_copy); | 466 ASSERT_EQ(privkey, privkey_copy); |
| 470 ASSERT_EQ(pubkey, pubkey_copy); | 467 ASSERT_EQ(pubkey, pubkey_copy); |
| 471 } | 468 } |
| 472 #endif | |
| 473 | 469 |
| OLD | NEW |