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