| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/crypto/signature_creator.h" | 7 #include "base/crypto/signature_creator.h" |
| 8 #include "base/crypto/signature_verifier.h" | 8 #include "base/crypto/signature_verifier.h" |
| 9 #include "base/leak_annotations.h" | |
| 10 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 11 |
| 13 TEST(SignatureCreatorTest, BasicTest) { | 12 TEST(SignatureCreatorTest, BasicTest) { |
| 14 // Do a verify round trip. | 13 // Do a verify round trip. |
| 15 scoped_ptr<base::RSAPrivateKey> key_original( | 14 scoped_ptr<base::RSAPrivateKey> key_original( |
| 16 base::RSAPrivateKey::Create(1024)); | 15 base::RSAPrivateKey::Create(1024)); |
| 17 ASSERT_TRUE(key_original.get()); | 16 ASSERT_TRUE(key_original.get()); |
| 18 | 17 |
| 19 std::vector<uint8> key_info; | 18 std::vector<uint8> key_info; |
| 20 key_original->ExportPrivateKey(&key_info); | 19 key_original->ExportPrivateKey(&key_info); |
| 21 // This test currently leaks some memory, | |
| 22 // see http://crbug.com/34742 | |
| 23 ANNOTATE_SCOPED_MEMORY_LEAK; | |
| 24 scoped_ptr<base::RSAPrivateKey> key( | 20 scoped_ptr<base::RSAPrivateKey> key( |
| 25 base::RSAPrivateKey::CreateFromPrivateKeyInfo(key_info)); | 21 base::RSAPrivateKey::CreateFromPrivateKeyInfo(key_info)); |
| 26 ASSERT_TRUE(key.get()); | 22 ASSERT_TRUE(key.get()); |
| 27 | 23 |
| 28 scoped_ptr<base::SignatureCreator> signer( | 24 scoped_ptr<base::SignatureCreator> signer( |
| 29 base::SignatureCreator::Create(key.get())); | 25 base::SignatureCreator::Create(key.get())); |
| 30 ASSERT_TRUE(signer.get()); | 26 ASSERT_TRUE(signer.get()); |
| 31 | 27 |
| 32 std::string data("Hello, World!"); | 28 std::string data("Hello, World!"); |
| 33 ASSERT_TRUE(signer->Update(reinterpret_cast<const uint8*>(data.c_str()), | 29 ASSERT_TRUE(signer->Update(reinterpret_cast<const uint8*>(data.c_str()), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 48 base::SignatureVerifier verifier; | 44 base::SignatureVerifier verifier; |
| 49 ASSERT_TRUE(verifier.VerifyInit( | 45 ASSERT_TRUE(verifier.VerifyInit( |
| 50 kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID), | 46 kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID), |
| 51 &signature.front(), signature.size(), | 47 &signature.front(), signature.size(), |
| 52 &public_key_info.front(), public_key_info.size())); | 48 &public_key_info.front(), public_key_info.size())); |
| 53 | 49 |
| 54 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), | 50 verifier.VerifyUpdate(reinterpret_cast<const uint8*>(data.c_str()), |
| 55 data.size()); | 51 data.size()); |
| 56 ASSERT_TRUE(verifier.VerifyFinal()); | 52 ASSERT_TRUE(verifier.VerifyFinal()); |
| 57 } | 53 } |
| OLD | NEW |