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

Unified Diff: content/child/webcrypto/test/test_helpers.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run git-cl format Created 6 years, 2 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
« no previous file with comments | « content/child/webcrypto/test/test_helpers.h ('k') | content/child/webcrypto/webcrypto_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/test/test_helpers.cc
diff --git a/content/child/webcrypto/test/test_helpers.cc b/content/child/webcrypto/test/test_helpers.cc
index e7f76ff3e532acf087d92a39c8fc01c8016288dc..ddabd7574c459a881144d253ad7ffed26e1c41d8 100644
--- a/content/child/webcrypto/test/test_helpers.cc
+++ b/content/child/webcrypto/test/test_helpers.cc
@@ -17,6 +17,7 @@
#include "base/values.h"
#include "content/child/webcrypto/algorithm_dispatch.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/status.h"
#include "content/child/webcrypto/webcrypto_util.h"
@@ -580,6 +581,42 @@ void ImportExportJwkSymmetricKey(
EXPECT_BYTES_EQ_HEX(key_hex, key_raw_out);
}
+Status GenerateSecretKey(const blink::WebCryptoAlgorithm& algorithm,
+ bool extractable,
+ blink::WebCryptoKeyUsageMask usage_mask,
+ blink::WebCryptoKey* key) {
+ GenerateKeyResult result;
+ Status status = GenerateKey(algorithm, extractable, usage_mask, &result);
+ if (status.IsError())
+ return status;
+
+ if (result.type() != GenerateKeyResult::TYPE_SECRET_KEY)
+ return Status::ErrorUnexpected();
+
+ *key = result.secret_key();
+
+ return Status::Success();
+}
+
+Status GenerateKeyPair(const blink::WebCryptoAlgorithm& algorithm,
+ bool extractable,
+ blink::WebCryptoKeyUsageMask usage_mask,
+ blink::WebCryptoKey* public_key,
+ blink::WebCryptoKey* private_key) {
+ GenerateKeyResult result;
+ Status status = GenerateKey(algorithm, extractable, usage_mask, &result);
+ if (status.IsError())
+ return status;
+
+ if (result.type() != GenerateKeyResult::TYPE_PUBLIC_PRIVATE_KEY_PAIR)
+ return Status::ErrorUnexpected();
+
+ *public_key = result.public_key();
+ *private_key = result.private_key();
+
+ return Status::Success();
+}
+
} // namespace webcrypto
} // namesapce content
« no previous file with comments | « content/child/webcrypto/test/test_helpers.h ('k') | content/child/webcrypto/webcrypto_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698