Chromium Code Reviews| 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 // Generate random private keys with two different sizes. Reimport, then | 10 // Generate random private keys with two different sizes. Reimport, then |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 std::vector<uint8> privkey4; | 38 std::vector<uint8> privkey4; |
| 39 ASSERT_TRUE(keypair3->ExportPrivateKey(&privkey3)); | 39 ASSERT_TRUE(keypair3->ExportPrivateKey(&privkey3)); |
| 40 ASSERT_TRUE(keypair4->ExportPrivateKey(&privkey4)); | 40 ASSERT_TRUE(keypair4->ExportPrivateKey(&privkey4)); |
| 41 | 41 |
| 42 ASSERT_EQ(privkey1.size(), privkey3.size()); | 42 ASSERT_EQ(privkey1.size(), privkey3.size()); |
| 43 ASSERT_EQ(privkey2.size(), privkey4.size()); | 43 ASSERT_EQ(privkey2.size(), privkey4.size()); |
| 44 ASSERT_TRUE(0 == memcmp(&privkey1.front(), &privkey3.front(), | 44 ASSERT_TRUE(0 == memcmp(&privkey1.front(), &privkey3.front(), |
| 45 privkey1.size())); | 45 privkey1.size())); |
| 46 ASSERT_TRUE(0 == memcmp(&privkey2.front(), &privkey4.front(), | 46 ASSERT_TRUE(0 == memcmp(&privkey2.front(), &privkey4.front(), |
| 47 privkey2.size())); | 47 privkey2.size())); |
| 48 | |
| 49 scoped_ptr<crypto::RSAPrivateKey> keypair_copy(keypair1->Copy()); | |
| 50 ASSERT_TRUE(keypair_copy.get()); | |
| 51 | |
| 52 std::vector<uint8> privkey_copy; | |
| 53 ASSERT_TRUE(keypair_copy->ExportPrivateKey(&privkey_copy)); | |
| 54 ASSERT_EQ(privkey1, privkey_copy); | |
|
wtc
2011/11/30 00:58:10
It would be nice to create a separate test for the
Sergey Ulanov
2011/11/30 22:30:03
Done.
wtc
2011/11/30 23:44:37
You didn't upload a new patch set. Not sure if yo
| |
| 48 } | 55 } |
| 49 | 56 |
| 50 | 57 |
| 51 // Verify that generated public keys look good. This test data was generated | 58 // Verify that generated public keys look good. This test data was generated |
| 52 // with the openssl command line tool. | 59 // with the openssl command line tool. |
| 53 TEST(RSAPrivateKeyUnitTest, PublicKeyTest) { | 60 TEST(RSAPrivateKeyUnitTest, PublicKeyTest) { |
| 54 const uint8 private_key_info[] = { | 61 const uint8 private_key_info[] = { |
| 55 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30, | 62 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30, |
| 56 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, | 63 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, |
| 57 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, | 64 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 ASSERT_TRUE(keypair1->ExportPrivateKey(&output1)); | 384 ASSERT_TRUE(keypair1->ExportPrivateKey(&output1)); |
| 378 ASSERT_TRUE(keypair2->ExportPrivateKey(&output2)); | 385 ASSERT_TRUE(keypair2->ExportPrivateKey(&output2)); |
| 379 | 386 |
| 380 ASSERT_EQ(input1.size(), output1.size()); | 387 ASSERT_EQ(input1.size(), output1.size()); |
| 381 ASSERT_EQ(input2.size(), output2.size()); | 388 ASSERT_EQ(input2.size(), output2.size()); |
| 382 ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(), | 389 ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(), |
| 383 input1.size())); | 390 input1.size())); |
| 384 ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(), | 391 ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(), |
| 385 input2.size())); | 392 input2.size())); |
| 386 } | 393 } |
| OLD | NEW |