blob: bc623f7349580da1db33e1643c93232531c3e261 [file] [log] [blame]
[email protected]37be4cfa2014-03-20 05:39:371// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/child/webcrypto/status.h"
6
7namespace content {
8
9namespace webcrypto {
10
[email protected]c5039362014-04-28 19:10:3411bool Status::IsError() const {
12 return type_ == TYPE_ERROR;
[email protected]37be4cfa2014-03-20 05:39:3713}
14
[email protected]c5039362014-04-28 19:10:3415bool Status::IsSuccess() const {
16 return type_ == TYPE_SUCCESS;
17}
[email protected]37be4cfa2014-03-20 05:39:3718
[email protected]c5039362014-04-28 19:10:3419Status Status::Success() {
20 return Status(TYPE_SUCCESS);
21}
22
23Status Status::OperationError() {
24 return Status(blink::WebCryptoErrorTypeOperation, "");
25}
26
27Status Status::DataError() {
28 return Status(blink::WebCryptoErrorTypeData, "");
29}
[email protected]37be4cfa2014-03-20 05:39:3730
31Status Status::ErrorJwkNotDictionary() {
[email protected]c5039362014-04-28 19:10:3432 return Status(blink::WebCryptoErrorTypeData,
33 "JWK input could not be parsed to a JSON dictionary");
[email protected]37be4cfa2014-03-20 05:39:3734}
35
36Status Status::ErrorJwkPropertyMissing(const std::string& property) {
[email protected]c5039362014-04-28 19:10:3437 return Status(blink::WebCryptoErrorTypeData,
38 "The required JWK property \"" + property + "\" was missing");
[email protected]37be4cfa2014-03-20 05:39:3739}
40
41Status Status::ErrorJwkPropertyWrongType(const std::string& property,
42 const std::string& expected_type) {
[email protected]c5039362014-04-28 19:10:3443 return Status(
44 blink::WebCryptoErrorTypeData,
45 "The JWK property \"" + property + "\" must be a " + expected_type);
[email protected]37be4cfa2014-03-20 05:39:3746}
47
48Status Status::ErrorJwkBase64Decode(const std::string& property) {
[email protected]c5039362014-04-28 19:10:3449 return Status(
50 blink::WebCryptoErrorTypeData,
51 "The JWK property \"" + property + "\" could not be base64 decoded");
[email protected]37be4cfa2014-03-20 05:39:3752}
53
54Status Status::ErrorJwkExtInconsistent() {
55 return Status(
[email protected]c5039362014-04-28 19:10:3456 blink::WebCryptoErrorTypeData,
[email protected]37be4cfa2014-03-20 05:39:3757 "The \"ext\" property of the JWK dictionary is inconsistent what that "
58 "specified by the Web Crypto call");
59}
60
61Status Status::ErrorJwkUnrecognizedAlgorithm() {
[email protected]c5039362014-04-28 19:10:3462 return Status(blink::WebCryptoErrorTypeData,
63 "The JWK \"alg\" property was not recognized");
[email protected]37be4cfa2014-03-20 05:39:3764}
65
66Status Status::ErrorJwkAlgorithmInconsistent() {
[email protected]c5039362014-04-28 19:10:3467 return Status(blink::WebCryptoErrorTypeData,
68 "The JWK \"alg\" property was inconsistent with that specified "
69 "by the Web Crypto call");
[email protected]37be4cfa2014-03-20 05:39:3770}
71
[email protected]37be4cfa2014-03-20 05:39:3772Status Status::ErrorJwkUnrecognizedUse() {
[email protected]c5039362014-04-28 19:10:3473 return Status(blink::WebCryptoErrorTypeData,
74 "The JWK \"use\" property could not be parsed");
[email protected]37be4cfa2014-03-20 05:39:3775}
76
77Status Status::ErrorJwkUnrecognizedKeyop() {
[email protected]c5039362014-04-28 19:10:3478 return Status(blink::WebCryptoErrorTypeData,
79 "The JWK \"key_ops\" property could not be parsed");
[email protected]37be4cfa2014-03-20 05:39:3780}
81
82Status Status::ErrorJwkUseInconsistent() {
[email protected]c5039362014-04-28 19:10:3483 return Status(blink::WebCryptoErrorTypeData,
84 "The JWK \"use\" property was inconsistent with that specified "
85 "by the Web Crypto call. The JWK usage must be a superset of "
86 "those requested");
[email protected]37be4cfa2014-03-20 05:39:3787}
88
89Status Status::ErrorJwkKeyopsInconsistent() {
[email protected]c5039362014-04-28 19:10:3490 return Status(blink::WebCryptoErrorTypeData,
91 "The JWK \"key_ops\" property was inconsistent with that "
92 "specified by the Web Crypto call. The JWK usage must be a "
93 "superset of those requested");
[email protected]37be4cfa2014-03-20 05:39:3794}
95
96Status Status::ErrorJwkUseAndKeyopsInconsistent() {
[email protected]c5039362014-04-28 19:10:3497 return Status(blink::WebCryptoErrorTypeData,
98 "The JWK \"use\" and \"key_ops\" properties were both found "
99 "but are inconsistent with each other.");
[email protected]37be4cfa2014-03-20 05:39:37100}
101
[email protected]37be4cfa2014-03-20 05:39:37102Status Status::ErrorJwkUnrecognizedKty() {
[email protected]c5039362014-04-28 19:10:34103 return Status(blink::WebCryptoErrorTypeData,
104 "The JWK \"kty\" property was unrecognized");
[email protected]37be4cfa2014-03-20 05:39:37105}
106
107Status Status::ErrorJwkIncorrectKeyLength() {
[email protected]c5039362014-04-28 19:10:34108 return Status(blink::WebCryptoErrorTypeData,
109 "The JWK \"k\" property did not include the right length "
110 "of key data for the given algorithm.");
[email protected]37be4cfa2014-03-20 05:39:37111}
112
[email protected]6f82af22014-05-21 15:26:14113Status Status::ErrorJwkIncompleteOptionalRsaPrivateKey() {
114 return Status(blink::WebCryptoErrorTypeData,
115 "The optional JWK properties p, q, dp, dq, qi must either all "
116 "be provided, or none provided");
117}
118
[email protected]37be4cfa2014-03-20 05:39:37119Status Status::ErrorImportEmptyKeyData() {
[email protected]c5039362014-04-28 19:10:34120 return Status(blink::WebCryptoErrorTypeData, "No key data was provided");
121}
122
123Status Status::ErrorImportAesKeyLength() {
124 return Status(blink::WebCryptoErrorTypeData,
[email protected]c5039362014-04-28 19:10:34125 "AES key data must be 128, 192 or 256 bits");
[email protected]37be4cfa2014-03-20 05:39:37126}
127
128Status Status::ErrorUnexpectedKeyType() {
[email protected]c5039362014-04-28 19:10:34129 return Status(blink::WebCryptoErrorTypeInvalidAccess,
130 "The key is not of the expected type");
[email protected]37be4cfa2014-03-20 05:39:37131}
132
133Status Status::ErrorIncorrectSizeAesCbcIv() {
[email protected]c5039362014-04-28 19:10:34134 return Status(blink::WebCryptoErrorTypeData,
135 "The \"iv\" has an unexpected length -- must be 16 bytes");
[email protected]37be4cfa2014-03-20 05:39:37136}
137
138Status Status::ErrorDataTooLarge() {
[email protected]c5039362014-04-28 19:10:34139 return Status(blink::WebCryptoErrorTypeData,
140 "The provided data is too large");
[email protected]37be4cfa2014-03-20 05:39:37141}
142
143Status Status::ErrorDataTooSmall() {
[email protected]c5039362014-04-28 19:10:34144 return Status(blink::WebCryptoErrorTypeData,
145 "The provided data is too small");
[email protected]37be4cfa2014-03-20 05:39:37146}
147
148Status Status::ErrorUnsupported() {
[email protected]c5039362014-04-28 19:10:34149 return Status(blink::WebCryptoErrorTypeNotSupported,
150 "The requested operation is unsupported");
[email protected]37be4cfa2014-03-20 05:39:37151}
152
153Status Status::ErrorUnexpected() {
[email protected]c5039362014-04-28 19:10:34154 return Status(blink::WebCryptoErrorTypeUnknown,
155 "Something unexpected happened...");
[email protected]37be4cfa2014-03-20 05:39:37156}
157
158Status Status::ErrorInvalidAesGcmTagLength() {
159 return Status(
[email protected]c5039362014-04-28 19:10:34160 blink::WebCryptoErrorTypeData,
[email protected]37be4cfa2014-03-20 05:39:37161 "The tag length is invalid: Must be 32, 64, 96, 104, 112, 120, or 128 "
162 "bits");
163}
164
165Status Status::ErrorInvalidAesKwDataLength() {
[email protected]c5039362014-04-28 19:10:34166 return Status(blink::WebCryptoErrorTypeData,
167 "The AES-KW input data length is invalid: not a multiple of 8 "
168 "bytes");
[email protected]37be4cfa2014-03-20 05:39:37169}
170
171Status Status::ErrorGenerateKeyPublicExponent() {
[email protected]c5039362014-04-28 19:10:34172 return Status(blink::WebCryptoErrorTypeData,
[email protected]c360f832014-06-12 13:21:50173 "The \"publicExponent\" must be either 3 or 65537");
[email protected]37be4cfa2014-03-20 05:39:37174}
175
[email protected]37be4cfa2014-03-20 05:39:37176Status Status::ErrorImportRsaEmptyModulus() {
[email protected]c5039362014-04-28 19:10:34177 return Status(blink::WebCryptoErrorTypeData, "The modulus is empty");
[email protected]37be4cfa2014-03-20 05:39:37178}
179
180Status Status::ErrorGenerateRsaZeroModulus() {
[email protected]c5039362014-04-28 19:10:34181 return Status(blink::WebCryptoErrorTypeData,
182 "The modulus bit length cannot be zero");
[email protected]37be4cfa2014-03-20 05:39:37183}
184
185Status Status::ErrorImportRsaEmptyExponent() {
[email protected]c5039362014-04-28 19:10:34186 return Status(blink::WebCryptoErrorTypeData,
187 "No bytes for the exponent were provided");
[email protected]37be4cfa2014-03-20 05:39:37188}
189
190Status Status::ErrorKeyNotExtractable() {
[email protected]c5039362014-04-28 19:10:34191 return Status(blink::WebCryptoErrorTypeInvalidAccess,
192 "They key is not extractable");
[email protected]37be4cfa2014-03-20 05:39:37193}
194
195Status Status::ErrorGenerateKeyLength() {
[email protected]c5039362014-04-28 19:10:34196 return Status(blink::WebCryptoErrorTypeData,
197 "Invalid key length: it is either zero or not a multiple of 8 "
198 "bits");
[email protected]37be4cfa2014-03-20 05:39:37199}
200
[email protected]9c2e9cf2014-05-23 23:13:47201Status Status::ErrorCreateKeyBadUsages() {
202 return Status(blink::WebCryptoErrorTypeData,
203 "Cannot create a key using the specified key usages.");
204}
205
[email protected]c5039362014-04-28 19:10:34206Status::Status(blink::WebCryptoErrorType error_type,
207 const std::string& error_details_utf8)
208 : type_(TYPE_ERROR),
209 error_type_(error_type),
210 error_details_(error_details_utf8) {
211}
[email protected]37be4cfa2014-03-20 05:39:37212
[email protected]c5039362014-04-28 19:10:34213Status::Status(Type type) : type_(type) {
214}
[email protected]37be4cfa2014-03-20 05:39:37215
216} // namespace webcrypto
217
218} // namespace content