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" |
11 #include "crypto/ec_private_key.h" | 11 #include "crypto/ec_private_key.h" |
12 #include "crypto/signature_verifier.h" | 12 #include "crypto/signature_verifier.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 #if defined(USE_OPENSSL) | 15 // TODO(rch): Add some exported keys from each to |
16 // Once ECSignatureCreator is implemented for OpenSSL, remove this #if block. | |
17 // TODO(rch): When that happens, also add some exported keys from each to | |
18 // test interop between NSS and OpenSSL. | 16 // test interop between NSS and OpenSSL. |
19 TEST(ECSignatureCreatorTest, OpenSSLStub) { | 17 |
20 scoped_ptr<crypto::ECSignatureCreator> signer( | |
21 crypto::ECSignatureCreator::Create(NULL)); | |
22 ASSERT_TRUE(signer.get()); | |
23 EXPECT_FALSE(signer->Sign(NULL, 0, NULL)); | |
24 } | |
25 #else | |
26 TEST(ECSignatureCreatorTest, BasicTest) { | 18 TEST(ECSignatureCreatorTest, BasicTest) { |
27 // Do a verify round trip. | 19 // Do a verify round trip. |
28 scoped_ptr<crypto::ECPrivateKey> key_original( | 20 scoped_ptr<crypto::ECPrivateKey> key_original( |
29 crypto::ECPrivateKey::Create()); | 21 crypto::ECPrivateKey::Create()); |
30 ASSERT_TRUE(key_original.get()); | 22 ASSERT_TRUE(key_original.get()); |
31 | 23 |
32 std::vector<uint8> key_info; | 24 std::vector<uint8> key_info; |
33 ASSERT_TRUE( | 25 ASSERT_TRUE( |
34 key_original->ExportEncryptedPrivateKey(std::string(), 1000, &key_info)); | 26 key_original->ExportEncryptedPrivateKey(std::string(), 1000, &key_info)); |
35 std::vector<uint8> pubkey_info; | 27 std::vector<uint8> pubkey_info; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 crypto::SignatureVerifier verifier; | 66 crypto::SignatureVerifier verifier; |
75 ASSERT_TRUE(verifier.VerifyInit( | 67 ASSERT_TRUE(verifier.VerifyInit( |
76 kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), | 68 kECDSAWithSHA256AlgorithmID, sizeof(kECDSAWithSHA256AlgorithmID), |
77 &signature[0], signature.size(), | 69 &signature[0], signature.size(), |
78 &public_key_info.front(), public_key_info.size())); | 70 &public_key_info.front(), public_key_info.size())); |
79 | 71 |
80 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), | 72 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), |
81 data.size()); | 73 data.size()); |
82 ASSERT_TRUE(verifier.VerifyFinal()); | 74 ASSERT_TRUE(verifier.VerifyFinal()); |
83 } | 75 } |
84 #endif // !defined(USE_OPENSSL) | |
OLD | NEW |