| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/child/webcrypto/status.h" | 5 #include "content/child/webcrypto/status.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" |
| 8 #include "base/strings/stringprintf.h" |
| 9 |
| 7 namespace content { | 10 namespace content { |
| 8 | 11 |
| 9 // TODO(eroman): The error text for JWK uses the terminology "property" however | 12 // TODO(eroman): The error text for JWK uses the terminology "property" however |
| 10 // it should instead call it a "member". Changing this needs to coordinate with | 13 // it should instead call it a "member". Changing this needs to coordinate with |
| 11 // the Blink LayoutTests as they depend on the old names. | 14 // the Blink LayoutTests as they depend on the old names. |
| 12 | 15 |
| 13 namespace webcrypto { | 16 namespace webcrypto { |
| 14 | 17 |
| 15 bool Status::IsError() const { | 18 bool Status::IsError() const { |
| 16 return type_ == TYPE_ERROR; | 19 return type_ == TYPE_ERROR; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 return Status(blink::WebCryptoErrorTypeData, | 245 return Status(blink::WebCryptoErrorTypeData, |
| 243 "Invalid key length: it is either zero or not a multiple of 8 " | 246 "Invalid key length: it is either zero or not a multiple of 8 " |
| 244 "bits"); | 247 "bits"); |
| 245 } | 248 } |
| 246 | 249 |
| 247 Status Status::ErrorCreateKeyBadUsages() { | 250 Status Status::ErrorCreateKeyBadUsages() { |
| 248 return Status(blink::WebCryptoErrorTypeSyntax, | 251 return Status(blink::WebCryptoErrorTypeSyntax, |
| 249 "Cannot create a key using the specified key usages."); | 252 "Cannot create a key using the specified key usages."); |
| 250 } | 253 } |
| 251 | 254 |
| 255 Status Status::ErrorImportedEcKeyIncorrectCurve() { |
| 256 return Status( |
| 257 blink::WebCryptoErrorTypeData, |
| 258 "The imported EC key specifies a different curve than requested"); |
| 259 } |
| 260 |
| 261 Status Status::ErrorJwkIncorrectCrv() { |
| 262 return Status( |
| 263 blink::WebCryptoErrorTypeData, |
| 264 "The JWK's \"crv\" member specifies a different curve than requested"); |
| 265 } |
| 266 |
| 267 Status Status::ErrorEcKeyInvalid() { |
| 268 return Status(blink::WebCryptoErrorTypeData, |
| 269 "The imported EC key is invalid"); |
| 270 } |
| 271 |
| 272 Status Status::JwkOctetStringWrongLength(const std::string& member_name, |
| 273 size_t expected_length, |
| 274 size_t actual_length) { |
| 275 return Status( |
| 276 blink::WebCryptoErrorTypeData, |
| 277 base::StringPrintf( |
| 278 "The JWK's \"%s\" member defines an octet string of length %" PRIuS |
| 279 " bytes but should be %" PRIuS, |
| 280 member_name.c_str(), actual_length, expected_length)); |
| 281 } |
| 282 |
| 252 Status::Status(blink::WebCryptoErrorType error_type, | 283 Status::Status(blink::WebCryptoErrorType error_type, |
| 253 const std::string& error_details_utf8) | 284 const std::string& error_details_utf8) |
| 254 : type_(TYPE_ERROR), | 285 : type_(TYPE_ERROR), |
| 255 error_type_(error_type), | 286 error_type_(error_type), |
| 256 error_details_(error_details_utf8) { | 287 error_details_(error_details_utf8) { |
| 257 } | 288 } |
| 258 | 289 |
| 259 Status::Status(Type type) : type_(type) { | 290 Status::Status(Type type) : type_(type) { |
| 260 } | 291 } |
| 261 | 292 |
| 262 } // namespace webcrypto | 293 } // namespace webcrypto |
| 263 | 294 |
| 264 } // namespace content | 295 } // namespace content |
| OLD | NEW |