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 <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 if (sign_context_) { | 43 if (sign_context_) { |
44 SGN_DestroyContext(sign_context_, PR_TRUE); | 44 SGN_DestroyContext(sign_context_, PR_TRUE); |
45 sign_context_ = NULL; | 45 sign_context_ = NULL; |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 // static | 49 // static |
50 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key, | 50 SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key, |
51 HashAlgorithm hash_alg) { | 51 HashAlgorithm hash_alg) { |
52 scoped_ptr<SignatureCreator> result(new SignatureCreator); | 52 scoped_ptr<SignatureCreator> result(new SignatureCreator); |
53 result->key_ = key; | |
54 | |
55 result->sign_context_ = SGN_NewContext(ToNSSSigOid(hash_alg), key->key()); | 53 result->sign_context_ = SGN_NewContext(ToNSSSigOid(hash_alg), key->key()); |
56 if (!result->sign_context_) { | 54 if (!result->sign_context_) { |
57 NOTREACHED(); | 55 NOTREACHED(); |
58 return NULL; | 56 return NULL; |
59 } | 57 } |
60 | 58 |
61 SECStatus rv = SGN_Begin(result->sign_context_); | 59 SECStatus rv = SGN_Begin(result->sign_context_); |
62 if (rv != SECSuccess) { | 60 if (rv != SECSuccess) { |
63 NOTREACHED(); | 61 NOTREACHED(); |
64 return NULL; | 62 return NULL; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 SECStatus rv = SGN_End(sign_context_, &signature_item); | 104 SECStatus rv = SGN_End(sign_context_, &signature_item); |
107 if (rv != SECSuccess) { | 105 if (rv != SECSuccess) { |
108 return false; | 106 return false; |
109 } | 107 } |
110 signature->assign(signature_item.data, | 108 signature->assign(signature_item.data, |
111 signature_item.data + signature_item.len); | 109 signature_item.data + signature_item.len); |
112 SECITEM_FreeItem(&signature_item, PR_FALSE); | 110 SECITEM_FreeItem(&signature_item, PR_FALSE); |
113 return true; | 111 return true; |
114 } | 112 } |
115 | 113 |
116 SignatureCreator::SignatureCreator() | 114 SignatureCreator::SignatureCreator() : sign_context_(NULL) { |
117 : key_(NULL), | |
118 sign_context_(NULL) { | |
119 EnsureNSSInit(); | 115 EnsureNSSInit(); |
120 } | 116 } |
121 | 117 |
122 } // namespace crypto | 118 } // namespace crypto |
OLD | NEW |