• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef BASE_CRYPTO_SIGNATURE_CREATOR_H_
6 #define BASE_CRYPTO_SIGNATURE_CREATOR_H_
7 
8 #include "build/build_config.h"
9 
10 #if defined(USE_NSS)
11 // Forward declaration.
12 struct SGNContextStr;
13 #elif defined(OS_MACOSX)
14 #include <Security/cssm.h>
15 #elif defined(OS_WIN)
16 #include <windows.h>
17 #include <wincrypt.h>
18 #endif
19 
20 #include <vector>
21 
22 #include "base/basictypes.h"
23 #include "base/crypto/rsa_private_key.h"
24 
25 namespace base {
26 
27 // 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 class SignatureCreator {
30  public:
31   // Create an instance. The caller must ensure that the provided PrivateKey
32   // instance outlives the created SignatureCreator.
33   static SignatureCreator* Create(RSAPrivateKey* key);
34 
35   ~SignatureCreator();
36 
37   // Update the signature with more data.
38   bool Update(const uint8* data_part, int data_part_len);
39 
40   // Finalize the signature.
41   bool Final(std::vector<uint8>* signature);
42 
43  private:
44   // Private constructor. Use the Create() method instead.
45   SignatureCreator();
46 
47   RSAPrivateKey* key_;
48 
49 #if defined(USE_NSS)
50   SGNContextStr* sign_context_;
51 #elif defined(OS_MACOSX)
52   CSSM_CSP_HANDLE csp_handle_;
53   CSSM_CC_HANDLE sig_handle_;
54 #elif defined(OS_WIN)
55   HCRYPTHASH hash_object_;
56 #endif
57 
58   DISALLOW_COPY_AND_ASSIGN(SignatureCreator);
59 };
60 
61 }  // namespace base
62 
63 #endif  // BASE_CRYPTO_SIGNATURE_CREATOR_H_
64