| 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 namespace webcrypto { | 12 namespace webcrypto { |
| 10 | 13 |
| 11 bool Status::IsError() const { | 14 bool Status::IsError() const { |
| 12 return type_ == TYPE_ERROR; | 15 return type_ == TYPE_ERROR; |
| 13 } | 16 } |
| 14 | 17 |
| 15 bool Status::IsSuccess() const { | 18 bool Status::IsSuccess() const { |
| 16 return type_ == TYPE_SUCCESS; | 19 return type_ == TYPE_SUCCESS; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 return Status(blink::WebCryptoErrorTypeData, | 239 return Status(blink::WebCryptoErrorTypeData, |
| 237 "Invalid key length: it is either zero or not a multiple of 8 " | 240 "Invalid key length: it is either zero or not a multiple of 8 " |
| 238 "bits"); | 241 "bits"); |
| 239 } | 242 } |
| 240 | 243 |
| 241 Status Status::ErrorCreateKeyBadUsages() { | 244 Status Status::ErrorCreateKeyBadUsages() { |
| 242 return Status(blink::WebCryptoErrorTypeSyntax, | 245 return Status(blink::WebCryptoErrorTypeSyntax, |
| 243 "Cannot create a key using the specified key usages."); | 246 "Cannot create a key using the specified key usages."); |
| 244 } | 247 } |
| 245 | 248 |
| 249 Status Status::ErrorImportedEcKeyIncorrectCurve() { |
| 250 return Status( |
| 251 blink::WebCryptoErrorTypeData, |
| 252 "The imported EC key specifies a different curve than requested"); |
| 253 } |
| 254 |
| 255 Status Status::ErrorJwkIncorrectCrv() { |
| 256 return Status( |
| 257 blink::WebCryptoErrorTypeData, |
| 258 "The JWK's \"crv\" member specifies a different curve than requested"); |
| 259 } |
| 260 |
| 261 Status Status::ErrorEcKeyInvalid() { |
| 262 return Status(blink::WebCryptoErrorTypeData, |
| 263 "The imported EC key is invalid"); |
| 264 } |
| 265 |
| 266 Status Status::JwkOctetStringWrongLength(const std::string& member_name, |
| 267 size_t expected_length, |
| 268 size_t actual_length) { |
| 269 return Status( |
| 270 blink::WebCryptoErrorTypeData, |
| 271 base::StringPrintf( |
| 272 "The JWK's \"%s\" member defines an octet string of length %" PRIuS |
| 273 " bytes but should be %" PRIuS, |
| 274 member_name.c_str(), actual_length, expected_length)); |
| 275 } |
| 276 |
| 246 Status::Status(blink::WebCryptoErrorType error_type, | 277 Status::Status(blink::WebCryptoErrorType error_type, |
| 247 const std::string& error_details_utf8) | 278 const std::string& error_details_utf8) |
| 248 : type_(TYPE_ERROR), | 279 : type_(TYPE_ERROR), |
| 249 error_type_(error_type), | 280 error_type_(error_type), |
| 250 error_details_(error_details_utf8) { | 281 error_details_(error_details_utf8) { |
| 251 } | 282 } |
| 252 | 283 |
| 253 Status::Status(Type type) : type_(type) { | 284 Status::Status(Type type) : type_(type) { |
| 254 } | 285 } |
| 255 | 286 |
| 256 } // namespace webcrypto | 287 } // namespace webcrypto |
| 257 | 288 |
| 258 } // namespace content | 289 } // namespace content |
| OLD | NEW |