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

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

Issue 243433006: [webcrypto] Set the error type for failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and try to fix android build... 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
« no previous file with comments | « content/child/webcrypto/shared_crypto_unittest.cc ('k') | content/child/webcrypto/status.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef CONTENT_CHILD_WEBCRYPTO_STATUS_H_ 5 #ifndef CONTENT_CHILD_WEBCRYPTO_STATUS_H_
6 #define CONTENT_CHILD_WEBCRYPTO_STATUS_H_ 6 #define CONTENT_CHILD_WEBCRYPTO_STATUS_H_
7 7
8 #include <string> 8 #include <string>
9 #include "content/common/content_export.h" 9 #include "content/common/content_export.h"
10 #include "third_party/WebKit/public/platform/WebCrypto.h"
11
12 #if !defined(WEBCRYPTO_HAS_ERROR_TYPE)
13
14 // TODO(eroman): Delete once Blink changes have rolled into Chromium.
15 namespace blink {
16
17 enum WebCryptoErrorType {
18 WebCryptoErrorTypeType,
19 WebCryptoErrorTypeNotSupported,
20 WebCryptoErrorTypeSyntax,
21 WebCryptoErrorTypeInvalidState,
22 WebCryptoErrorTypeInvalidAccess,
23 WebCryptoErrorTypeUnknown,
24 WebCryptoErrorTypeData,
25 WebCryptoErrorTypeOperation,
26 };
27
28 } // namespace blink
29
30 #endif
10 31
11 namespace content { 32 namespace content {
12 33
13 namespace webcrypto { 34 namespace webcrypto {
14 35
15 // Status indicates whether an operation completed successfully, or with an 36 // Status indicates whether an operation completed successfully, or with an
16 // error. The error is used for verification in unit-tests, as well as for 37 // error. The error is used for verification in unit-tests, as well as for
17 // display to the user. 38 // display to the user.
18 // 39 //
19 // As such, it is important that errors DO NOT reveal any sensitive material 40 // As such, it is important that errors DO NOT reveal any sensitive material
20 // (like key bytes). 41 // (like key bytes).
21 // 42 //
22 // Care must be taken with what errors are reported back to blink when doing 43 // Care must be taken with what errors are reported back to blink when doing
23 // compound operations like unwrapping a JWK key. In this case, errors 44 // compound operations like unwrapping a JWK key. In this case, errors
24 // generated by the JWK import are not appropriate to report since the wrapped 45 // generated by the JWK import are not appropriate to report since the wrapped
25 // JWK is not visible to the caller. 46 // JWK is not visible to the caller.
26 class CONTENT_EXPORT Status { 47 class CONTENT_EXPORT Status {
27 public: 48 public:
28 // Returns true if the Status represents an error (any one of them). 49 // Returns true if the Status represents an error (any one of them).
29 bool IsError() const; 50 bool IsError() const;
30 51
31 // Returns true if the Status represent success. 52 // Returns true if the Status represent success.
32 bool IsSuccess() const; 53 bool IsSuccess() const;
33 54
34 // Returns true if the Status contains a non-empty error message. 55 // Returns a UTF-8 error message (non-localized) describing the error.
35 bool HasErrorDetails() const; 56 const std::string& error_details() const { return error_details_; }
36 57
37 // Returns a UTF-8 error message (non-localized) describing the error. This 58 blink::WebCryptoErrorType error_type() const { return error_type_; }
38 // message is intended to be displayed in the dev tools console.
39 std::string ToString() const;
40 59
41 // Constructs a status representing success. 60 // Constructs a status representing success.
42 static Status Success(); 61 static Status Success();
43 62
44 // Constructs a status representing a generic error. It contains no extra 63 // Constructs a status representing a generic operation error. It contains no
45 // details. 64 // extra details.
46 static Status Error(); 65 static Status OperationError();
66
67 // Constructs a status representing a generic data error. It contains no
68 // extra details.
69 static Status DataError();
47 70
48 // ------------------------------------ 71 // ------------------------------------
49 // Errors when importing a JWK formatted key 72 // Errors when importing a JWK formatted key
50 // ------------------------------------ 73 // ------------------------------------
51 74
52 // The key bytes could not parsed as JSON dictionary. This either 75 // The key bytes could not parsed as JSON dictionary. This either
53 // means there was a parsing error, or the JSON object was not 76 // means there was a parsing error, or the JSON object was not
54 // convertable to a dictionary. 77 // convertable to a dictionary.
55 static Status ErrorJwkNotDictionary(); 78 static Status ErrorJwkNotDictionary();
56 79
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 135
113 // ------------------------------------ 136 // ------------------------------------
114 // Other errors 137 // Other errors
115 // ------------------------------------ 138 // ------------------------------------
116 139
117 // No key data was provided when importing an spki, pkcs8, or jwk formatted 140 // No key data was provided when importing an spki, pkcs8, or jwk formatted
118 // key. This does not apply to raw format, since it is possible to have empty 141 // key. This does not apply to raw format, since it is possible to have empty
119 // key data there. 142 // key data there.
120 static Status ErrorImportEmptyKeyData(); 143 static Status ErrorImportEmptyKeyData();
121 144
145 // The key data buffer provided for importKey() is an incorrect length for
146 // AES.
147 static Status ErrorImportAesKeyLength();
148
122 // The wrong key was used for the operation. For instance, a public key was 149 // The wrong key was used for the operation. For instance, a public key was
123 // used to verify a RsaSsaPkcs1v1_5 signature, or tried exporting a private 150 // used to verify a RsaSsaPkcs1v1_5 signature, or tried exporting a private
124 // key using spki format. 151 // key using spki format.
125 static Status ErrorUnexpectedKeyType(); 152 static Status ErrorUnexpectedKeyType();
126 153
127 // When doing an AES-CBC encryption/decryption, the "iv" parameter was not 16 154 // When doing an AES-CBC encryption/decryption, the "iv" parameter was not 16
128 // bytes. 155 // bytes.
129 static Status ErrorIncorrectSizeAesCbcIv(); 156 static Status ErrorIncorrectSizeAesCbcIv();
130 157
131 // The data provided to an encrypt/decrypt/sign/verify operation was too 158 // The data provided to an encrypt/decrypt/sign/verify operation was too
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // An unextractable key was used by an operation which exports the key data. 202 // An unextractable key was used by an operation which exports the key data.
176 static Status ErrorKeyNotExtractable(); 203 static Status ErrorKeyNotExtractable();
177 204
178 // The key length specified when generating a key was invalid. Either it was 205 // The key length specified when generating a key was invalid. Either it was
179 // zero, or it was not a multiple of 8 bits. 206 // zero, or it was not a multiple of 8 bits.
180 static Status ErrorGenerateKeyLength(); 207 static Status ErrorGenerateKeyLength();
181 208
182 private: 209 private:
183 enum Type { TYPE_ERROR, TYPE_SUCCESS }; 210 enum Type { TYPE_ERROR, TYPE_SUCCESS };
184 211
185 // Constructs an error with the specified message. 212 // Constructs an error with the specified error type and message.
186 explicit Status(const std::string& error_details_utf8); 213 Status(blink::WebCryptoErrorType error_type,
214 const std::string& error_details_utf8);
187 215
188 // Constructs a success or error without any details. 216 // Constructs a success or error without any details.
189 explicit Status(Type type); 217 explicit Status(Type type);
190 218
191 Type type_; 219 Type type_;
220 blink::WebCryptoErrorType error_type_;
192 std::string error_details_; 221 std::string error_details_;
193 }; 222 };
194 223
195 } // namespace webcrypto 224 } // namespace webcrypto
196 225
197 } // namespace content 226 } // namespace content
198 227
199 #endif // CONTENT_CHILD_WEBCRYPTO_STATUS_H_ 228 #endif // CONTENT_CHILD_WEBCRYPTO_STATUS_H_
OLDNEW
« no previous file with comments | « content/child/webcrypto/shared_crypto_unittest.cc ('k') | content/child/webcrypto/status.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698