| 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;
|
| +
|
| + 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
|
|
|