Disable crashing tests, my previous checkin to mark them flaky did not help.
[chromium-blink-merge.git] / base / crypto / signature_creator_nss.cc
blob92bf4d73ad3402c7b3772a3925f33d921465a115
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.
5 #include "base/crypto/signature_creator.h"
7 #include <cryptohi.h>
8 #include <keyhi.h>
9 #include <stdlib.h>
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/nss_util.h"
15 namespace base {
17 SignatureCreator::~SignatureCreator() {
18 if (sign_context_) {
19 SGN_DestroyContext(sign_context_, PR_TRUE);
20 sign_context_ = NULL;
24 // static
25 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) {
26 scoped_ptr<SignatureCreator> result(new SignatureCreator);
27 result->key_ = key;
29 result->sign_context_ = SGN_NewContext(SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION,
30 key->key());
31 if (!result->sign_context_) {
32 NOTREACHED();
33 return NULL;
36 SECStatus rv = SGN_Begin(result->sign_context_);
37 if (rv != SECSuccess) {
38 NOTREACHED();
39 return NULL;
42 return result.release();
45 bool SignatureCreator::Update(const uint8* data_part, int data_part_len) {
46 // TODO(wtc): Remove this const_cast when we require NSS 3.12.5.
47 // See NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=518255
48 SECStatus rv = SGN_Update(sign_context_,
49 const_cast<unsigned char*>(data_part),
50 data_part_len);
51 if (rv != SECSuccess) {
52 NOTREACHED();
53 return false;
56 return true;
59 bool SignatureCreator::Final(std::vector<uint8>* signature) {
60 SECItem signature_item;
61 SECStatus rv = SGN_End(sign_context_, &signature_item);
62 if (rv != SECSuccess) {
63 NOTREACHED();
64 return false;
66 signature->assign(signature_item.data,
67 signature_item.data + signature_item.len);
68 SECITEM_FreeItem(&signature_item, PR_FALSE);
69 return true;
72 SignatureCreator::SignatureCreator() : sign_context_(NULL) {
73 EnsureNSSInit();
76 } // namespace base