OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef BASE_CRYPTO_SIGNATURE_CREATOR_H_ | 5 #ifndef BASE_CRYPTO_SIGNATURE_CREATOR_H_ |
6 #define BASE_CRYPTO_SIGNATURE_CREATOR_H_ | 6 #define BASE_CRYPTO_SIGNATURE_CREATOR_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(USE_NSS) | 10 #if defined(USE_NSS) |
11 // Forward declaration. | 11 // Forward declaration. |
12 struct SGNContextStr; | 12 struct SGNContextStr; |
13 #elif defined(OS_MACOSX) | 13 #elif defined(OS_MACOSX) |
14 #include <Security/cssm.h> | 14 #include <Security/cssm.h> |
15 #elif defined(OS_WIN) | |
16 #include <windows.h> | |
17 #include <wincrypt.h> | |
18 #endif | 15 #endif |
19 | 16 |
20 #include <vector> | 17 #include <vector> |
21 | 18 |
22 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
23 #include "base/crypto/rsa_private_key.h" | 20 #include "base/crypto/rsa_private_key.h" |
24 | 21 |
| 22 #if defined(OS_WIN) |
| 23 #include "base/crypto/scoped_capi_types.h" |
| 24 #endif |
| 25 |
25 namespace base { | 26 namespace base { |
26 | 27 |
27 // Signs data using a bare private key (as opposed to a full certificate). | 28 // Signs data using a bare private key (as opposed to a full certificate). |
28 // Currently can only sign data using SHA-1 with RSA encryption. | 29 // Currently can only sign data using SHA-1 with RSA encryption. |
29 class SignatureCreator { | 30 class SignatureCreator { |
30 public: | 31 public: |
31 // Create an instance. The caller must ensure that the provided PrivateKey | 32 // Create an instance. The caller must ensure that the provided PrivateKey |
32 // instance outlives the created SignatureCreator. | 33 // instance outlives the created SignatureCreator. |
33 static SignatureCreator* Create(RSAPrivateKey* key); | 34 static SignatureCreator* Create(RSAPrivateKey* key); |
34 | 35 |
35 ~SignatureCreator(); | 36 ~SignatureCreator(); |
36 | 37 |
37 // Update the signature with more data. | 38 // Update the signature with more data. |
38 bool Update(const uint8* data_part, int data_part_len); | 39 bool Update(const uint8* data_part, int data_part_len); |
39 | 40 |
40 // Finalize the signature. | 41 // Finalize the signature. |
41 bool Final(std::vector<uint8>* signature); | 42 bool Final(std::vector<uint8>* signature); |
42 | 43 |
43 private: | 44 private: |
44 // Private constructor. Use the Create() method instead. | 45 // Private constructor. Use the Create() method instead. |
45 SignatureCreator(); | 46 SignatureCreator(); |
46 | 47 |
47 RSAPrivateKey* key_; | 48 RSAPrivateKey* key_; |
48 | 49 |
49 #if defined(USE_NSS) | 50 #if defined(USE_NSS) |
50 SGNContextStr* sign_context_; | 51 SGNContextStr* sign_context_; |
51 #elif defined(OS_MACOSX) | 52 #elif defined(OS_MACOSX) |
52 CSSM_CC_HANDLE sig_handle_; | 53 CSSM_CC_HANDLE sig_handle_; |
53 #elif defined(OS_WIN) | 54 #elif defined(OS_WIN) |
54 HCRYPTHASH hash_object_; | 55 ScopedHCRYPTHASH hash_object_; |
55 #endif | 56 #endif |
56 | 57 |
57 DISALLOW_COPY_AND_ASSIGN(SignatureCreator); | 58 DISALLOW_COPY_AND_ASSIGN(SignatureCreator); |
58 }; | 59 }; |
59 | 60 |
60 } // namespace base | 61 } // namespace base |
61 | 62 |
62 #endif // BASE_CRYPTO_SIGNATURE_CREATOR_H_ | 63 #endif // BASE_CRYPTO_SIGNATURE_CREATOR_H_ |
OLD | NEW |