| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "crypto/signature_creator.h" | 5 #include "crypto/signature_creator.h" |
| 6 | 6 |
| 7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
| 8 #include <keyhi.h> | 8 #include <keyhi.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| 11 | 11 |
| 12 #include <memory> |
| 13 |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "crypto/nss_util.h" | 15 #include "crypto/nss_util.h" |
| 15 #include "crypto/rsa_private_key.h" | 16 #include "crypto/rsa_private_key.h" |
| 16 | 17 |
| 17 namespace crypto { | 18 namespace crypto { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 SECOidTag ToNSSSigOid(SignatureCreator::HashAlgorithm hash_alg) { | 22 SECOidTag ToNSSSigOid(SignatureCreator::HashAlgorithm hash_alg) { |
| 22 switch (hash_alg) { | 23 switch (hash_alg) { |
| 23 case SignatureCreator::SHA1: | 24 case SignatureCreator::SHA1: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 SignatureCreator::~SignatureCreator() { | 44 SignatureCreator::~SignatureCreator() { |
| 44 if (sign_context_) { | 45 if (sign_context_) { |
| 45 SGN_DestroyContext(sign_context_, PR_TRUE); | 46 SGN_DestroyContext(sign_context_, PR_TRUE); |
| 46 sign_context_ = NULL; | 47 sign_context_ = NULL; |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 | 50 |
| 50 // static | 51 // static |
| 51 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key, | 52 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key, |
| 52 HashAlgorithm hash_alg) { | 53 HashAlgorithm hash_alg) { |
| 53 scoped_ptr<SignatureCreator> result(new SignatureCreator); | 54 std::unique_ptr<SignatureCreator> result(new SignatureCreator); |
| 54 result->sign_context_ = SGN_NewContext(ToNSSSigOid(hash_alg), key->key()); | 55 result->sign_context_ = SGN_NewContext(ToNSSSigOid(hash_alg), key->key()); |
| 55 if (!result->sign_context_) { | 56 if (!result->sign_context_) { |
| 56 NOTREACHED(); | 57 NOTREACHED(); |
| 57 return NULL; | 58 return NULL; |
| 58 } | 59 } |
| 59 | 60 |
| 60 SECStatus rv = SGN_Begin(result->sign_context_); | 61 SECStatus rv = SGN_Begin(result->sign_context_); |
| 61 if (rv != SECSuccess) { | 62 if (rv != SECSuccess) { |
| 62 NOTREACHED(); | 63 NOTREACHED(); |
| 63 return NULL; | 64 return NULL; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 signature_item.data + signature_item.len); | 111 signature_item.data + signature_item.len); |
| 111 SECITEM_FreeItem(&signature_item, PR_FALSE); | 112 SECITEM_FreeItem(&signature_item, PR_FALSE); |
| 112 return true; | 113 return true; |
| 113 } | 114 } |
| 114 | 115 |
| 115 SignatureCreator::SignatureCreator() : sign_context_(NULL) { | 116 SignatureCreator::SignatureCreator() : sign_context_(NULL) { |
| 116 EnsureNSSInit(); | 117 EnsureNSSInit(); |
| 117 } | 118 } |
| 118 | 119 |
| 119 } // namespace crypto | 120 } // namespace crypto |
| OLD | NEW |