[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/child/webcrypto/status.h" |
| 6 | |
eroman | b2ead6d | 2014-11-14 02:26:14 | [diff] [blame] | 7 | #include "base/format_macros.h" |
| 8 | #include "base/strings/stringprintf.h" |
| 9 | |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 10 | namespace content { |
| 11 | |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 12 | namespace webcrypto { |
| 13 | |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 14 | bool Status::IsError() const { |
| 15 | return type_ == TYPE_ERROR; |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 16 | } |
| 17 | |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 18 | bool Status::IsSuccess() const { |
| 19 | return type_ == TYPE_SUCCESS; |
| 20 | } |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 21 | |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 22 | Status Status::Success() { |
| 23 | return Status(TYPE_SUCCESS); |
| 24 | } |
| 25 | |
| 26 | Status Status::OperationError() { |
| 27 | return Status(blink::WebCryptoErrorTypeOperation, ""); |
| 28 | } |
| 29 | |
| 30 | Status Status::DataError() { |
| 31 | return Status(blink::WebCryptoErrorTypeData, ""); |
| 32 | } |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 33 | |
| 34 | Status Status::ErrorJwkNotDictionary() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 35 | return Status(blink::WebCryptoErrorTypeData, |
| 36 | "JWK input could not be parsed to a JSON dictionary"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 37 | } |
| 38 | |
eroman | 398e7e1 | 2014-11-08 03:05:10 | [diff] [blame] | 39 | Status Status::ErrorJwkMemberMissing(const std::string& member_name) { |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 40 | return Status(blink::WebCryptoErrorTypeData, |
| 41 | "The required JWK member \"" + member_name + "\" was missing"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 42 | } |
| 43 | |
eroman | 398e7e1 | 2014-11-08 03:05:10 | [diff] [blame] | 44 | Status Status::ErrorJwkMemberWrongType(const std::string& member_name, |
| 45 | const std::string& expected_type) { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 46 | return Status( |
| 47 | blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 48 | "The JWK member \"" + member_name + "\" must be a " + expected_type); |
eroman | 398e7e1 | 2014-11-08 03:05:10 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | Status Status::ErrorJwkBase64Decode(const std::string& member_name) { |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 52 | return Status(blink::WebCryptoErrorTypeData, |
| 53 | "The JWK member \"" + member_name + |
| 54 | "\" could not be base64url decoded or contained padding"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | Status Status::ErrorJwkExtInconsistent() { |
| 58 | return Status( |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 59 | blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 60 | "The \"ext\" member of the JWK dictionary is inconsistent what that " |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 61 | "specified by the Web Crypto call"); |
| 62 | } |
| 63 | |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 64 | Status Status::ErrorJwkAlgorithmInconsistent() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 65 | return Status(blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 66 | "The JWK \"alg\" member was inconsistent with that specified " |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 67 | "by the Web Crypto call"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 70 | Status Status::ErrorJwkUnrecognizedUse() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 71 | return Status(blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 72 | "The JWK \"use\" member could not be parsed"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | Status Status::ErrorJwkUnrecognizedKeyop() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 76 | return Status(blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 77 | "The JWK \"key_ops\" member could not be parsed"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | Status Status::ErrorJwkUseInconsistent() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 81 | return Status(blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 82 | "The JWK \"use\" member was inconsistent with that specified " |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 83 | "by the Web Crypto call. The JWK usage must be a superset of " |
| 84 | "those requested"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | Status Status::ErrorJwkKeyopsInconsistent() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 88 | return Status(blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 89 | "The JWK \"key_ops\" member was inconsistent with that " |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 90 | "specified by the Web Crypto call. The JWK usage must be a " |
| 91 | "superset of those requested"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | Status Status::ErrorJwkUseAndKeyopsInconsistent() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 95 | return Status(blink::WebCryptoErrorTypeData, |
| 96 | "The JWK \"use\" and \"key_ops\" properties were both found " |
| 97 | "but are inconsistent with each other."); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 98 | } |
| 99 | |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 100 | Status Status::ErrorJwkUnexpectedKty(const std::string& expected) { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 101 | return Status(blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 102 | "The JWK \"kty\" member was not \"" + expected + "\""); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | Status Status::ErrorJwkIncorrectKeyLength() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 106 | return Status(blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 107 | "The JWK \"k\" member did not include the right length " |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 108 | "of key data for the given algorithm."); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 109 | } |
| 110 | |
eroman | 398e7e1 | 2014-11-08 03:05:10 | [diff] [blame] | 111 | Status Status::ErrorJwkEmptyBigInteger(const std::string& member_name) { |
[email protected] | 6f82af2 | 2014-05-21 15:26:14 | [diff] [blame] | 112 | return Status(blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 113 | "The JWK \"" + member_name + "\" member was empty."); |
[email protected] | 31130d6c | 2014-07-26 19:59:14 | [diff] [blame] | 114 | } |
| 115 | |
eroman | 398e7e1 | 2014-11-08 03:05:10 | [diff] [blame] | 116 | Status Status::ErrorJwkBigIntegerHasLeadingZero( |
| 117 | const std::string& member_name) { |
[email protected] | 31130d6c | 2014-07-26 19:59:14 | [diff] [blame] | 118 | return Status( |
| 119 | blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 120 | "The JWK \"" + member_name + "\" member contained a leading zero."); |
[email protected] | 6f82af2 | 2014-05-21 15:26:14 | [diff] [blame] | 121 | } |
| 122 | |
eroman | ca92d1e | 2014-10-28 01:15:18 | [diff] [blame] | 123 | Status Status::ErrorJwkDuplicateKeyOps() { |
| 124 | return Status(blink::WebCryptoErrorTypeData, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 125 | "The \"key_ops\" member of the JWK dictionary contains " |
eroman | ca92d1e | 2014-10-28 01:15:18 | [diff] [blame] | 126 | "duplicate usages."); |
| 127 | } |
| 128 | |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 129 | Status Status::ErrorImportEmptyKeyData() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 130 | return Status(blink::WebCryptoErrorTypeData, "No key data was provided"); |
| 131 | } |
| 132 | |
[email protected] | 38409aec | 2014-07-19 00:54:51 | [diff] [blame] | 133 | Status Status::ErrorUnsupportedImportKeyFormat() { |
| 134 | return Status(blink::WebCryptoErrorTypeNotSupported, |
| 135 | "Unsupported import key format for algorithm"); |
| 136 | } |
| 137 | |
| 138 | Status Status::ErrorUnsupportedExportKeyFormat() { |
| 139 | return Status(blink::WebCryptoErrorTypeNotSupported, |
| 140 | "Unsupported export key format for algorithm"); |
| 141 | } |
| 142 | |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 143 | Status Status::ErrorImportAesKeyLength() { |
| 144 | return Status(blink::WebCryptoErrorTypeData, |
eroman | be884dce | 2014-11-26 21:23:29 | [diff] [blame] | 145 | "AES key data must be 128 or 256 bits"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 146 | } |
| 147 | |
eroman | f93fd5b | 2014-12-11 00:21:06 | [diff] [blame^] | 148 | Status Status::ErrorGetAesKeyLength() { |
| 149 | return Status(blink::WebCryptoErrorTypeOperation, |
| 150 | "AES key length must be 128 or 256 bits"); |
| 151 | } |
| 152 | |
eroman | 9e9ed05 | 2014-11-26 03:00:40 | [diff] [blame] | 153 | Status Status::ErrorGenerateAesKeyLength() { |
| 154 | return Status(blink::WebCryptoErrorTypeOperation, |
| 155 | "AES key length must be 128 or 256 bits"); |
| 156 | } |
| 157 | |
[email protected] | b05ba93 | 2014-06-13 08:49:15 | [diff] [blame] | 158 | Status Status::ErrorAes192BitUnsupported() { |
| 159 | return Status(blink::WebCryptoErrorTypeNotSupported, |
| 160 | "192-bit AES keys are not supported"); |
| 161 | } |
| 162 | |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 163 | Status Status::ErrorUnexpectedKeyType() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 164 | return Status(blink::WebCryptoErrorTypeInvalidAccess, |
| 165 | "The key is not of the expected type"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | Status Status::ErrorIncorrectSizeAesCbcIv() { |
xun.sun | 99cd209 | 2014-12-04 17:41:02 | [diff] [blame] | 169 | return Status(blink::WebCryptoErrorTypeOperation, |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 170 | "The \"iv\" has an unexpected length -- must be 16 bytes"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 171 | } |
| 172 | |
eroman | 4d7a0e0 | 2014-08-27 00:30:33 | [diff] [blame] | 173 | Status Status::ErrorIncorrectSizeAesCtrCounter() { |
xun.sun | 99cd209 | 2014-12-04 17:41:02 | [diff] [blame] | 174 | return Status(blink::WebCryptoErrorTypeOperation, |
eroman | 4d7a0e0 | 2014-08-27 00:30:33 | [diff] [blame] | 175 | "The \"counter\" has an unexpected length -- must be 16 bytes"); |
| 176 | } |
| 177 | |
| 178 | Status Status::ErrorInvalidAesCtrCounterLength() { |
xun.sun | 99cd209 | 2014-12-04 17:41:02 | [diff] [blame] | 179 | return Status(blink::WebCryptoErrorTypeOperation, |
eroman | 8c565ba | 2014-12-10 20:59:06 | [diff] [blame] | 180 | "The \"length\" member must be >= 1 and <= 128"); |
eroman | 4d7a0e0 | 2014-08-27 00:30:33 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | Status Status::ErrorAesCtrInputTooLongCounterRepeated() { |
| 184 | return Status(blink::WebCryptoErrorTypeData, |
| 185 | "The input is too large for the counter length."); |
| 186 | } |
| 187 | |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 188 | Status Status::ErrorDataTooLarge() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 189 | return Status(blink::WebCryptoErrorTypeData, |
| 190 | "The provided data is too large"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | Status Status::ErrorDataTooSmall() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 194 | return Status(blink::WebCryptoErrorTypeData, |
| 195 | "The provided data is too small"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | Status Status::ErrorUnsupported() { |
[email protected] | cb7f3e3 | 2014-06-19 14:41:41 | [diff] [blame] | 199 | return ErrorUnsupported("The requested operation is unsupported"); |
| 200 | } |
| 201 | |
| 202 | Status Status::ErrorUnsupported(const std::string& message) { |
| 203 | return Status(blink::WebCryptoErrorTypeNotSupported, message); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | Status Status::ErrorUnexpected() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 207 | return Status(blink::WebCryptoErrorTypeUnknown, |
| 208 | "Something unexpected happened..."); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | Status Status::ErrorInvalidAesGcmTagLength() { |
| 212 | return Status( |
xun.sun | e573755 | 2014-12-02 23:52:24 | [diff] [blame] | 213 | blink::WebCryptoErrorTypeOperation, |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 214 | "The tag length is invalid: Must be 32, 64, 96, 104, 112, 120, or 128 " |
| 215 | "bits"); |
| 216 | } |
| 217 | |
| 218 | Status Status::ErrorInvalidAesKwDataLength() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 219 | return Status(blink::WebCryptoErrorTypeData, |
| 220 | "The AES-KW input data length is invalid: not a multiple of 8 " |
| 221 | "bytes"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | Status Status::ErrorGenerateKeyPublicExponent() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 225 | return Status(blink::WebCryptoErrorTypeData, |
[email protected] | c360f83 | 2014-06-12 13:21:50 | [diff] [blame] | 226 | "The \"publicExponent\" must be either 3 or 65537"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 227 | } |
| 228 | |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 229 | Status Status::ErrorImportRsaEmptyModulus() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 230 | return Status(blink::WebCryptoErrorTypeData, "The modulus is empty"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 231 | } |
| 232 | |
[email protected] | e9aa71a | 2014-07-25 08:38:02 | [diff] [blame] | 233 | Status Status::ErrorGenerateRsaUnsupportedModulus() { |
| 234 | return Status(blink::WebCryptoErrorTypeNotSupported, |
| 235 | "The modulus length must be a multiple of 8 bits and >= 256 " |
| 236 | "and <= 16384"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | Status Status::ErrorImportRsaEmptyExponent() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 240 | return Status(blink::WebCryptoErrorTypeData, |
| 241 | "No bytes for the exponent were provided"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | Status Status::ErrorKeyNotExtractable() { |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 245 | return Status(blink::WebCryptoErrorTypeInvalidAccess, |
| 246 | "They key is not extractable"); |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 247 | } |
| 248 | |
eroman | 9e9ed05 | 2014-11-26 03:00:40 | [diff] [blame] | 249 | Status Status::ErrorGenerateHmacKeyLengthZero() { |
| 250 | return Status(blink::WebCryptoErrorTypeOperation, |
xun.sun | e573755 | 2014-12-02 23:52:24 | [diff] [blame] | 251 | "HMAC key length must not be zero"); |
eroman | 9e9ed05 | 2014-11-26 03:00:40 | [diff] [blame] | 252 | } |
| 253 | |
eroman | f93fd5b | 2014-12-11 00:21:06 | [diff] [blame^] | 254 | Status Status::ErrorGetHmacKeyLengthZero() { |
| 255 | return Status(blink::WebCryptoErrorTypeType, |
| 256 | "HMAC key length must not be zero"); |
| 257 | } |
| 258 | |
eroman | 5d519974 | 2014-12-10 22:18:07 | [diff] [blame] | 259 | Status Status::ErrorHmacImportBadLength() { |
| 260 | return Status( |
| 261 | blink::WebCryptoErrorTypeData, |
| 262 | "The optional HMAC key length must be shorter than the key data, and by " |
| 263 | "no more than 7 bits."); |
| 264 | } |
| 265 | |
[email protected] | 9c2e9cf | 2014-05-23 23:13:47 | [diff] [blame] | 266 | Status Status::ErrorCreateKeyBadUsages() { |
xun.sun | 60b6b98 | 2014-11-04 22:57:19 | [diff] [blame] | 267 | return Status(blink::WebCryptoErrorTypeSyntax, |
[email protected] | 9c2e9cf | 2014-05-23 23:13:47 | [diff] [blame] | 268 | "Cannot create a key using the specified key usages."); |
| 269 | } |
| 270 | |
nharper | 70f820a | 2014-12-03 20:36:07 | [diff] [blame] | 271 | Status Status::ErrorCreateKeyEmptyUsages() { |
| 272 | return Status(blink::WebCryptoErrorTypeSyntax, |
| 273 | "Usages cannot be empty when creating a key."); |
| 274 | } |
| 275 | |
eroman | b2ead6d | 2014-11-14 02:26:14 | [diff] [blame] | 276 | Status Status::ErrorImportedEcKeyIncorrectCurve() { |
| 277 | return Status( |
| 278 | blink::WebCryptoErrorTypeData, |
| 279 | "The imported EC key specifies a different curve than requested"); |
| 280 | } |
| 281 | |
| 282 | Status Status::ErrorJwkIncorrectCrv() { |
| 283 | return Status( |
| 284 | blink::WebCryptoErrorTypeData, |
| 285 | "The JWK's \"crv\" member specifies a different curve than requested"); |
| 286 | } |
| 287 | |
| 288 | Status Status::ErrorEcKeyInvalid() { |
| 289 | return Status(blink::WebCryptoErrorTypeData, |
| 290 | "The imported EC key is invalid"); |
| 291 | } |
| 292 | |
| 293 | Status Status::JwkOctetStringWrongLength(const std::string& member_name, |
| 294 | size_t expected_length, |
| 295 | size_t actual_length) { |
| 296 | return Status( |
| 297 | blink::WebCryptoErrorTypeData, |
| 298 | base::StringPrintf( |
| 299 | "The JWK's \"%s\" member defines an octet string of length %" PRIuS |
| 300 | " bytes but should be %" PRIuS, |
| 301 | member_name.c_str(), actual_length, expected_length)); |
| 302 | } |
| 303 | |
eroman | ed48e81 | 2014-11-28 19:59:13 | [diff] [blame] | 304 | Status Status::ErrorEcdhPublicKeyWrongType() { |
| 305 | return Status( |
| 306 | blink::WebCryptoErrorTypeInvalidAccess, |
| 307 | "The public parameter for ECDH key derivation is not a public EC key"); |
| 308 | } |
| 309 | |
| 310 | Status Status::ErrorEcdhPublicKeyWrongAlgorithm() { |
| 311 | return Status( |
| 312 | blink::WebCryptoErrorTypeInvalidAccess, |
| 313 | "The public parameter for ECDH key derivation must be for ECDH"); |
| 314 | } |
| 315 | |
| 316 | Status Status::ErrorEcdhCurveMismatch() { |
| 317 | return Status(blink::WebCryptoErrorTypeInvalidAccess, |
| 318 | "The public parameter for ECDH key derivation is for a " |
| 319 | "different named curve"); |
| 320 | } |
| 321 | |
| 322 | Status Status::ErrorEcdhLengthTooBig(unsigned int max_length_bits) { |
eroman | cb4e417a | 2014-12-05 21:32:29 | [diff] [blame] | 323 | return Status(blink::WebCryptoErrorTypeOperation, |
eroman | ed48e81 | 2014-11-28 19:59:13 | [diff] [blame] | 324 | base::StringPrintf( |
| 325 | "Length specified for ECDH key derivation is too large. " |
| 326 | "Maximum allowed is %u bits", |
| 327 | max_length_bits)); |
| 328 | } |
| 329 | |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 330 | Status::Status(blink::WebCryptoErrorType error_type, |
| 331 | const std::string& error_details_utf8) |
| 332 | : type_(TYPE_ERROR), |
| 333 | error_type_(error_type), |
| 334 | error_details_(error_details_utf8) { |
| 335 | } |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 336 | |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 337 | Status::Status(Type type) : type_(type) { |
| 338 | } |
[email protected] | 37be4cfa | 2014-03-20 05:39:37 | [diff] [blame] | 339 | |
| 340 | } // namespace webcrypto |
| 341 | |
| 342 | } // namespace content |