Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2508)

Unified Diff: base/crypto/signature_creator_unittest.cc

Issue 118277: Introduce SignatureCreator. (Closed)
Patch Set: Responses to feedback Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/crypto/signature_creator.h ('k') | base/crypto/signature_creator_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/crypto/signature_creator_unittest.cc
diff --git a/base/crypto/signature_creator_unittest.cc b/base/crypto/signature_creator_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a65ad2201a1f9e46256bfdf20ac18ed06a31e776
--- /dev/null
+++ b/base/crypto/signature_creator_unittest.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <vector>
+
+#include "base/crypto/signature_creator.h"
+#include "base/crypto/signature_verifier.h"
+#include "base/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(SignatureCreatorTest, BasicTest) {
+ // Do a verify round trip.
+ scoped_ptr<base::RSAPrivateKey> key(base::RSAPrivateKey::Create(1024));
+ ASSERT_TRUE(key.get());
+
+ scoped_ptr<base::SignatureCreator> signer(
+ base::SignatureCreator::Create(key.get()));
+ ASSERT_TRUE(signer.get());
+
+ std::string data("Hello, world!");
+ ASSERT_TRUE(signer->Update(reinterpret_cast<const uint8*>(data.c_str()),
+ data.size()));
+
+ std::vector<uint8> signature;
+ ASSERT_TRUE(signer->Final(&signature));
+
+ std::vector<uint8> public_key_info;
+ ASSERT_TRUE(key->ExportPublicKey(&public_key_info));
+
+ // This is the algorithm ID for SHA-1 with RSA encryption.
+ // TODO(aa): Factor this out into some shared location.
+ const uint8 kSHA1WithRSAAlgorithmID[] = {
+ 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
+ 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00
+ };
+ base::SignatureVerifier verifier;
+ ASSERT_TRUE(verifier.VerifyInit(
+ kSHA1WithRSAAlgorithmID, sizeof(kSHA1WithRSAAlgorithmID),
+ &signature.front(), signature.size(),
+ &public_key_info.front(), public_key_info.size()));
+}
+
+// TODO(aa): Would be nice to test some well-known signatures.
« no previous file with comments | « base/crypto/signature_creator.h ('k') | base/crypto/signature_creator_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698