OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return "public"; | 46 return "public"; |
47 case WebKit::WebCryptoKeyTypePrivate: | 47 case WebKit::WebCryptoKeyTypePrivate: |
48 return "private"; | 48 return "private"; |
49 } | 49 } |
50 ASSERT_NOT_REACHED(); | 50 ASSERT_NOT_REACHED(); |
51 return 0; | 51 return 0; |
52 } | 52 } |
53 | 53 |
54 const char* keyUsageToString(WebKit::WebCryptoKeyUsage usage) | 54 const char* keyUsageToString(WebKit::WebCryptoKeyUsage usage) |
55 { | 55 { |
| 56 // NOTE: Keep this in sync with keyUsageStringToMask() below. |
56 switch (usage) { | 57 switch (usage) { |
57 case WebKit::WebCryptoKeyUsageEncrypt: | 58 case WebKit::WebCryptoKeyUsageEncrypt: |
58 return "encrypt"; | 59 return "encrypt"; |
59 case WebKit::WebCryptoKeyUsageDecrypt: | 60 case WebKit::WebCryptoKeyUsageDecrypt: |
60 return "decrypt"; | 61 return "decrypt"; |
61 case WebKit::WebCryptoKeyUsageSign: | 62 case WebKit::WebCryptoKeyUsageSign: |
62 return "sign"; | 63 return "sign"; |
63 case WebKit::WebCryptoKeyUsageVerify: | 64 case WebKit::WebCryptoKeyUsageVerify: |
64 return "verify"; | 65 return "verify"; |
65 case WebKit::WebCryptoKeyUsageDeriveKey: | 66 case WebKit::WebCryptoKeyUsageDeriveKey: |
66 return "deriveKey"; | 67 return "deriveKey"; |
67 case WebKit::WebCryptoKeyUsageWrapKey: | 68 case WebKit::WebCryptoKeyUsageWrapKey: |
68 return "wrapKey"; | 69 return "wrapKey"; |
69 case WebKit::WebCryptoKeyUsageUnwrapKey: | 70 case WebKit::WebCryptoKeyUsageUnwrapKey: |
70 return "unwrapKey"; | 71 return "unwrapKey"; |
71 case WebKit::EndOfWebCryptoKeyUsage: | 72 case WebKit::EndOfWebCryptoKeyUsage: |
72 break; | 73 break; |
73 } | 74 } |
74 ASSERT_NOT_REACHED(); | 75 ASSERT_NOT_REACHED(); |
75 return 0; | 76 return 0; |
76 } | 77 } |
77 | 78 |
| 79 WebKit::WebCryptoKeyUsageMask keyUsageStringToMask(const String& usageString) |
| 80 { |
| 81 // There are few enough values that testing serially is fast enough. |
| 82 if (usageString == "encrypt") |
| 83 return WebKit::WebCryptoKeyUsageEncrypt; |
| 84 if (usageString == "decrypt") |
| 85 return WebKit::WebCryptoKeyUsageDecrypt; |
| 86 if (usageString == "sign") |
| 87 return WebKit::WebCryptoKeyUsageSign; |
| 88 if (usageString == "verify") |
| 89 return WebKit::WebCryptoKeyUsageVerify; |
| 90 if (usageString == "deriveKey") |
| 91 return WebKit::WebCryptoKeyUsageDeriveKey; |
| 92 if (usageString == "wrapKey") |
| 93 return WebKit::WebCryptoKeyUsageWrapKey; |
| 94 if (usageString == "unwrapKey") |
| 95 return WebKit::WebCryptoKeyUsageUnwrapKey; |
| 96 |
| 97 return 0; |
| 98 } |
| 99 |
78 } // namespace | 100 } // namespace |
79 | 101 |
80 Key::Key(const WebKit::WebCryptoKey& key) | 102 Key::Key(const WebKit::WebCryptoKey& key) |
81 : m_key(key) | 103 : m_key(key) |
82 { | 104 { |
83 ScriptWrappable::init(this); | 105 ScriptWrappable::init(this); |
84 } | 106 } |
85 | 107 |
86 String Key::type() const | 108 String Key::type() const |
87 { | 109 { |
(...skipping 22 matching lines...) Expand all Loading... |
110 | 132 |
111 // The WebCryptoKeyUsage values are consecutive powers of 2. Test each one i
n order. | 133 // The WebCryptoKeyUsage values are consecutive powers of 2. Test each one i
n order. |
112 for (int i = 0; (1 << i) < WebKit::EndOfWebCryptoKeyUsage; ++i) { | 134 for (int i = 0; (1 << i) < WebKit::EndOfWebCryptoKeyUsage; ++i) { |
113 WebKit::WebCryptoKeyUsage usage = static_cast<WebKit::WebCryptoKeyUsage>
(1 << i); | 135 WebKit::WebCryptoKeyUsage usage = static_cast<WebKit::WebCryptoKeyUsage>
(1 << i); |
114 if (m_key.usages() & usage) | 136 if (m_key.usages() & usage) |
115 result.append(ASCIILiteral(keyUsageToString(usage))); | 137 result.append(ASCIILiteral(keyUsageToString(usage))); |
116 } | 138 } |
117 return result; | 139 return result; |
118 } | 140 } |
119 | 141 |
| 142 bool Key::parseFormat(const String& formatString, WebKit::WebCryptoKeyFormat& fo
rmat) |
| 143 { |
| 144 // There are few enough values that testing serially is fast enough. |
| 145 if (formatString == "raw") { |
| 146 format = WebKit::WebCryptoKeyFormatRaw; |
| 147 return true; |
| 148 } |
| 149 if (formatString == "pkcs8") { |
| 150 format = WebKit::WebCryptoKeyFormatPkcs8; |
| 151 return true; |
| 152 } |
| 153 if (formatString == "spki") { |
| 154 format = WebKit::WebCryptoKeyFormatSpki; |
| 155 return true; |
| 156 } |
| 157 if (formatString == "jwk") { |
| 158 format = WebKit::WebCryptoKeyFormatJwk; |
| 159 return true; |
| 160 } |
| 161 |
| 162 return false; |
| 163 } |
| 164 |
| 165 bool Key::parseUsageMask(const Vector<String>& usages, WebKit::WebCryptoKeyUsage
Mask& mask) |
| 166 { |
| 167 mask = 0; |
| 168 for (size_t i = 0; i < usages.size(); ++i) { |
| 169 WebKit::WebCryptoKeyUsageMask usage = keyUsageStringToMask(usages[i]); |
| 170 if (!usage) |
| 171 return false; |
| 172 mask |= usage; |
| 173 } |
| 174 return true; |
| 175 } |
| 176 |
120 } // namespace WebCore | 177 } // namespace WebCore |
OLD | NEW |