OLD | NEW |
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_ != NULL; |
| 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::ErrorJwkNotDictionary() { |
| 37 return Status("JWK input could not be parsed to a JSON dictionary"); |
| 38 } |
| 39 |
| 40 Status Status::ErrorJwkMissingKty() { |
| 41 return Status("JWK dictionary is missing \"kty\" property or it is not a " |
| 42 "string"); |
| 43 } |
| 44 |
| 45 Status Status::ErrorJwkExtractableInconsistent() { |
| 46 return Status("The \"extractable\" property of the JWK dictionary is " |
| 47 "inconsistent what that specified by the Web Crypto call"); |
| 48 } |
| 49 |
| 50 Status Status::ErrorJwkUnrecognizedAlgorithm() { |
| 51 return Status("The JWK \"alg\" property was not recognized"); |
| 52 } |
| 53 |
| 54 Status Status::ErrorJwkAlgorithmInconsistent() { |
| 55 return Status("The JWK \"alg\" property was inconsistent with that specified " |
| 56 "by the Web Crypto call"); |
| 57 } |
| 58 |
| 59 Status Status::ErrorJwkAlgorithmMissing() { |
| 60 return Status("The JWK optional \"alg\" property is missing or not a string, " |
| 61 "and one wasn't specified by the Web Crypto call"); |
| 62 } |
| 63 |
| 64 Status Status::ErrorJwkUnrecognizedUsage() { |
| 65 return Status("The JWK \"use\" property could not be parsed"); |
| 66 } |
| 67 |
| 68 Status Status::ErrorJwkUsageInconsistent() { |
| 69 return Status("The JWK \"use\" property was inconsistent with that specified " |
| 70 "by the Web Crypto call. The JWK usage must be a superset of " |
| 71 "those requested"); |
| 72 } |
| 73 |
| 74 Status Status::ErrorJwkDecodeK() { |
| 75 return Status("Could not extract required base64 encoded property \"k\""); |
| 76 } |
| 77 |
| 78 Status Status::ErrorJwkDecodeN() { |
| 79 return Status("Could not extract required base64 encoded property \"n\""); |
| 80 } |
| 81 |
| 82 Status Status::ErrorJwkDecodeE() { |
| 83 return Status("Could not extract required base64 encoded property \"e\""); |
| 84 } |
| 85 |
| 86 Status Status::ErrorJwkRsaPrivateKeyUnsupported() { |
| 87 return Status("JWK RSA key contained \"d\" property: Private key import is " |
| 88 "not yet supported"); |
| 89 } |
| 90 |
| 91 Status Status::ErrorJwkUnrecognizedKty() { |
| 92 return Status("The JWK \"kty\" property was unrecognized"); |
| 93 } |
| 94 |
| 95 Status Status::ErrorImportEmptyKeyData() { |
| 96 return Status("No key data was provided"); |
| 97 } |
| 98 |
| 99 Status Status::ErrorUnexpectedKeyType() { |
| 100 return Status("The key is not of the expected type"); |
| 101 } |
| 102 |
| 103 Status Status::ErrorIncorrectSizedAesCbcIv() { |
| 104 return Status("The \"iv\" has an unexpected length -- must be 16 bytes"); |
| 105 } |
| 106 |
| 107 Status Status::ErrorDataTooBig() { |
| 108 return Status("The provided data is too large"); |
| 109 } |
| 110 |
| 111 Status Status::ErrorUnsupported() { |
| 112 return Status("The requested operation is unsupported"); |
| 113 } |
| 114 |
| 115 Status Status::ErrorUnexpected() { |
| 116 return Status("Something unexpected happened..."); |
| 117 } |
| 118 |
| 119 Status Status::ErrorInvalidAesGcmTagLength() { |
| 120 return Status("The tag length is invalid: either too large or not a multiple " |
| 121 "of 8 bits"); |
| 122 } |
| 123 |
| 124 Status Status::ErrorGenerateKeyPublicExponent() { |
| 125 return Status("The \"publicExponent\" is either empty, zero, or too large"); |
| 126 } |
| 127 |
| 128 Status Status::ErrorMissingAlgorithmImportRawKey() { |
| 129 return Status("The key's algorithm must be specified when importing " |
| 130 "raw-formatted key."); |
| 131 } |
| 132 |
| 133 Status Status::ErrorImportRsaEmptyModulus() { |
| 134 return Status("The modulus is empty"); |
| 135 } |
| 136 |
| 137 Status Status::ErrorGenerateRsaZeroModulus() { |
| 138 return Status("The modulus bit length cannot be zero"); |
| 139 } |
| 140 |
| 141 Status Status::ErrorImportRsaEmptyExponent() { |
| 142 return Status("No bytes for the exponent were provided"); |
| 143 } |
| 144 |
| 145 Status Status::ErrorKeyNotExtractable() { |
| 146 return Status("They key is not extractable"); |
| 147 } |
| 148 |
| 149 Status Status::ErrorGenerateKeyLength() { |
| 150 return Status("Invalid key length: it is either zero or not a multiple of 8 " |
| 151 "bits"); |
| 152 } |
| 153 |
| 154 Status::Status(const char* error_details_utf8) |
| 155 : error_details_(error_details_utf8) { |
| 156 } |
19 | 157 |
20 const uint8* Uint8VectorStart(const std::vector<uint8>& data) { | 158 const uint8* Uint8VectorStart(const std::vector<uint8>& data) { |
21 if (data.empty()) | 159 if (data.empty()) |
22 return NULL; | 160 return NULL; |
23 return &data[0]; | 161 return &data[0]; |
24 } | 162 } |
25 | 163 |
26 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned new_size) { | 164 void ShrinkBuffer(blink::WebArrayBuffer* buffer, unsigned new_size) { |
27 DCHECK_LE(new_size, buffer->byteLength()); | 165 DCHECK_LE(new_size, buffer->byteLength()); |
28 | 166 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 return 128; | 313 return 128; |
176 default: | 314 default: |
177 NOTREACHED(); | 315 NOTREACHED(); |
178 return 0; | 316 return 0; |
179 } | 317 } |
180 } | 318 } |
181 | 319 |
182 } // namespace webcrypto | 320 } // namespace webcrypto |
183 | 321 |
184 } // namespace content | 322 } // namespace content |
OLD | NEW |