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

Unified Diff: content/child/webcrypto/webcrypto_util.cc

Issue 787123003: Refactor: Extract some duplicated code for verifying usages during import of asymmetric key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years 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/webcrypto_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/webcrypto_util.cc
diff --git a/content/child/webcrypto/webcrypto_util.cc b/content/child/webcrypto/webcrypto_util.cc
index 6dad83fcae7dae6c9cb0bd1ecd7b50139d56c670..64b827db1c76b4a788e08ad459c29f275b8263b9 100644
--- a/content/child/webcrypto/webcrypto_util.cc
+++ b/content/child/webcrypto/webcrypto_util.cc
@@ -262,6 +262,31 @@ Status GetRsaKeyGenParameters(
return Status::Success();
}
+Status VerifyUsagesBeforeImportAsymmetricKey(
+ blink::WebCryptoKeyFormat format,
+ blink::WebCryptoKeyUsageMask all_public_key_usages,
+ blink::WebCryptoKeyUsageMask all_private_key_usages,
+ blink::WebCryptoKeyUsageMask usages) {
+ switch (format) {
+ case blink::WebCryptoKeyFormatSpki:
+ return CheckKeyCreationUsages(all_public_key_usages, usages);
+ case blink::WebCryptoKeyFormatPkcs8:
+ return CheckKeyCreationUsages(all_private_key_usages, usages);
+ case blink::WebCryptoKeyFormatJwk: {
+ // The JWK could represent either a public key or private key. The usages
+ // must make sense for one of the two. The usages will be checked again by
+ // ImportKeyJwk() once the key type has been determined.
+ if (CheckKeyCreationUsages(all_public_key_usages, usages).IsError() &&
+ CheckKeyCreationUsages(all_private_key_usages, usages).IsError()) {
+ return Status::ErrorCreateKeyBadUsages();
+ }
+ return Status::Success();
+ }
+ default:
+ return Status::ErrorUnsupportedImportKeyFormat();
+ }
+}
+
} // namespace webcrypto
} // namespace content
« no previous file with comments | « content/child/webcrypto/webcrypto_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698