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

Unified Diff: Source/modules/crypto/Key.cpp

Issue 19885002: WebCrypto: Add interfaces for importKey(). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Move test stuff into MockWebCrypto Created 7 years, 5 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: Source/modules/crypto/Key.cpp
diff --git a/Source/modules/crypto/Key.cpp b/Source/modules/crypto/Key.cpp
index d10fbd4249dd3403a7e9efe49896250bff693730..d632b604e5c5ab2d8f576af8480e818c0f460a51 100644
--- a/Source/modules/crypto/Key.cpp
+++ b/Source/modules/crypto/Key.cpp
@@ -53,6 +53,7 @@ const char* keyTypeToString(WebKit::WebCryptoKeyType type)
const char* keyUsageToString(WebKit::WebCryptoKeyUsage usage)
{
+ // NOTE: Keep this in sync with keyUsageStringToMask() below.
switch (usage) {
case WebKit::WebCryptoKeyUsageEncrypt:
return "encrypt";
@@ -75,6 +76,27 @@ const char* keyUsageToString(WebKit::WebCryptoKeyUsage usage)
return 0;
}
+WebKit::WebCryptoKeyUsageMask keyUsageStringToMask(const String& usageString)
+{
+ // There are few enough values that testing serially is fast enough.
+ if (usageString == "encrypt")
+ return WebKit::WebCryptoKeyUsageEncrypt;
+ if (usageString == "decrypt")
+ return WebKit::WebCryptoKeyUsageDecrypt;
+ if (usageString == "sign")
+ return WebKit::WebCryptoKeyUsageSign;
+ if (usageString == "verify")
+ return WebKit::WebCryptoKeyUsageVerify;
+ if (usageString == "deriveKey")
+ return WebKit::WebCryptoKeyUsageDeriveKey;
+ if (usageString == "wrapKey")
+ return WebKit::WebCryptoKeyUsageWrapKey;
+ if (usageString == "unwrapKey")
+ return WebKit::WebCryptoKeyUsageUnwrapKey;
abarth-chromium 2013/07/23 06:22:07 Maybe use a single table to drive both? The table
eroman 2013/07/23 23:29:02 Done.
+
+ return 0;
+}
+
} // namespace
Key::Key(const WebKit::WebCryptoKey& key)
@@ -117,4 +139,39 @@ Vector<String> Key::usages() const
return result;
}
+bool Key::parseFormat(const String& formatString, WebKit::WebCryptoKeyFormat& format)
+{
+ // There are few enough values that testing serially is fast enough.
+ if (formatString == "raw") {
+ format = WebKit::WebCryptoKeyFormatRaw;
+ return true;
+ }
+ if (formatString == "pkcs8") {
+ format = WebKit::WebCryptoKeyFormatPkcs8;
+ return true;
+ }
+ if (formatString == "spki") {
+ format = WebKit::WebCryptoKeyFormatSpki;
+ return true;
+ }
+ if (formatString == "jwk") {
+ format = WebKit::WebCryptoKeyFormatJwk;
+ return true;
+ }
+
+ return false;
+}
+
+bool Key::parseUsageMask(const Vector<String>& usages, WebKit::WebCryptoKeyUsageMask& mask)
+{
+ mask = 0;
+ for (size_t i = 0; i < usages.size(); ++i) {
+ WebKit::WebCryptoKeyUsageMask usage = keyUsageStringToMask(usages[i]);
+ if (!usage)
+ return false;
+ mask |= usage;
+ }
+ return true;
+}
+
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698