Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: content/child/webcrypto/status.cc

Issue 243433006: [webcrypto] Set the error type for failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 namespace content { 7 namespace content {
8 8
9 namespace webcrypto { 9 namespace webcrypto {
10 10
11 bool Status::IsError() const { return type_ == TYPE_ERROR; } 11 bool Status::IsError() const {
12 12 return type_ == TYPE_ERROR;
13 bool Status::IsSuccess() const { return type_ == TYPE_SUCCESS; } 13 }
14 14
15 bool Status::HasErrorDetails() const { return !error_details_.empty(); } 15 bool Status::IsSuccess() const {
16 return type_ == TYPE_SUCCESS;
17 }
18
19 // TODO(eroman): Delete
20 bool Status::HasErrorDetails() const {
21 return !error_details_.empty();
22 }
16 23
17 std::string Status::ToString() const { 24 std::string Status::ToString() const {
18 return IsSuccess() ? "Success" : error_details_; 25 return IsSuccess() ? "Success" : error_details_;
19 } 26 }
20 27
21 Status Status::Success() { return Status(TYPE_SUCCESS); } 28 Status Status::Success() {
22 29 return Status(TYPE_SUCCESS);
23 Status Status::Error() { return Status(TYPE_ERROR); } 30 }
31
32 Status Status::OperationError() {
33 return Status(blink::WebCryptoErrorTypeOperation, "");
34 }
24 35
25 Status Status::ErrorJwkNotDictionary() { 36 Status Status::ErrorJwkNotDictionary() {
26 return Status("JWK input could not be parsed to a JSON dictionary"); 37 return Status(blink::WebCryptoErrorTypeData,
38 "JWK input could not be parsed to a JSON dictionary");
27 } 39 }
28 40
29 Status Status::ErrorJwkPropertyMissing(const std::string& property) { 41 Status Status::ErrorJwkPropertyMissing(const std::string& property) {
30 return Status("The required JWK property \"" + property + "\" was missing"); 42 return Status(blink::WebCryptoErrorTypeData,
43 "The required JWK property \"" + property + "\" was missing");
31 } 44 }
32 45
33 Status Status::ErrorJwkPropertyWrongType(const std::string& property, 46 Status Status::ErrorJwkPropertyWrongType(const std::string& property,
34 const std::string& expected_type) { 47 const std::string& expected_type) {
35 return Status("The JWK property \"" + property + "\" must be a " + 48 return Status(
36 expected_type); 49 blink::WebCryptoErrorTypeData,
50 "The JWK property \"" + property + "\" must be a " + expected_type);
37 } 51 }
38 52
39 Status Status::ErrorJwkBase64Decode(const std::string& property) { 53 Status Status::ErrorJwkBase64Decode(const std::string& property) {
40 return Status("The JWK property \"" + property + 54 return Status(
41 "\" could not be base64 decoded"); 55 blink::WebCryptoErrorTypeData,
56 "The JWK property \"" + property + "\" could not be base64 decoded");
42 } 57 }
43 58
44 Status Status::ErrorJwkExtInconsistent() { 59 Status Status::ErrorJwkExtInconsistent() {
45 return Status( 60 return Status(
61 blink::WebCryptoErrorTypeData,
46 "The \"ext\" property of the JWK dictionary is inconsistent what that " 62 "The \"ext\" property of the JWK dictionary is inconsistent what that "
47 "specified by the Web Crypto call"); 63 "specified by the Web Crypto call");
48 } 64 }
49 65
50 Status Status::ErrorJwkUnrecognizedAlgorithm() { 66 Status Status::ErrorJwkUnrecognizedAlgorithm() {
51 return Status("The JWK \"alg\" property was not recognized"); 67 return Status(blink::WebCryptoErrorTypeData,
68 "The JWK \"alg\" property was not recognized");
52 } 69 }
53 70
54 Status Status::ErrorJwkAlgorithmInconsistent() { 71 Status Status::ErrorJwkAlgorithmInconsistent() {
55 return Status( 72 return Status(blink::WebCryptoErrorTypeData,
56 "The JWK \"alg\" property was inconsistent with that specified " 73 "The JWK \"alg\" property was inconsistent with that specified "
57 "by the Web Crypto call"); 74 "by the Web Crypto call");
58 } 75 }
59 76
60 Status Status::ErrorJwkUnrecognizedUse() { 77 Status Status::ErrorJwkUnrecognizedUse() {
61 return Status("The JWK \"use\" property could not be parsed"); 78 return Status(blink::WebCryptoErrorTypeData,
79 "The JWK \"use\" property could not be parsed");
62 } 80 }
63 81
64 Status Status::ErrorJwkUnrecognizedKeyop() { 82 Status Status::ErrorJwkUnrecognizedKeyop() {
65 return Status("The JWK \"key_ops\" property could not be parsed"); 83 return Status(blink::WebCryptoErrorTypeData,
84 "The JWK \"key_ops\" property could not be parsed");
66 } 85 }
67 86
68 Status Status::ErrorJwkUseInconsistent() { 87 Status Status::ErrorJwkUseInconsistent() {
69 return Status( 88 return Status(blink::WebCryptoErrorTypeData,
70 "The JWK \"use\" property was inconsistent with that specified " 89 "The JWK \"use\" property was inconsistent with that specified "
71 "by the Web Crypto call. The JWK usage must be a superset of " 90 "by the Web Crypto call. The JWK usage must be a superset of "
72 "those requested"); 91 "those requested");
73 } 92 }
74 93
75 Status Status::ErrorJwkKeyopsInconsistent() { 94 Status Status::ErrorJwkKeyopsInconsistent() {
76 return Status( 95 return Status(blink::WebCryptoErrorTypeData,
77 "The JWK \"key_ops\" property was inconsistent with that " 96 "The JWK \"key_ops\" property was inconsistent with that "
78 "specified by the Web Crypto call. The JWK usage must be a " 97 "specified by the Web Crypto call. The JWK usage must be a "
79 "superset of those requested"); 98 "superset of those requested");
80 } 99 }
81 100
82 Status Status::ErrorJwkUseAndKeyopsInconsistent() { 101 Status Status::ErrorJwkUseAndKeyopsInconsistent() {
83 return Status( 102 return Status(blink::WebCryptoErrorTypeData,
84 "The JWK \"use\" and \"key_ops\" properties were both found " 103 "The JWK \"use\" and \"key_ops\" properties were both found "
85 "but are inconsistent with each other."); 104 "but are inconsistent with each other.");
86 } 105 }
87 106
88 Status Status::ErrorJwkRsaPrivateKeyUnsupported() { 107 Status Status::ErrorJwkRsaPrivateKeyUnsupported() {
89 return Status( 108 return Status(blink::WebCryptoErrorTypeNotSupported,
90 "JWK RSA key contained \"d\" property: Private key import is " 109 "JWK RSA key contained \"d\" property: Private key import is "
91 "not yet supported"); 110 "not yet supported");
92 } 111 }
93 112
94 Status Status::ErrorJwkUnrecognizedKty() { 113 Status Status::ErrorJwkUnrecognizedKty() {
95 return Status("The JWK \"kty\" property was unrecognized"); 114 return Status(blink::WebCryptoErrorTypeData,
115 "The JWK \"kty\" property was unrecognized");
96 } 116 }
97 117
98 Status Status::ErrorJwkIncorrectKeyLength() { 118 Status Status::ErrorJwkIncorrectKeyLength() {
99 return Status( 119 return Status(blink::WebCryptoErrorTypeData,
100 "The JWK \"k\" property did not include the right length " 120 "The JWK \"k\" property did not include the right length "
101 "of key data for the given algorithm."); 121 "of key data for the given algorithm.");
102 } 122 }
103 123
104 Status Status::ErrorImportEmptyKeyData() { 124 Status Status::ErrorImportEmptyKeyData() {
105 return Status("No key data was provided"); 125 return Status(blink::WebCryptoErrorTypeData, "No key data was provided");
126 }
127
128 Status Status::ErrorImportAesKeyLength() {
129 return Status(blink::WebCryptoErrorTypeData,
130 "AES key data must be 128, 192 or 256 bits");
106 } 131 }
107 132
108 Status Status::ErrorUnexpectedKeyType() { 133 Status Status::ErrorUnexpectedKeyType() {
109 return Status("The key is not of the expected type"); 134 return Status(blink::WebCryptoErrorTypeInvalidAccess,
135 "The key is not of the expected type");
110 } 136 }
111 137
112 Status Status::ErrorIncorrectSizeAesCbcIv() { 138 Status Status::ErrorIncorrectSizeAesCbcIv() {
113 return Status("The \"iv\" has an unexpected length -- must be 16 bytes"); 139 return Status(blink::WebCryptoErrorTypeData,
140 "The \"iv\" has an unexpected length -- must be 16 bytes");
114 } 141 }
115 142
116 Status Status::ErrorDataTooLarge() { 143 Status Status::ErrorDataTooLarge() {
117 return Status("The provided data is too large"); 144 return Status(blink::WebCryptoErrorTypeData,
145 "The provided data is too large");
118 } 146 }
119 147
120 Status Status::ErrorDataTooSmall() { 148 Status Status::ErrorDataTooSmall() {
121 return Status("The provided data is too small"); 149 return Status(blink::WebCryptoErrorTypeData,
150 "The provided data is too small");
122 } 151 }
123 152
124 Status Status::ErrorUnsupported() { 153 Status Status::ErrorUnsupported() {
125 return Status("The requested operation is unsupported"); 154 return Status(blink::WebCryptoErrorTypeNotSupported,
155 "The requested operation is unsupported");
126 } 156 }
127 157
128 Status Status::ErrorUnexpected() { 158 Status Status::ErrorUnexpected() {
129 return Status("Something unexpected happened..."); 159 return Status(blink::WebCryptoErrorTypeUnknown,
160 "Something unexpected happened...");
130 } 161 }
131 162
132 Status Status::ErrorInvalidAesGcmTagLength() { 163 Status Status::ErrorInvalidAesGcmTagLength() {
133 return Status( 164 return Status(
165 blink::WebCryptoErrorTypeData,
134 "The tag length is invalid: Must be 32, 64, 96, 104, 112, 120, or 128 " 166 "The tag length is invalid: Must be 32, 64, 96, 104, 112, 120, or 128 "
135 "bits"); 167 "bits");
136 } 168 }
137 169
138 Status Status::ErrorInvalidAesKwDataLength() { 170 Status Status::ErrorInvalidAesKwDataLength() {
139 return Status( 171 return Status(blink::WebCryptoErrorTypeData,
140 "The AES-KW input data length is invalid: not a multiple of 8 " 172 "The AES-KW input data length is invalid: not a multiple of 8 "
141 "bytes"); 173 "bytes");
142 } 174 }
143 175
144 Status Status::ErrorGenerateKeyPublicExponent() { 176 Status Status::ErrorGenerateKeyPublicExponent() {
145 return Status("The \"publicExponent\" is either empty, zero, or too large"); 177 return Status(blink::WebCryptoErrorTypeData,
178 "The \"publicExponent\" is either empty, zero, or too large");
146 } 179 }
147 180
148 Status Status::ErrorImportRsaEmptyModulus() { 181 Status Status::ErrorImportRsaEmptyModulus() {
149 return Status("The modulus is empty"); 182 return Status(blink::WebCryptoErrorTypeData, "The modulus is empty");
150 } 183 }
151 184
152 Status Status::ErrorGenerateRsaZeroModulus() { 185 Status Status::ErrorGenerateRsaZeroModulus() {
153 return Status("The modulus bit length cannot be zero"); 186 return Status(blink::WebCryptoErrorTypeData,
187 "The modulus bit length cannot be zero");
154 } 188 }
155 189
156 Status Status::ErrorImportRsaEmptyExponent() { 190 Status Status::ErrorImportRsaEmptyExponent() {
157 return Status("No bytes for the exponent were provided"); 191 return Status(blink::WebCryptoErrorTypeData,
192 "No bytes for the exponent were provided");
158 } 193 }
159 194
160 Status Status::ErrorKeyNotExtractable() { 195 Status Status::ErrorKeyNotExtractable() {
161 return Status("They key is not extractable"); 196 return Status(blink::WebCryptoErrorTypeInvalidAccess,
197 "They key is not extractable");
162 } 198 }
163 199
164 Status Status::ErrorGenerateKeyLength() { 200 Status Status::ErrorGenerateKeyLength() {
165 return Status( 201 return Status(blink::WebCryptoErrorTypeData,
166 "Invalid key length: it is either zero or not a multiple of 8 " 202 "Invalid key length: it is either zero or not a multiple of 8 "
167 "bits"); 203 "bits");
168 } 204 }
169 205
170 Status::Status(const std::string& error_details_utf8) 206 Status::Status(blink::WebCryptoErrorType error_type,
171 : type_(TYPE_ERROR), error_details_(error_details_utf8) {} 207 const std::string& error_details_utf8)
172 208 : type_(TYPE_ERROR),
173 Status::Status(Type type) : type_(type) {} 209 error_type_(error_type),
174 210 error_details_(error_details_utf8) {
211 }
212
213 Status::Status(Type type) : type_(type) {
214 }
175 215
176 } // namespace webcrypto 216 } // namespace webcrypto
177 217
178 } // namespace content 218 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698