| 1 | /* |
| 2 | This file is part of the WebKit open source project. |
| 3 | This file has been generated by generate-bindings.pl. DO NOT MODIFY! |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Library General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Library General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Library General Public License |
| 16 | along with this library; see the file COPYING.LIB. If not, write to |
| 17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | |
| 23 | #if ENABLE(WEB_CRYPTO) |
| 24 | |
| 25 | #include "JSJsonWebKey.h" |
| 26 | |
| 27 | #include "JSCryptoKeyUsage.h" |
| 28 | #include "JSDOMConvertBoolean.h" |
| 29 | #include "JSDOMConvertEnumeration.h" |
| 30 | #include "JSDOMConvertSequences.h" |
| 31 | #include "JSDOMConvertStrings.h" |
| 32 | #include "JSDOMGlobalObject.h" |
| 33 | #include "JSRsaOtherPrimesInfo.h" |
| 34 | #include <JavaScriptCore/JSArray.h> |
| 35 | #include <JavaScriptCore/JSCInlines.h> |
| 36 | #include <JavaScriptCore/ObjectConstructor.h> |
| 37 | |
| 38 | |
| 39 | namespace WebCore { |
| 40 | using namespace JSC; |
| 41 | |
| 42 | #if ENABLE(WEB_CRYPTO) |
| 43 | |
| 44 | template<> JsonWebKey convertDictionary<JsonWebKey>(ExecState& state, JSValue value) |
| 45 | { |
| 46 | VM& vm = state.vm(); |
| 47 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 48 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 49 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 50 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 51 | throwTypeError(&state, throwScope); |
| 52 | return { }; |
| 53 | } |
| 54 | JsonWebKey result; |
| 55 | JSValue algValue; |
| 56 | if (isNullOrUndefined) |
| 57 | algValue = jsUndefined(); |
| 58 | else { |
| 59 | algValue = object->get(&state, Identifier::fromString(&state, "alg" )); |
| 60 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 61 | } |
| 62 | if (!algValue.isUndefined()) { |
| 63 | result.alg = convert<IDLDOMString>(state, algValue); |
| 64 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 65 | } |
| 66 | JSValue crvValue; |
| 67 | if (isNullOrUndefined) |
| 68 | crvValue = jsUndefined(); |
| 69 | else { |
| 70 | crvValue = object->get(&state, Identifier::fromString(&state, "crv" )); |
| 71 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 72 | } |
| 73 | if (!crvValue.isUndefined()) { |
| 74 | result.crv = convert<IDLDOMString>(state, crvValue); |
| 75 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 76 | } |
| 77 | JSValue dValue; |
| 78 | if (isNullOrUndefined) |
| 79 | dValue = jsUndefined(); |
| 80 | else { |
| 81 | dValue = object->get(&state, Identifier::fromString(&state, "d" )); |
| 82 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 83 | } |
| 84 | if (!dValue.isUndefined()) { |
| 85 | result.d = convert<IDLDOMString>(state, dValue); |
| 86 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 87 | } |
| 88 | JSValue dpValue; |
| 89 | if (isNullOrUndefined) |
| 90 | dpValue = jsUndefined(); |
| 91 | else { |
| 92 | dpValue = object->get(&state, Identifier::fromString(&state, "dp" )); |
| 93 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 94 | } |
| 95 | if (!dpValue.isUndefined()) { |
| 96 | result.dp = convert<IDLDOMString>(state, dpValue); |
| 97 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 98 | } |
| 99 | JSValue dqValue; |
| 100 | if (isNullOrUndefined) |
| 101 | dqValue = jsUndefined(); |
| 102 | else { |
| 103 | dqValue = object->get(&state, Identifier::fromString(&state, "dq" )); |
| 104 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 105 | } |
| 106 | if (!dqValue.isUndefined()) { |
| 107 | result.dq = convert<IDLDOMString>(state, dqValue); |
| 108 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 109 | } |
| 110 | JSValue eValue; |
| 111 | if (isNullOrUndefined) |
| 112 | eValue = jsUndefined(); |
| 113 | else { |
| 114 | eValue = object->get(&state, Identifier::fromString(&state, "e" )); |
| 115 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 116 | } |
| 117 | if (!eValue.isUndefined()) { |
| 118 | result.e = convert<IDLDOMString>(state, eValue); |
| 119 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 120 | } |
| 121 | JSValue extValue; |
| 122 | if (isNullOrUndefined) |
| 123 | extValue = jsUndefined(); |
| 124 | else { |
| 125 | extValue = object->get(&state, Identifier::fromString(&state, "ext" )); |
| 126 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 127 | } |
| 128 | if (!extValue.isUndefined()) { |
| 129 | result.ext = convert<IDLBoolean>(state, extValue); |
| 130 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 131 | } |
| 132 | JSValue kValue; |
| 133 | if (isNullOrUndefined) |
| 134 | kValue = jsUndefined(); |
| 135 | else { |
| 136 | kValue = object->get(&state, Identifier::fromString(&state, "k" )); |
| 137 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 138 | } |
| 139 | if (!kValue.isUndefined()) { |
| 140 | result.k = convert<IDLDOMString>(state, kValue); |
| 141 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 142 | } |
| 143 | JSValue key_opsValue; |
| 144 | if (isNullOrUndefined) |
| 145 | key_opsValue = jsUndefined(); |
| 146 | else { |
| 147 | key_opsValue = object->get(&state, Identifier::fromString(&state, "key_ops" )); |
| 148 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 149 | } |
| 150 | if (!key_opsValue.isUndefined()) { |
| 151 | result.key_ops = convert<IDLSequence<IDLEnumeration<CryptoKeyUsage>>>(state, key_opsValue); |
| 152 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 153 | } |
| 154 | JSValue ktyValue; |
| 155 | if (isNullOrUndefined) |
| 156 | ktyValue = jsUndefined(); |
| 157 | else { |
| 158 | ktyValue = object->get(&state, Identifier::fromString(&state, "kty" )); |
| 159 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 160 | } |
| 161 | if (!ktyValue.isUndefined()) { |
| 162 | result.kty = convert<IDLDOMString>(state, ktyValue); |
| 163 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 164 | } else { |
| 165 | throwRequiredMemberTypeError(state, throwScope, "kty" , "JsonWebKey" , "DOMString" ); |
| 166 | return { }; |
| 167 | } |
| 168 | JSValue nValue; |
| 169 | if (isNullOrUndefined) |
| 170 | nValue = jsUndefined(); |
| 171 | else { |
| 172 | nValue = object->get(&state, Identifier::fromString(&state, "n" )); |
| 173 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 174 | } |
| 175 | if (!nValue.isUndefined()) { |
| 176 | result.n = convert<IDLDOMString>(state, nValue); |
| 177 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 178 | } |
| 179 | JSValue othValue; |
| 180 | if (isNullOrUndefined) |
| 181 | othValue = jsUndefined(); |
| 182 | else { |
| 183 | othValue = object->get(&state, Identifier::fromString(&state, "oth" )); |
| 184 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 185 | } |
| 186 | if (!othValue.isUndefined()) { |
| 187 | result.oth = convert<IDLSequence<IDLDictionary<RsaOtherPrimesInfo>>>(state, othValue); |
| 188 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 189 | } |
| 190 | JSValue pValue; |
| 191 | if (isNullOrUndefined) |
| 192 | pValue = jsUndefined(); |
| 193 | else { |
| 194 | pValue = object->get(&state, Identifier::fromString(&state, "p" )); |
| 195 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 196 | } |
| 197 | if (!pValue.isUndefined()) { |
| 198 | result.p = convert<IDLDOMString>(state, pValue); |
| 199 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 200 | } |
| 201 | JSValue qValue; |
| 202 | if (isNullOrUndefined) |
| 203 | qValue = jsUndefined(); |
| 204 | else { |
| 205 | qValue = object->get(&state, Identifier::fromString(&state, "q" )); |
| 206 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 207 | } |
| 208 | if (!qValue.isUndefined()) { |
| 209 | result.q = convert<IDLDOMString>(state, qValue); |
| 210 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 211 | } |
| 212 | JSValue qiValue; |
| 213 | if (isNullOrUndefined) |
| 214 | qiValue = jsUndefined(); |
| 215 | else { |
| 216 | qiValue = object->get(&state, Identifier::fromString(&state, "qi" )); |
| 217 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 218 | } |
| 219 | if (!qiValue.isUndefined()) { |
| 220 | result.qi = convert<IDLDOMString>(state, qiValue); |
| 221 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 222 | } |
| 223 | JSValue useValue; |
| 224 | if (isNullOrUndefined) |
| 225 | useValue = jsUndefined(); |
| 226 | else { |
| 227 | useValue = object->get(&state, Identifier::fromString(&state, "use" )); |
| 228 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 229 | } |
| 230 | if (!useValue.isUndefined()) { |
| 231 | result.use = convert<IDLDOMString>(state, useValue); |
| 232 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 233 | } |
| 234 | JSValue xValue; |
| 235 | if (isNullOrUndefined) |
| 236 | xValue = jsUndefined(); |
| 237 | else { |
| 238 | xValue = object->get(&state, Identifier::fromString(&state, "x" )); |
| 239 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 240 | } |
| 241 | if (!xValue.isUndefined()) { |
| 242 | result.x = convert<IDLDOMString>(state, xValue); |
| 243 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 244 | } |
| 245 | JSValue yValue; |
| 246 | if (isNullOrUndefined) |
| 247 | yValue = jsUndefined(); |
| 248 | else { |
| 249 | yValue = object->get(&state, Identifier::fromString(&state, "y" )); |
| 250 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 251 | } |
| 252 | if (!yValue.isUndefined()) { |
| 253 | result.y = convert<IDLDOMString>(state, yValue); |
| 254 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 255 | } |
| 256 | return result; |
| 257 | } |
| 258 | |
| 259 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const JsonWebKey& dictionary) |
| 260 | { |
| 261 | auto& vm = state.vm(); |
| 262 | |
| 263 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 264 | |
| 265 | if (!IDLDOMString::isNullValue(dictionary.alg)) { |
| 266 | auto algValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.alg)); |
| 267 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "alg" ), algValue); |
| 268 | } |
| 269 | if (!IDLDOMString::isNullValue(dictionary.crv)) { |
| 270 | auto crvValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.crv)); |
| 271 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "crv" ), crvValue); |
| 272 | } |
| 273 | if (!IDLDOMString::isNullValue(dictionary.d)) { |
| 274 | auto dValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.d)); |
| 275 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "d" ), dValue); |
| 276 | } |
| 277 | if (!IDLDOMString::isNullValue(dictionary.dp)) { |
| 278 | auto dpValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.dp)); |
| 279 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "dp" ), dpValue); |
| 280 | } |
| 281 | if (!IDLDOMString::isNullValue(dictionary.dq)) { |
| 282 | auto dqValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.dq)); |
| 283 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "dq" ), dqValue); |
| 284 | } |
| 285 | if (!IDLDOMString::isNullValue(dictionary.e)) { |
| 286 | auto eValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.e)); |
| 287 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "e" ), eValue); |
| 288 | } |
| 289 | if (!IDLBoolean::isNullValue(dictionary.ext)) { |
| 290 | auto extValue = toJS<IDLBoolean>(IDLBoolean::extractValueFromNullable(dictionary.ext)); |
| 291 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "ext" ), extValue); |
| 292 | } |
| 293 | if (!IDLDOMString::isNullValue(dictionary.k)) { |
| 294 | auto kValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.k)); |
| 295 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "k" ), kValue); |
| 296 | } |
| 297 | if (!IDLSequence<IDLEnumeration<CryptoKeyUsage>>::isNullValue(dictionary.key_ops)) { |
| 298 | auto key_opsValue = toJS<IDLSequence<IDLEnumeration<CryptoKeyUsage>>>(state, globalObject, IDLSequence<IDLEnumeration<CryptoKeyUsage>>::extractValueFromNullable(dictionary.key_ops)); |
| 299 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "key_ops" ), key_opsValue); |
| 300 | } |
| 301 | auto ktyValue = toJS<IDLDOMString>(state, dictionary.kty); |
| 302 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "kty" ), ktyValue); |
| 303 | if (!IDLDOMString::isNullValue(dictionary.n)) { |
| 304 | auto nValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.n)); |
| 305 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "n" ), nValue); |
| 306 | } |
| 307 | if (!IDLSequence<IDLDictionary<RsaOtherPrimesInfo>>::isNullValue(dictionary.oth)) { |
| 308 | auto othValue = toJS<IDLSequence<IDLDictionary<RsaOtherPrimesInfo>>>(state, globalObject, IDLSequence<IDLDictionary<RsaOtherPrimesInfo>>::extractValueFromNullable(dictionary.oth)); |
| 309 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "oth" ), othValue); |
| 310 | } |
| 311 | if (!IDLDOMString::isNullValue(dictionary.p)) { |
| 312 | auto pValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.p)); |
| 313 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "p" ), pValue); |
| 314 | } |
| 315 | if (!IDLDOMString::isNullValue(dictionary.q)) { |
| 316 | auto qValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.q)); |
| 317 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "q" ), qValue); |
| 318 | } |
| 319 | if (!IDLDOMString::isNullValue(dictionary.qi)) { |
| 320 | auto qiValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.qi)); |
| 321 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "qi" ), qiValue); |
| 322 | } |
| 323 | if (!IDLDOMString::isNullValue(dictionary.use)) { |
| 324 | auto useValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.use)); |
| 325 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "use" ), useValue); |
| 326 | } |
| 327 | if (!IDLDOMString::isNullValue(dictionary.x)) { |
| 328 | auto xValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.x)); |
| 329 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "x" ), xValue); |
| 330 | } |
| 331 | if (!IDLDOMString::isNullValue(dictionary.y)) { |
| 332 | auto yValue = toJS<IDLDOMString>(state, IDLDOMString::extractValueFromNullable(dictionary.y)); |
| 333 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "y" ), yValue); |
| 334 | } |
| 335 | return result; |
| 336 | } |
| 337 | |
| 338 | #endif |
| 339 | |
| 340 | } // namespace WebCore |
| 341 | |
| 342 | #endif // ENABLE(WEB_CRYPTO) |
| 343 | |