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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/crypto/signature_creator_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/crypto/signature_creator.h"
6
7 #include "base/logging.h"
8 #include "base/scoped_ptr.h"
9
10 namespace base {
11
12 // static
13 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) {
14 scoped_ptr<SignatureCreator> result(new SignatureCreator);
15 result->key_ = key;
16
17 if (!CryptCreateHash(key->provider(), CALG_SHA1, 0, 0,
18 &result->hash_object_)) {
19 NOTREACHED();
20 return NULL;
21 }
22
23 return result.release();
24 }
25
26 SignatureCreator::~SignatureCreator() {
27 if (hash_object_) {
28 if (!CryptDestroyHash(hash_object_))
29 NOTREACHED();
30
31 hash_object_ = 0;
32 }
33 }
34
35 bool SignatureCreator::Update(const uint8* data_part, int data_part_len) {
36 if (!CryptHashData(hash_object_, data_part, data_part_len, 0)) {
37 NOTREACHED();
38 return false;
39 }
40
41 return true;
42 }
43
44 bool SignatureCreator::Final(std::vector<uint8>* signature) {
45 DWORD signature_length = 0;
46 if (!CryptSignHash(hash_object_, AT_SIGNATURE, NULL, 0, NULL,
47 &signature_length)) {
48 return false;
49 }
50
51 signature->resize(signature_length);
52 if (!CryptSignHash(hash_object_, AT_SIGNATURE, NULL, 0, &signature->front(),
53 &signature_length)) {
54 return false;
55 }
56
57 signature->resize(signature_length);
58 hash_object_ = 0;
59 return true;
60 }
61
62 } // namespace base
OLDNEW
« 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