Chromium Code Reviews| Index: Source/modules/crypto/Key.cpp |
| diff --git a/Source/modules/crypto/Key.cpp b/Source/modules/crypto/Key.cpp |
| index d10fbd4249dd3403a7e9efe49896250bff693730..3866b732b8a945054534b2445af8fbe400c16995 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. |
|
abarth-chromium
2013/07/23 21:45:49
IMHO, a table would be more maintainable here, but
eroman
2013/07/23 23:29:02
Done.
|
| switch (usage) { |
| case WebKit::WebCryptoKeyUsageEncrypt: |
| return "encrypt"; |
| @@ -75,8 +76,33 @@ 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() |
| +{ |
| +} |
| + |
| Key::Key(const WebKit::WebCryptoKey& key) |
| : m_key(key) |
| { |
| @@ -117,4 +143,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 |