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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 ASSERT_TRUE(keypair1->ExportPrivateKey(&output1)); | 396 ASSERT_TRUE(keypair1->ExportPrivateKey(&output1)); |
397 ASSERT_TRUE(keypair2->ExportPrivateKey(&output2)); | 397 ASSERT_TRUE(keypair2->ExportPrivateKey(&output2)); |
398 | 398 |
399 ASSERT_EQ(input1.size(), output1.size()); | 399 ASSERT_EQ(input1.size(), output1.size()); |
400 ASSERT_EQ(input2.size(), output2.size()); | 400 ASSERT_EQ(input2.size(), output2.size()); |
401 ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(), | 401 ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(), |
402 input1.size())); | 402 input1.size())); |
403 ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(), | 403 ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(), |
404 input2.size())); | 404 input2.size())); |
405 } | 405 } |
| 406 |
| 407 // The following test can run if either USE_NSS or USE_OPENSSL is defined, but |
| 408 // not otherwise (since it uses crypto::RSAPrivateKey::CreateFromKey). |
| 409 #if defined(USE_NSS) || defined(USE_OPENSSL) |
| 410 TEST(RSAPrivateKeyUnitTest, CreateFromKeyTest) { |
| 411 scoped_ptr<crypto::RSAPrivateKey> key_pair( |
| 412 crypto::RSAPrivateKey::Create(256)); |
| 413 |
| 414 scoped_ptr<crypto::RSAPrivateKey> key_copy( |
| 415 crypto::RSAPrivateKey::CreateFromKey(key_pair->key())); |
| 416 ASSERT_TRUE(key_copy.get()); |
| 417 |
| 418 std::vector<uint8> privkey; |
| 419 std::vector<uint8> pubkey; |
| 420 ASSERT_TRUE(key_pair->ExportPrivateKey(&privkey)); |
| 421 ASSERT_TRUE(key_pair->ExportPublicKey(&pubkey)); |
| 422 |
| 423 std::vector<uint8> privkey_copy; |
| 424 std::vector<uint8> pubkey_copy; |
| 425 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); |
| 426 ASSERT_TRUE(key_copy->ExportPublicKey(&pubkey_copy)); |
| 427 |
| 428 ASSERT_EQ(privkey, privkey_copy); |
| 429 ASSERT_EQ(pubkey, pubkey_copy); |
| 430 } |
| 431 #endif |
| 432 |
OLD | NEW |