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"
11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/nss_util.h"
17 SignatureCreator::~SignatureCreator() {
19 SGN_DestroyContext(sign_context_
, PR_TRUE
);
25 SignatureCreator
* SignatureCreator::Create(RSAPrivateKey
* key
) {
26 scoped_ptr
<SignatureCreator
> result(new SignatureCreator
);
29 result
->sign_context_
= SGN_NewContext(SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION
,
31 if (!result
->sign_context_
) {
36 SECStatus rv
= SGN_Begin(result
->sign_context_
);
37 if (rv
!= SECSuccess
) {
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
),
51 if (rv
!= SECSuccess
) {
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
) {
66 signature
->assign(signature_item
.data
,
67 signature_item
.data
+ signature_item
.len
);
68 SECITEM_FreeItem(&signature_item
, PR_FALSE
);
72 SignatureCreator::SignatureCreator() : sign_context_(NULL
) {