| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ec_signature_creator.h" | 5 #include "crypto/ec_signature_creator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 EXPECT_FALSE(signer->Sign(NULL, 0, NULL)); | 23 EXPECT_FALSE(signer->Sign(NULL, 0, NULL)); |
| 24 } | 24 } |
| 25 #else | 25 #else |
| 26 TEST(ECSignatureCreatorTest, BasicTest) { | 26 TEST(ECSignatureCreatorTest, BasicTest) { |
| 27 // Do a verify round trip. | 27 // Do a verify round trip. |
| 28 scoped_ptr<crypto::ECPrivateKey> key_original( | 28 scoped_ptr<crypto::ECPrivateKey> key_original( |
| 29 crypto::ECPrivateKey::Create()); | 29 crypto::ECPrivateKey::Create()); |
| 30 ASSERT_TRUE(key_original.get()); | 30 ASSERT_TRUE(key_original.get()); |
| 31 | 31 |
| 32 std::vector<uint8> key_info; | 32 std::vector<uint8> key_info; |
| 33 ASSERT_TRUE(key_original->ExportEncryptedPrivateKey("", 1000, &key_info)); | 33 ASSERT_TRUE( |
| 34 key_original->ExportEncryptedPrivateKey(std::string(), 1000, &key_info)); |
| 34 std::vector<uint8> pubkey_info; | 35 std::vector<uint8> pubkey_info; |
| 35 ASSERT_TRUE(key_original->ExportPublicKey(&pubkey_info)); | 36 ASSERT_TRUE(key_original->ExportPublicKey(&pubkey_info)); |
| 36 | 37 |
| 37 scoped_ptr<crypto::ECPrivateKey> key( | 38 scoped_ptr<crypto::ECPrivateKey> key( |
| 38 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo("", key_info, | 39 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo( |
| 39 pubkey_info)); | 40 std::string(), key_info, pubkey_info)); |
| 40 ASSERT_TRUE(key.get()); | 41 ASSERT_TRUE(key.get()); |
| 41 ASSERT_TRUE(key->key() != NULL); | 42 ASSERT_TRUE(key->key() != NULL); |
| 42 | 43 |
| 43 scoped_ptr<crypto::ECSignatureCreator> signer( | 44 scoped_ptr<crypto::ECSignatureCreator> signer( |
| 44 crypto::ECSignatureCreator::Create(key.get())); | 45 crypto::ECSignatureCreator::Create(key.get())); |
| 45 ASSERT_TRUE(signer.get()); | 46 ASSERT_TRUE(signer.get()); |
| 46 | 47 |
| 47 std::string data("Hello, World!"); | 48 std::string data("Hello, World!"); |
| 48 std::vector<uint8> signature; | 49 std::vector<uint8> signature; |
| 49 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8*>(data.c_str()), | 50 ASSERT_TRUE(signer->Sign(reinterpret_cast<const uint8*>(data.c_str()), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 64 ASSERT_TRUE(verifier.VerifyInit( | 65 ASSERT_TRUE(verifier.VerifyInit( |
| 65 kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), | 66 kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), |
| 66 &signature[0], signature.size(), | 67 &signature[0], signature.size(), |
| 67 &public_key_info.front(), public_key_info.size())); | 68 &public_key_info.front(), public_key_info.size())); |
| 68 | 69 |
| 69 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), | 70 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), |
| 70 data.size()); | 71 data.size()); |
| 71 ASSERT_TRUE(verifier.VerifyFinal()); | 72 ASSERT_TRUE(verifier.VerifyFinal()); |
| 72 } | 73 } |
| 73 #endif // !defined(USE_OPENSSL) | 74 #endif // !defined(USE_OPENSSL) |
| OLD | NEW |