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

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

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « base/crypto/signature_creator_nss.cc ('k') | base/crypto/signature_creator_unittest.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) 2011 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 <openssl/evp.h>
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/openssl_util.h"
12 #include "base/stl_util-inl.h"
13
14 namespace base {
15
16 // static
17 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) {
18 OpenSSLErrStackTracer err_tracer(FROM_HERE);
19 scoped_ptr<SignatureCreator> result(new SignatureCreator);
20 result->key_ = key;
21 if (!EVP_SignInit_ex(result->sign_context_, EVP_sha1(), NULL))
22 return NULL;
23 return result.release();
24 }
25
26 SignatureCreator::SignatureCreator()
27 : sign_context_(EVP_MD_CTX_create()) {
28 }
29
30 SignatureCreator::~SignatureCreator() {
31 EVP_MD_CTX_destroy(sign_context_);
32 }
33
34 bool SignatureCreator::Update(const uint8* data_part, int data_part_len) {
35 OpenSSLErrStackTracer err_tracer(FROM_HERE);
36 return EVP_SignUpdate(sign_context_, data_part, data_part_len) == 1;
37 }
38
39 bool SignatureCreator::Final(std::vector<uint8>* signature) {
40 OpenSSLErrStackTracer err_tracer(FROM_HERE);
41 EVP_PKEY* key = key_->key();
42 signature->resize(EVP_PKEY_size(key));
43
44 unsigned int len = 0;
45 int rv = EVP_SignFinal(sign_context_, vector_as_array(signature), &len, key);
46 if (!rv) {
47 signature->clear();
48 return false;
49 }
50 signature->resize(len);
51 return true;
52 }
53
54 } // namespace base
OLDNEW
« no previous file with comments | « base/crypto/signature_creator_nss.cc ('k') | base/crypto/signature_creator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698