| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 blink::WebCryptoKeyUsage usage = keyUsageMappings[i].value; | 161 blink::WebCryptoKeyUsage usage = keyUsageMappings[i].value; |
| 162 if (m_key.usages() & usage) | 162 if (m_key.usages() & usage) |
| 163 result.append(keyUsageToString(usage)); | 163 result.append(keyUsageToString(usage)); |
| 164 } | 164 } |
| 165 return result; | 165 return result; |
| 166 } | 166 } |
| 167 | 167 |
| 168 bool Key::canBeUsedForAlgorithm(const blink::WebCryptoAlgorithm& algorithm, Algo
rithmOperation op, CryptoResult* result) const | 168 bool Key::canBeUsedForAlgorithm(const blink::WebCryptoAlgorithm& algorithm, Algo
rithmOperation op, CryptoResult* result) const |
| 169 { | 169 { |
| 170 if (!(m_key.usages() & toKeyUsage(op))) { | 170 if (!(m_key.usages() & toKeyUsage(op))) { |
| 171 result->completeWithError("key.usages does not permit this operation"); | 171 result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key.u
sages does not permit this operation"); |
| 172 return false; | 172 return false; |
| 173 } | 173 } |
| 174 | 174 |
| 175 if (m_key.algorithm().id() != algorithm.id()) { | 175 if (m_key.algorithm().id() != algorithm.id()) { |
| 176 result->completeWithError("key.algorithm does not match that of operatio
n"); | 176 result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key.a
lgorithm does not match that of operation"); |
| 177 return false; | 177 return false; |
| 178 } | 178 } |
| 179 | 179 |
| 180 return true; | 180 return true; |
| 181 } | 181 } |
| 182 | 182 |
| 183 bool Key::parseFormat(const String& formatString, blink::WebCryptoKeyFormat& for
mat, CryptoResult* result) | 183 bool Key::parseFormat(const String& formatString, blink::WebCryptoKeyFormat& for
mat, CryptoResult* result) |
| 184 { | 184 { |
| 185 // There are few enough values that testing serially is fast enough. | 185 // There are few enough values that testing serially is fast enough. |
| 186 if (formatString == "raw") { | 186 if (formatString == "raw") { |
| 187 format = blink::WebCryptoKeyFormatRaw; | 187 format = blink::WebCryptoKeyFormatRaw; |
| 188 return true; | 188 return true; |
| 189 } | 189 } |
| 190 if (formatString == "pkcs8") { | 190 if (formatString == "pkcs8") { |
| 191 format = blink::WebCryptoKeyFormatPkcs8; | 191 format = blink::WebCryptoKeyFormatPkcs8; |
| 192 return true; | 192 return true; |
| 193 } | 193 } |
| 194 if (formatString == "spki") { | 194 if (formatString == "spki") { |
| 195 format = blink::WebCryptoKeyFormatSpki; | 195 format = blink::WebCryptoKeyFormatSpki; |
| 196 return true; | 196 return true; |
| 197 } | 197 } |
| 198 if (formatString == "jwk") { | 198 if (formatString == "jwk") { |
| 199 format = blink::WebCryptoKeyFormatJwk; | 199 format = blink::WebCryptoKeyFormatJwk; |
| 200 return true; | 200 return true; |
| 201 } | 201 } |
| 202 | 202 |
| 203 result->completeWithError("Invalid keyFormat argument"); | 203 result->completeWithError(blink::WebCryptoErrorTypeSyntax, "Invalid keyForma
t argument"); |
| 204 return false; | 204 return false; |
| 205 } | 205 } |
| 206 | 206 |
| 207 bool Key::parseUsageMask(const Vector<String>& usages, blink::WebCryptoKeyUsageM
ask& mask, CryptoResult* result) | 207 bool Key::parseUsageMask(const Vector<String>& usages, blink::WebCryptoKeyUsageM
ask& mask, CryptoResult* result) |
| 208 { | 208 { |
| 209 mask = 0; | 209 mask = 0; |
| 210 for (size_t i = 0; i < usages.size(); ++i) { | 210 for (size_t i = 0; i < usages.size(); ++i) { |
| 211 blink::WebCryptoKeyUsageMask usage = keyUsageStringToMask(usages[i]); | 211 blink::WebCryptoKeyUsageMask usage = keyUsageStringToMask(usages[i]); |
| 212 if (!usage) { | 212 if (!usage) { |
| 213 result->completeWithError("Invalid keyUsages argument"); | 213 result->completeWithError(blink::WebCryptoErrorTypeSyntax, "Invalid
keyUsages argument"); |
| 214 return false; | 214 return false; |
| 215 } | 215 } |
| 216 mask |= usage; | 216 mask |= usage; |
| 217 } | 217 } |
| 218 return true; | 218 return true; |
| 219 } | 219 } |
| 220 | 220 |
| 221 void Key::trace(Visitor* visitor) | 221 void Key::trace(Visitor* visitor) |
| 222 { | 222 { |
| 223 visitor->trace(m_algorithm); | 223 visitor->trace(m_algorithm); |
| 224 } | 224 } |
| 225 | 225 |
| 226 } // namespace WebCore | 226 } // namespace WebCore |
| OLD | NEW |