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 #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" | 10 #include "third_party/WebKit/public/platform/WebCrypto.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 namespace webcrypto { | 14 namespace webcrypto { |
15 | 15 |
16 // Status indicates whether an operation completed successfully, or with an | 16 // Status indicates whether an operation completed successfully, or with an |
17 // error. The error is used for verification in unit-tests, as well as for | 17 // error. The error is used for verification in unit-tests, as well as for |
18 // display to the user. | 18 // display to the user. |
19 // | 19 // |
20 // As such, it is important that errors DO NOT reveal any sensitive material | 20 // As such, it is important that errors DO NOT reveal any sensitive material |
21 // (like key bytes). | 21 // (like key bytes). |
22 // | |
23 // Care must be taken with what errors are reported back to Blink when doing | |
24 // compound operations like unwrapping a JWK key. In this case, errors | |
25 // generated by the JWK import are not appropriate to report since the wrapped | |
26 // JWK is not visible to the caller. | |
27 class CONTENT_EXPORT Status { | 22 class CONTENT_EXPORT Status { |
28 public: | 23 public: |
29 Status() : type_(TYPE_ERROR) {} | 24 Status() : type_(TYPE_ERROR) {} |
30 | 25 |
31 // Returns true if the Status represents an error (any one of them). | 26 // Returns true if the Status represents an error (any one of them). |
32 bool IsError() const; | 27 bool IsError() const; |
33 | 28 |
34 // Returns true if the Status represent success. | 29 // Returns true if the Status represent success. |
35 bool IsSuccess() const; | 30 bool IsSuccess() const; |
36 | 31 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // The exponent bytes were empty when importing an RSA public key. | 175 // The exponent bytes were empty when importing an RSA public key. |
181 static Status ErrorImportRsaEmptyExponent(); | 176 static Status ErrorImportRsaEmptyExponent(); |
182 | 177 |
183 // An unextractable key was used by an operation which exports the key data. | 178 // An unextractable key was used by an operation which exports the key data. |
184 static Status ErrorKeyNotExtractable(); | 179 static Status ErrorKeyNotExtractable(); |
185 | 180 |
186 // The key length specified when generating a key was invalid. Either it was | 181 // The key length specified when generating a key was invalid. Either it was |
187 // zero, or it was not a multiple of 8 bits. | 182 // zero, or it was not a multiple of 8 bits. |
188 static Status ErrorGenerateKeyLength(); | 183 static Status ErrorGenerateKeyLength(); |
189 | 184 |
| 185 // Attempted to create a key (either by importKey(), generateKey(), or |
| 186 // unwrapKey()) however the key usages were not applicable for the key type |
| 187 // and algorithm. |
| 188 static Status ErrorCreateKeyBadUsages(); |
| 189 |
190 private: | 190 private: |
191 enum Type { TYPE_ERROR, TYPE_SUCCESS }; | 191 enum Type { TYPE_ERROR, TYPE_SUCCESS }; |
192 | 192 |
193 // Constructs an error with the specified error type and message. | 193 // Constructs an error with the specified error type and message. |
194 Status(blink::WebCryptoErrorType error_type, | 194 Status(blink::WebCryptoErrorType error_type, |
195 const std::string& error_details_utf8); | 195 const std::string& error_details_utf8); |
196 | 196 |
197 // Constructs a success or error without any details. | 197 // Constructs a success or error without any details. |
198 explicit Status(Type type); | 198 explicit Status(Type type); |
199 | 199 |
200 Type type_; | 200 Type type_; |
201 blink::WebCryptoErrorType error_type_; | 201 blink::WebCryptoErrorType error_type_; |
202 std::string error_details_; | 202 std::string error_details_; |
203 }; | 203 }; |
204 | 204 |
205 } // namespace webcrypto | 205 } // namespace webcrypto |
206 | 206 |
207 } // namespace content | 207 } // namespace content |
208 | 208 |
209 #endif // CONTENT_CHILD_WEBCRYPTO_STATUS_H_ | 209 #endif // CONTENT_CHILD_WEBCRYPTO_STATUS_H_ |
OLD | NEW |