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