| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); | 143 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); |
| 144 | 144 |
| 145 scoped_ptr<crypto::RSAPrivateKey> key_copy(key->Copy()); | 145 scoped_ptr<crypto::RSAPrivateKey> key_copy(key->Copy()); |
| 146 ASSERT_TRUE(key_copy.get()); | 146 ASSERT_TRUE(key_copy.get()); |
| 147 | 147 |
| 148 std::vector<uint8> privkey_copy; | 148 std::vector<uint8> privkey_copy; |
| 149 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); | 149 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); |
| 150 ASSERT_EQ(input, privkey_copy); | 150 ASSERT_EQ(input, privkey_copy); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Test that CreateFromPrivateKeyInfo fails if there is extra data after the RSA |
| 154 // key. |
| 155 TEST(RSAPrivateKeyUnitTest, ExtraData) { |
| 156 std::vector<uint8> input( |
| 157 kTestPrivateKeyInfo, kTestPrivateKeyInfo + sizeof(kTestPrivateKeyInfo)); |
| 158 input.push_back(0); |
| 159 |
| 160 scoped_ptr<crypto::RSAPrivateKey> key( |
| 161 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); |
| 162 |
| 163 // Import should fail. |
| 164 EXPECT_FALSE(key); |
| 165 } |
| 166 |
| 153 | 167 |
| 154 // Verify that generated public keys look good. This test data was generated | 168 // Verify that generated public keys look good. This test data was generated |
| 155 // with the openssl command line tool. | 169 // with the openssl command line tool. |
| 156 TEST(RSAPrivateKeyUnitTest, PublicKeyTest) { | 170 TEST(RSAPrivateKeyUnitTest, PublicKeyTest) { |
| 157 const uint8 expected_public_key_info[] = { | 171 const uint8 expected_public_key_info[] = { |
| 158 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, | 172 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
| 159 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, | 173 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, |
| 160 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, | 174 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81, |
| 161 0x89, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b, | 175 0x89, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b, |
| 162 0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61, | 176 0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61, |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 std::vector<uint8> privkey_copy; | 437 std::vector<uint8> privkey_copy; |
| 424 std::vector<uint8> pubkey_copy; | 438 std::vector<uint8> pubkey_copy; |
| 425 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); | 439 ASSERT_TRUE(key_copy->ExportPrivateKey(&privkey_copy)); |
| 426 ASSERT_TRUE(key_copy->ExportPublicKey(&pubkey_copy)); | 440 ASSERT_TRUE(key_copy->ExportPublicKey(&pubkey_copy)); |
| 427 | 441 |
| 428 ASSERT_EQ(privkey, privkey_copy); | 442 ASSERT_EQ(privkey, privkey_copy); |
| 429 ASSERT_EQ(pubkey, pubkey_copy); | 443 ASSERT_EQ(pubkey, pubkey_copy); |
| 430 } | 444 } |
| 431 #endif | 445 #endif |
| 432 | 446 |
| OLD | NEW |