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

Side by Side Diff: content/renderer/webcrypto/webcrypto_util.cc

Issue 145083006: [webcrypto] Add error messages for failed operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Check the Status in unittests Created 6 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/webcrypto/webcrypto_util.h" 5 #include "content/renderer/webcrypto/webcrypto_util.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" 9 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
11 11
12 namespace content { 12 namespace content {
13 13
14 namespace webcrypto { 14 namespace webcrypto {
15 15
16 namespace { 16 bool Status::IsError() const {
17 return error_details_;
18 }
17 19
18 } // namespace 20 bool Status::IsSuccess() const {
21 return !IsError();
22 }
23
24 std::string Status::ToString() const {
25 return IsSuccess() ? "Success" : std::string(error_details_);
26 }
27
28 Status Status::Success() {
29 return Status(NULL);
30 }
31
32 Status Status::Error() {
33 return Status("");
34 }
35
36 Status Status::ErrorEmptyKeyData() {
37 return Status("No key data was provided");
38 }
39
40 Status Status::ErrorEmptyData() {
41 return Status("No data was provided");
42 }
43
44 Status Status::ErrorEmptySignatureData() {
45 return Status("No signature data was provided");
46 }
47
48 Status Status::ErrorUnexpectedKeyType() {
49 return Status("The key is not of the expected type");
50 }
51
52 Status Status::ErrorJwkNotDictionary() {
53 return Status("JWK input could not be parsed to a JSON dictionary");
54 }
55
56 Status Status::ErrorJwkMissingKty() {
57 return Status("JWK dictionary is missing \"kty\" property or it is not a "
58 "string");
59 }
60
61 Status Status::ErrorJwkExtractableInconsistent() {
62 return Status("The \"extractable\" property of the JWK dictionary is "
63 "inconsistent what that specified by the Web Crypto call");
64 }
65
66 Status Status::ErrorJwkUnrecognizedAlgorithm() {
67 return Status("The JWK \"alg\" property was not recognized");
68 }
69
70 Status Status::ErrorJwkAlgorithmInconsistent() {
71 return Status("The JWK \"alg\" property was inconsistent with that specified "
72 "by the Web Crypto call");
73 }
74
75 Status Status::ErrorJwkAlgorithmMissing() {
76 return Status("The JWK optional \"alg\" property is missing or not a string, "
77 "and one wasn't specified by the Web Crypto call");
78 }
79
80 Status Status::ErrorJwkUnrecognizedUsage() {
81 return Status("The JWK \"use\" property could not be parsed");
82 }
83
84 Status Status::ErrorJwkUsageInconsistent() {
85 return Status("The JWK \"use\" property was inconsistent with that specified "
86 "by the Web Crypto call. The JWK usage must be a superset of "
87 "those requested");
88 }
89
90 Status Status::ErrorJwkDecodeK() {
91 return Status("Could not extract required base64 encoded property \"k\"");
92 }
93
94 Status Status::ErrorJwkDecodeN() {
95 return Status("Could not extract required base64 encoded property \"n\"");
96 }
97
98 Status Status::ErrorJwkDecodeE() {
99 return Status("Could not extract required base64 encoded property \"e\"");
100 }
101
102 Status Status::ErrorJwkRsaPrivateKeyUnsupported() {
103 return Status("JWK RSA key contained \"d\" property: Private key import is "
104 "not yet supported");
105 }
106
107 Status Status::ErrorJwkUnrecognizedKty() {
108 return Status("The JWK \"kty\" property was unrecognized");
109 }
110
111 Status Status::ErrorIncorrectSizedIv() {
112 return Status("The \"iv\" has an unexpected length");
113 }
114
115 Status Status::ErrorDataTooBig() {
116 return Status("The provided data is too large");
117 }
118
119 Status Status::ErrorUnsupported() {
120 return Status("The requested operation is unsupported");
121 }
122
123 Status Status::ErrorUnexpected() {
124 return Status("Something unexpected happened...");
125 }
126
127 Status Status::ErrorInvalidAesGcmTagLength() {
128 return Status("The tag length is invalid: either too large or not a multiple "
129 "of 8 bits");
130 }
131
132 Status Status::ErrorPublicExponent() {
133 return Status("The \"publicExponent\" is either empty, zero, or too large");
134 }
135
136 Status Status::ErrorMissingAlgorithmRawKey() {
137 return Status("The key's algorithm must be specified when importing "
138 "raw-formatted key.");
139 }
140
141 Status Status::ErrorEmptyModulus() {
142 return Status("The modulus is empty");
143 }
144
145 Status Status::ErrorEmptyExponent() {
146 return Status("No bytes for the exponent were provided");
147 }
148
149 Status Status::ErrorKeyNotExtractable() {
150 return Status("They key is not extractable");
151 }
152
153 Status Status::ErrorKeyLength() {
154 return Status("Invalid key length: it is either zero or not a multiple of 8 "
155 "bits");
156 }
157
158 Status::Status(const char* error_details_utf8)
159 : error_details_(error_details_utf8) {
160 }
19 161
20 const uint8* Uint8VectorStart(const std::vector<uint8>& data) { 162 const uint8* Uint8VectorStart(const std::vector<uint8>& data) {
21 if (data.empty()) 163 if (data.empty())
22 return NULL; 164 return NULL;
23 return &data[0]; 165 return &data[0];
24 } 166 }
25 167
26 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned new_size) { 168 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned new_size) {
27 DCHECK_LE(new_size, buffer->byteLength()); 169 DCHECK_LE(new_size, buffer->byteLength());
28 170
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return 128; 317 return 128;
176 default: 318 default:
177 NOTREACHED(); 319 NOTREACHED();
178 return 0; 320 return 0;
179 } 321 }
180 } 322 }
181 323
182 } // namespace webcrypto 324 } // namespace webcrypto
183 325
184 } // namespace content 326 } // namespace content
OLDNEW
« content/renderer/webcrypto/webcrypto_util.h ('K') | « content/renderer/webcrypto/webcrypto_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698