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 #if defined(USE_OPENSSL) |
16 // Once ECSignatureCreator is implemented for OpenSSL, remove this #if block. | 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 | 17 // TODO(rch): When that happens, also add some exported keys from each to |
18 // test interop between NSS and OpenSSL. | 18 // test interop between NSS and OpenSSL. |
19 TEST(ECSignatureCreatorTest, OpenSSLStub) { | 19 TEST(ECSignatureCreatorTest, OpenSSLStub) { |
20 scoped_ptr<crypto::ECSignatureCreator> signer( | 20 scoped_ptr<crypto::ECSignatureCreator> signer( |
21 crypto::ECSignatureCreator::Create(NULL)); | 21 crypto::ECSignatureCreator::Create(NULL)); |
22 ASSERT_FALSE(signer.get()); | 22 ASSERT_TRUE(signer.get()); |
| 23 EXPECT_FALSE(signer->Sign(NULL, 0, NULL)); |
23 } | 24 } |
24 #else | 25 #else |
25 TEST(ECSignatureCreatorTest, BasicTest) { | 26 TEST(ECSignatureCreatorTest, BasicTest) { |
26 // Do a verify round trip. | 27 // Do a verify round trip. |
27 scoped_ptr<crypto::ECPrivateKey> key_original( | 28 scoped_ptr<crypto::ECPrivateKey> key_original( |
28 crypto::ECPrivateKey::Create()); | 29 crypto::ECPrivateKey::Create()); |
29 ASSERT_TRUE(key_original.get()); | 30 ASSERT_TRUE(key_original.get()); |
30 | 31 |
31 std::vector<uint8> key_info; | 32 std::vector<uint8> key_info; |
32 ASSERT_TRUE(key_original->ExportEncryptedPrivateKey("", 1000, &key_info)); | 33 ASSERT_TRUE(key_original->ExportEncryptedPrivateKey("", 1000, &key_info)); |
(...skipping 30 matching lines...) Expand all Loading... |
63 ASSERT_TRUE(verifier.VerifyInit( | 64 ASSERT_TRUE(verifier.VerifyInit( |
64 kECDSAWithSHA1AlgorithmID, sizeof(kECDSAWithSHA1AlgorithmID), | 65 kECDSAWithSHA1AlgorithmID, sizeof(kECDSAWithSHA1AlgorithmID), |
65 &signature.front(), signature.size(), | 66 &signature.front(), signature.size(), |
66 &public_key_info.front(), public_key_info.size())); | 67 &public_key_info.front(), public_key_info.size())); |
67 | 68 |
68 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), | 69 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), |
69 data.size()); | 70 data.size()); |
70 ASSERT_TRUE(verifier.VerifyFinal()); | 71 ASSERT_TRUE(verifier.VerifyFinal()); |
71 } | 72 } |
72 #endif // !defined(USE_OPENSSL) | 73 #endif // !defined(USE_OPENSSL) |
OLD | NEW |