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

Unified Diff: base/crypto/signature_creator_win.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_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/crypto/signature_creator_win.cc
diff --git a/base/crypto/signature_creator_win.cc b/base/crypto/signature_creator_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..651ed7ac16df37d13191700a604f8fe8fba319a0
--- /dev/null
+++ b/base/crypto/signature_creator_win.cc
@@ -0,0 +1,62 @@
+// 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 "base/crypto/signature_creator.h"
+
+#include "base/logging.h"
+#include "base/scoped_ptr.h"
+
+namespace base {
+
+// static
+SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) {
+ scoped_ptr<SignatureCreator> result(new SignatureCreator);
+ result->key_ = key;
+
+ if (!CryptCreateHash(key->provider(), CALG_SHA1, 0, 0,
+ &result->hash_object_)) {
+ NOTREACHED();
+ return NULL;
+ }
+
+ return result.release();
+}
+
+SignatureCreator::~SignatureCreator() {
+ if (hash_object_) {
+ if (!CryptDestroyHash(hash_object_))
+ NOTREACHED();
+
+ hash_object_ = 0;
+ }
+}
+
+bool SignatureCreator::Update(const uint8* data_part, int data_part_len) {
+ if (!CryptHashData(hash_object_, data_part, data_part_len, 0)) {
+ NOTREACHED();
+ return false;
+ }
+
+ return true;
+}
+
+bool SignatureCreator::Final(std::vector<uint8>* signature) {
+ DWORD signature_length = 0;
+ if (!CryptSignHash(hash_object_, AT_SIGNATURE, NULL, 0, NULL,
+ &signature_length)) {
+ return false;
+ }
+
+ signature->resize(signature_length);
+ if (!CryptSignHash(hash_object_, AT_SIGNATURE, NULL, 0, &signature->front(),
+ &signature_length)) {
+ return false;
+ }
+
+ signature->resize(signature_length);
+ hash_object_ = 0;
+ return true;
+}
+
+} // namespace base
« no previous file with comments | « base/crypto/signature_creator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698