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 TEST(RSAPrivateKeyUnitTest, CreateFromKeyTest) { |
| 408 scoped_ptr<crypto::RSAPrivateKey> key_pair( |
| 409 crypto::RSAPrivateKey::Create(256)); |
| 410 |
| 411 scoped_ptr<crypto::RSAPrivateKey> key_copy( |
| 412 crypto::RSAPrivateKey::CreateFromKey(key_pair->key())); |
| 413 ASSERT_TRUE(key_copy.get()); |
| 414 |
| 415 std::vector<uint8> privkey; |
| 416 std::vector<uint8> pubkey; |
| 417 ASSERT_TRUE(key_pair->ExportPrivateKey(&privkey)); |
| 418 ASSERT_TRUE(key_pair->ExportPublicKey(&pubkey)); |
| 419 |
| 420 std::vector<uint8> privkey_copy; |
| 421 std::vector<uint8> pubkey_copy; |
| 422 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); |
| 423 ASSERT_TRUE(key_copy->ExportPublicKey(&pubkey_copy)); |
| 424 |
| 425 ASSERT_EQ(privkey, privkey_copy); |
| 426 ASSERT_EQ(pubkey, pubkey_copy); |
| 427 } |
| 428 |
| 429 |
OLD | NEW |