summaryrefslogtreecommitdiffstats
path: root/base/crypto/rsa_private_key_nss.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/crypto/rsa_private_key_nss.cc')
-rw-r--r--base/crypto/rsa_private_key_nss.cc135
1 files changed, 68 insertions, 67 deletions
diff --git a/base/crypto/rsa_private_key_nss.cc b/base/crypto/rsa_private_key_nss.cc
index 7786521..3084636 100644
--- a/base/crypto/rsa_private_key_nss.cc
+++ b/base/crypto/rsa_private_key_nss.cc
@@ -41,28 +41,11 @@ static bool ReadAttribute(SECKEYPrivateKey* key,
namespace base {
-// static
-RSAPrivateKey* RSAPrivateKey::CreateWithParams(uint16 num_bits,
- bool permanent,
- bool sensitive) {
- base::EnsureNSSInit();
-
- scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey);
-
- PK11SlotInfo *slot = GetDefaultNSSKeySlot();
- if (!slot)
- return NULL;
-
- PK11RSAGenParams param;
- param.keySizeInBits = num_bits;
- param.pe = 65537L;
- result->key_ = PK11_GenerateKeyPair(slot, CKM_RSA_PKCS_KEY_PAIR_GEN, &param,
- &result->public_key_, permanent, sensitive, NULL);
- PK11_FreeSlot(slot);
- if (!result->key_)
- return NULL;
-
- return result.release();
+RSAPrivateKey::~RSAPrivateKey() {
+ if (key_)
+ SECKEY_DestroyPrivateKey(key_);
+ if (public_key_)
+ SECKEY_DestroyPublicKey(public_key_);
}
// static
@@ -80,41 +63,6 @@ RSAPrivateKey* RSAPrivateKey::CreateSensitive(uint16 num_bits) {
}
// static
-RSAPrivateKey* RSAPrivateKey::CreateFromPrivateKeyInfoWithParams(
- const std::vector<uint8>& input, bool permanent, bool sensitive) {
- // This method currently leaks some memory.
- // See http://crbug.com/34742.
- ANNOTATE_SCOPED_MEMORY_LEAK;
- base::EnsureNSSInit();
-
- scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey);
-
- PK11SlotInfo *slot = GetDefaultNSSKeySlot();
- if (!slot)
- return NULL;
-
- SECItem der_private_key_info;
- der_private_key_info.data = const_cast<unsigned char*>(&input.front());
- der_private_key_info.len = input.size();
- SECStatus rv = PK11_ImportDERPrivateKeyInfoAndReturnKey(slot,
- &der_private_key_info, NULL, NULL, permanent, sensitive,
- KU_DIGITAL_SIGNATURE, &result->key_, NULL);
- PK11_FreeSlot(slot);
- if (rv != SECSuccess) {
- NOTREACHED();
- return NULL;
- }
-
- result->public_key_ = SECKEY_ConvertToPublicKey(result->key_);
- if (!result->public_key_) {
- NOTREACHED();
- return NULL;
- }
-
- return result.release();
-}
-
-// static
RSAPrivateKey* RSAPrivateKey::CreateFromPrivateKeyInfo(
const std::vector<uint8>& input) {
return CreateFromPrivateKeyInfoWithParams(input,
@@ -193,16 +141,6 @@ RSAPrivateKey* RSAPrivateKey::FindFromPublicKeyInfo(
return result.release();
}
-RSAPrivateKey::RSAPrivateKey() : key_(NULL), public_key_(NULL) {
- EnsureNSSInit();
-}
-
-RSAPrivateKey::~RSAPrivateKey() {
- if (key_)
- SECKEY_DestroyPrivateKey(key_);
- if (public_key_)
- SECKEY_DestroyPublicKey(public_key_);
-}
bool RSAPrivateKey::ExportPrivateKey(std::vector<uint8>* output) {
PrivateKeyInfoCodec private_key_info(true);
@@ -240,4 +178,67 @@ bool RSAPrivateKey::ExportPublicKey(std::vector<uint8>* output) {
return true;
}
+RSAPrivateKey::RSAPrivateKey() : key_(NULL), public_key_(NULL) {
+ EnsureNSSInit();
+}
+
+// static
+RSAPrivateKey* RSAPrivateKey::CreateWithParams(uint16 num_bits,
+ bool permanent,
+ bool sensitive) {
+ base::EnsureNSSInit();
+
+ scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey);
+
+ PK11SlotInfo *slot = GetDefaultNSSKeySlot();
+ if (!slot)
+ return NULL;
+
+ PK11RSAGenParams param;
+ param.keySizeInBits = num_bits;
+ param.pe = 65537L;
+ result->key_ = PK11_GenerateKeyPair(slot, CKM_RSA_PKCS_KEY_PAIR_GEN, &param,
+ &result->public_key_, permanent, sensitive, NULL);
+ PK11_FreeSlot(slot);
+ if (!result->key_)
+ return NULL;
+
+ return result.release();
+}
+
+// static
+RSAPrivateKey* RSAPrivateKey::CreateFromPrivateKeyInfoWithParams(
+ const std::vector<uint8>& input, bool permanent, bool sensitive) {
+ // This method currently leaks some memory.
+ // See http://crbug.com/34742.
+ ANNOTATE_SCOPED_MEMORY_LEAK;
+ base::EnsureNSSInit();
+
+ scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey);
+
+ PK11SlotInfo *slot = GetDefaultNSSKeySlot();
+ if (!slot)
+ return NULL;
+
+ SECItem der_private_key_info;
+ der_private_key_info.data = const_cast<unsigned char*>(&input.front());
+ der_private_key_info.len = input.size();
+ SECStatus rv = PK11_ImportDERPrivateKeyInfoAndReturnKey(slot,
+ &der_private_key_info, NULL, NULL, permanent, sensitive,
+ KU_DIGITAL_SIGNATURE, &result->key_, NULL);
+ PK11_FreeSlot(slot);
+ if (rv != SECSuccess) {
+ NOTREACHED();
+ return NULL;
+ }
+
+ result->public_key_ = SECKEY_ConvertToPublicKey(result->key_);
+ if (!result->public_key_) {
+ NOTREACHED();
+ return NULL;
+ }
+
+ return result.release();
+}
+
} // namespace base