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

Side by Side Diff: base/crypto/signature_creator_nss.cc

Issue 208032: Linux (nss) implementations of RSAPrivateKey and SignatureCreator (Closed)
Patch Set: last cr changes. Created 11 years, 3 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.h ('k') | base/crypto/signature_creator_win.cc » ('j') | 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 <cryptohi.h>
8 #include <keyhi.h>
9 #include <stdlib.h>
10
11 #include "base/logging.h"
12 #include "base/nss_init.h"
13 #include "base/scoped_ptr.h"
14
15 namespace base {
16
17 // static
18 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) {
19 scoped_ptr<SignatureCreator> result(new SignatureCreator);
20 result->key_ = key;
21
22 result->sign_context_ = SGN_NewContext(SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION,
23 key->key());
24 if (!result->sign_context_) {
25 NOTREACHED();
26 return NULL;
27 }
28
29 SECStatus rv = SGN_Begin(result->sign_context_);
30 if (rv != SECSuccess) {
31 NOTREACHED();
32 return NULL;
33 }
34
35 return result.release();
36 }
37
38 SignatureCreator::SignatureCreator() : sign_context_(NULL) {
39 EnsureNSSInit();
40 }
41
42 SignatureCreator::~SignatureCreator() {
43 if (sign_context_) {
44 SGN_DestroyContext(sign_context_, PR_TRUE);
45 sign_context_ = NULL;
46 }
47 }
48
49 bool SignatureCreator::Update(const uint8* data_part, int data_part_len) {
50 SECStatus rv = SGN_Update(sign_context_,
51 const_cast<unsigned char*>(data_part),
52 data_part_len);
53 if (rv != SECSuccess) {
54 NOTREACHED();
55 return false;
56 }
57
58 return true;
59 }
60
61 bool SignatureCreator::Final(std::vector<uint8>* signature) {
62 SECItem signature_item;
63 SECStatus rv = SGN_End(sign_context_, &signature_item);
64 if (rv != SECSuccess) {
65 NOTREACHED();
66 return false;
67 }
68 signature->assign(signature_item.data,
69 signature_item.data + signature_item.len);
70
71 return true;
72 }
73
74 } // namespace base
OLDNEW
« 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