| 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 "JSCryptoRsaKeyAlgorithm.h" |
| 26 | |
| 27 | #include "JSDOMConvertBufferSource.h" |
| 28 | #include "JSDOMConvertNumbers.h" |
| 29 | #include "JSDOMConvertStrings.h" |
| 30 | #include "JSDOMGlobalObject.h" |
| 31 | #include <JavaScriptCore/JSCInlines.h> |
| 32 | #include <JavaScriptCore/ObjectConstructor.h> |
| 33 | |
| 34 | |
| 35 | namespace WebCore { |
| 36 | using namespace JSC; |
| 37 | |
| 38 | #if ENABLE(WEB_CRYPTO) |
| 39 | |
| 40 | template<> CryptoRsaKeyAlgorithm convertDictionary<CryptoRsaKeyAlgorithm>(ExecState& state, JSValue value) |
| 41 | { |
| 42 | VM& vm = state.vm(); |
| 43 | auto throwScope = DECLARE_THROW_SCOPE(vm); |
| 44 | bool isNullOrUndefined = value.isUndefinedOrNull(); |
| 45 | auto* object = isNullOrUndefined ? nullptr : value.getObject(); |
| 46 | if (UNLIKELY(!isNullOrUndefined && !object)) { |
| 47 | throwTypeError(&state, throwScope); |
| 48 | return { }; |
| 49 | } |
| 50 | CryptoRsaKeyAlgorithm result; |
| 51 | JSValue nameValue; |
| 52 | if (isNullOrUndefined) |
| 53 | nameValue = jsUndefined(); |
| 54 | else { |
| 55 | nameValue = object->get(&state, Identifier::fromString(&state, "name" )); |
| 56 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 57 | } |
| 58 | if (!nameValue.isUndefined()) { |
| 59 | result.name = convert<IDLDOMString>(state, nameValue); |
| 60 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 61 | } else { |
| 62 | throwRequiredMemberTypeError(state, throwScope, "name" , "CryptoRsaKeyAlgorithm" , "DOMString" ); |
| 63 | return { }; |
| 64 | } |
| 65 | JSValue modulusLengthValue; |
| 66 | if (isNullOrUndefined) |
| 67 | modulusLengthValue = jsUndefined(); |
| 68 | else { |
| 69 | modulusLengthValue = object->get(&state, Identifier::fromString(&state, "modulusLength" )); |
| 70 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 71 | } |
| 72 | if (!modulusLengthValue.isUndefined()) { |
| 73 | result.modulusLength = convert<IDLUnsignedLong>(state, modulusLengthValue); |
| 74 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 75 | } else { |
| 76 | throwRequiredMemberTypeError(state, throwScope, "modulusLength" , "CryptoRsaKeyAlgorithm" , "unsigned long" ); |
| 77 | return { }; |
| 78 | } |
| 79 | JSValue publicExponentValue; |
| 80 | if (isNullOrUndefined) |
| 81 | publicExponentValue = jsUndefined(); |
| 82 | else { |
| 83 | publicExponentValue = object->get(&state, Identifier::fromString(&state, "publicExponent" )); |
| 84 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 85 | } |
| 86 | if (!publicExponentValue.isUndefined()) { |
| 87 | result.publicExponent = convert<IDLUint8Array>(state, publicExponentValue); |
| 88 | RETURN_IF_EXCEPTION(throwScope, { }); |
| 89 | } else { |
| 90 | throwRequiredMemberTypeError(state, throwScope, "publicExponent" , "CryptoRsaKeyAlgorithm" , "Uint8Array" ); |
| 91 | return { }; |
| 92 | } |
| 93 | return result; |
| 94 | } |
| 95 | |
| 96 | JSC::JSObject* convertDictionaryToJS(JSC::ExecState& state, JSDOMGlobalObject& globalObject, const CryptoRsaKeyAlgorithm& dictionary) |
| 97 | { |
| 98 | auto& vm = state.vm(); |
| 99 | |
| 100 | auto result = constructEmptyObject(&state, globalObject.objectPrototype()); |
| 101 | |
| 102 | auto nameValue = toJS<IDLDOMString>(state, dictionary.name); |
| 103 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "name" ), nameValue); |
| 104 | auto modulusLengthValue = toJS<IDLUnsignedLong>(dictionary.modulusLength); |
| 105 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "modulusLength" ), modulusLengthValue); |
| 106 | auto publicExponentValue = toJS<IDLUint8Array>(state, globalObject, dictionary.publicExponent); |
| 107 | result->putDirect(vm, JSC::Identifier::fromString(&vm, "publicExponent" ), publicExponentValue); |
| 108 | return result; |
| 109 | } |
| 110 | |
| 111 | #endif |
| 112 | |
| 113 | } // namespace WebCore |
| 114 | |
| 115 | #endif // ENABLE(WEB_CRYPTO) |
| 116 | |