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
3 // found in the LICENSE file.
5 #ifndef CRYPTO_SIGNATURE_CREATOR_H_
6 #define CRYPTO_SIGNATURE_CREATOR_H_
8 #include "build/build_config.h"
10 #if defined(USE_OPENSSL)
11 // Forward declaration for openssl/*.h
12 typedef struct env_md_ctx_st EVP_MD_CTX
;
13 #elif defined(USE_NSS)
14 // Forward declaration.
16 #elif defined(OS_MACOSX) && !defined(OS_IOS)
17 #include <Security/cssm.h>
22 #include "base/basictypes.h"
23 #include "crypto/crypto_export.h"
26 #include "crypto/scoped_capi_types.h"
33 // Signs data using a bare private key (as opposed to a full certificate).
34 // Currently can only sign data using SHA-1 with RSA encryption.
35 class CRYPTO_EXPORT SignatureCreator
{
39 // Create an instance. The caller must ensure that the provided PrivateKey
40 // instance outlives the created SignatureCreator.
41 static SignatureCreator
* Create(RSAPrivateKey
* key
);
43 // Update the signature with more data.
44 bool Update(const uint8
* data_part
, int data_part_len
);
46 // Finalize the signature.
47 bool Final(std::vector
<uint8
>* signature
);
50 // Private constructor. Use the Create() method instead.
55 #if defined(USE_OPENSSL)
56 EVP_MD_CTX
* sign_context_
;
57 #elif defined(USE_NSS)
58 SGNContextStr
* sign_context_
;
59 #elif defined(OS_MACOSX) && !defined(OS_IOS)
60 CSSM_CC_HANDLE sig_handle_
;
62 ScopedHCRYPTHASH hash_object_
;
65 DISALLOW_COPY_AND_ASSIGN(SignatureCreator
);
70 #endif // CRYPTO_SIGNATURE_CREATOR_H_