Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: base/crypto/rsa_private_key.h

Issue 208032: Linux (nss) implementations of RSAPrivateKey and SignatureCreator (Closed)
Patch Set: last cr changes. Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/base.gyp ('k') | base/crypto/rsa_private_key_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_RSA_PRIVATE_KEY_H_ 5 #ifndef BASE_CRYPTO_RSA_PRIVATE_KEY_H_
6 #define BASE_CRYPTO_RSA_PRIVATE_KEY_H_ 6 #define BASE_CRYPTO_RSA_PRIVATE_KEY_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #if defined(OS_WIN) 10 #if defined(USE_NSS)
11 #include <cryptoht.h>
12 #include <keythi.h>
13 #elif defined(OS_MACOSX)
14 // TODO(port);
15 #elif defined(OS_WIN)
11 #include <windows.h> 16 #include <windows.h>
12 #include <wincrypt.h> 17 #include <wincrypt.h>
13 #else
14 // TODO(port)
15 #endif 18 #endif
16 19
17 #include <vector> 20 #include <vector>
18 21
19 #include "base/basictypes.h" 22 #include "base/basictypes.h"
20 23
21 namespace base { 24 namespace base {
22 25
23 // Encapsulates an RSA private key. Can be used to generate new keys, export 26 // Encapsulates an RSA private key. Can be used to generate new keys, export
24 // keys to other formats, or to extract a public key. 27 // keys to other formats, or to extract a public key.
25 class RSAPrivateKey { 28 class RSAPrivateKey {
26 public: 29 public:
27 // Create a new random instance. Can return NULL if initialization fails. 30 // Create a new random instance. Can return NULL if initialization fails.
28 static RSAPrivateKey* Create(uint16 num_bits); 31 static RSAPrivateKey* Create(uint16 num_bits);
29 32
30 // Create a new instance by importing an existing private key. The format is 33 // Create a new instance by importing an existing private key. The format is
31 // an ASN.1-encoded PrivateKeyInfo block from PKCS #8. This can return NULL if 34 // an ASN.1-encoded PrivateKeyInfo block from PKCS #8. This can return NULL if
32 // initialization fails. 35 // initialization fails.
33 static RSAPrivateKey* CreateFromPrivateKeyInfo( 36 static RSAPrivateKey* CreateFromPrivateKeyInfo(
34 const std::vector<uint8>& input); 37 const std::vector<uint8>& input);
35 38
36 ~RSAPrivateKey(); 39 ~RSAPrivateKey();
37 40
38 #if defined(OS_WIN) 41 #if defined(USE_NSS)
42 SECKEYPrivateKey* key() { return key_; }
43 #elif defined(OS_WIN)
39 HCRYPTPROV provider() { return provider_; } 44 HCRYPTPROV provider() { return provider_; }
40 HCRYPTKEY key() { return key_; } 45 HCRYPTKEY key() { return key_; }
41 #endif 46 #endif
42 47
43 // Exports the private key to a PKCS #1 PrivateKey block. 48 // Exports the private key to a PKCS #1 PrivateKey block.
44 bool ExportPrivateKey(std::vector<uint8>* output); 49 bool ExportPrivateKey(std::vector<uint8>* output);
45 50
46 // Exports the public key to an X509 SubjectPublicKeyInfo block. 51 // Exports the public key to an X509 SubjectPublicKeyInfo block.
47 bool ExportPublicKey(std::vector<uint8>* output); 52 bool ExportPublicKey(std::vector<uint8>* output);
48 53
49 private: 54 private:
50 // Constructor is private. Use Create() or CreateFromPrivateKeyInfo() 55 // Constructor is private. Use Create() or CreateFromPrivateKeyInfo()
51 // instead. 56 // instead.
52 RSAPrivateKey(); 57 RSAPrivateKey();
53 58
54 #if defined(OS_WIN) 59 #if defined(USE_NSS)
60 SECKEYPrivateKey* key_;
61 SECKEYPublicKey* public_key_;
62 #elif defined(OS_WIN)
55 bool InitProvider(); 63 bool InitProvider();
56 64
57 HCRYPTPROV provider_; 65 HCRYPTPROV provider_;
58 HCRYPTKEY key_; 66 HCRYPTKEY key_;
59 #endif 67 #endif
60 68
61 DISALLOW_COPY_AND_ASSIGN(RSAPrivateKey); 69 DISALLOW_COPY_AND_ASSIGN(RSAPrivateKey);
62 }; 70 };
63 71
64 } // namespace base 72 } // namespace base
65 73
66 #endif // BASE_CRYPTO_RSA_PRIVATE_KEY_H_ 74 #endif // BASE_CRYPTO_RSA_PRIVATE_KEY_H_
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | base/crypto/rsa_private_key_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698