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

Unified Diff: content/child/webcrypto/openssl/rsa_key_openssl.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a new return type "GenerateKeyPairResult" to encapsulate secretkey vs keypair Created 6 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 side-by-side diff with in-line comments
Download patch
Index: content/child/webcrypto/openssl/rsa_key_openssl.cc
diff --git a/content/child/webcrypto/openssl/rsa_key_openssl.cc b/content/child/webcrypto/openssl/rsa_key_openssl.cc
index cd8197aa86177952c96c873874fefd655ad3aa3a..8848d091a55c1ec98ab9debe8550a9056c376fd1 100644
--- a/content/child/webcrypto/openssl/rsa_key_openssl.cc
+++ b/content/child/webcrypto/openssl/rsa_key_openssl.cc
@@ -10,6 +10,7 @@
#include "base/logging.h"
#include "base/stl_util.h"
#include "content/child/webcrypto/crypto_data.h"
+#include "content/child/webcrypto/generate_key_result.h"
#include "content/child/webcrypto/jwk.h"
#include "content/child/webcrypto/openssl/key_openssl.h"
#include "content/child/webcrypto/status.h"
@@ -228,34 +229,27 @@ Status ImportRsaPublicKey(const blink::WebCryptoAlgorithm& algorithm,
} // namespace
-Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeGenerateKeyPair(
+Status RsaHashedAlgorithm::GenerateKey(
+ const blink::WebCryptoAlgorithm& algorithm,
+ bool extractable,
blink::WebCryptoKeyUsageMask combined_usage_mask,
- blink::WebCryptoKeyUsageMask* public_usage_mask,
- blink::WebCryptoKeyUsageMask* private_usage_mask) const {
+ GenerateKeyResult* result) const {
Status status = CheckKeyCreationUsages(
all_public_key_usages_ | all_private_key_usages_, combined_usage_mask);
if (status.IsError())
return status;
- *public_usage_mask = combined_usage_mask & all_public_key_usages_;
- *private_usage_mask = combined_usage_mask & all_private_key_usages_;
-
- return Status::Success();
-}
+ const blink::WebCryptoKeyUsageMask public_usage_mask =
+ combined_usage_mask & all_public_key_usages_;
+ const blink::WebCryptoKeyUsageMask private_usage_mask =
+ combined_usage_mask & all_private_key_usages_;
-Status RsaHashedAlgorithm::GenerateKeyPair(
- const blink::WebCryptoAlgorithm& algorithm,
- bool extractable,
- blink::WebCryptoKeyUsageMask public_usage_mask,
- blink::WebCryptoKeyUsageMask private_usage_mask,
- blink::WebCryptoKey* public_key,
- blink::WebCryptoKey* private_key) const {
const blink::WebCryptoRsaHashedKeyGenParams* params =
algorithm.rsaHashedKeyGenParams();
unsigned int public_exponent = 0;
unsigned int modulus_length_bits = 0;
- Status status =
+ status =
GetRsaKeyGenParameters(params, &public_exponent, &modulus_length_bits);
if (status.IsError())
return status;
@@ -290,6 +284,8 @@ Status RsaHashedAlgorithm::GenerateKeyPair(
return Status::OperationError();
}
+ result->set_type(GenerateKeyResult::TYPE_PUBLIC_PRIVATE_KEY_PAIR);
+
// Note that extractable is unconditionally set to true. This is because per
// the WebCrypto spec generated public keys are always public.
status = CreateWebCryptoPublicKey(public_pkey.Pass(),
@@ -297,7 +293,7 @@ Status RsaHashedAlgorithm::GenerateKeyPair(
params->hash(),
true,
public_usage_mask,
- public_key);
+ result->mutable_public_key());
if (status.IsError())
return status;
@@ -306,7 +302,7 @@ Status RsaHashedAlgorithm::GenerateKeyPair(
params->hash(),
extractable,
private_usage_mask,
- private_key);
+ result->mutable_private_key());
}
Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeImportKey(

Powered by Google App Engine
This is Rietveld 408576698