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 "JSCryptoKeyUsage.h" |
26 | |
27 | #include <JavaScriptCore/JSCInlines.h> |
28 | #include <JavaScriptCore/JSString.h> |
29 | #include <wtf/NeverDestroyed.h> |
30 | |
31 | |
32 | namespace WebCore { |
33 | using namespace JSC; |
34 | |
35 | String convertEnumerationToString(CryptoKeyUsage enumerationValue) |
36 | { |
37 | static const NeverDestroyed<String> values[] = { |
38 | MAKE_STATIC_STRING_IMPL("encrypt" ), |
39 | MAKE_STATIC_STRING_IMPL("decrypt" ), |
40 | MAKE_STATIC_STRING_IMPL("sign" ), |
41 | MAKE_STATIC_STRING_IMPL("verify" ), |
42 | MAKE_STATIC_STRING_IMPL("deriveKey" ), |
43 | MAKE_STATIC_STRING_IMPL("deriveBits" ), |
44 | MAKE_STATIC_STRING_IMPL("wrapKey" ), |
45 | MAKE_STATIC_STRING_IMPL("unwrapKey" ), |
46 | }; |
47 | static_assert(static_cast<size_t>(CryptoKeyUsage::Encrypt) == 0, "CryptoKeyUsage::Encrypt is not 0 as expected" ); |
48 | static_assert(static_cast<size_t>(CryptoKeyUsage::Decrypt) == 1, "CryptoKeyUsage::Decrypt is not 1 as expected" ); |
49 | static_assert(static_cast<size_t>(CryptoKeyUsage::Sign) == 2, "CryptoKeyUsage::Sign is not 2 as expected" ); |
50 | static_assert(static_cast<size_t>(CryptoKeyUsage::Verify) == 3, "CryptoKeyUsage::Verify is not 3 as expected" ); |
51 | static_assert(static_cast<size_t>(CryptoKeyUsage::DeriveKey) == 4, "CryptoKeyUsage::DeriveKey is not 4 as expected" ); |
52 | static_assert(static_cast<size_t>(CryptoKeyUsage::DeriveBits) == 5, "CryptoKeyUsage::DeriveBits is not 5 as expected" ); |
53 | static_assert(static_cast<size_t>(CryptoKeyUsage::WrapKey) == 6, "CryptoKeyUsage::WrapKey is not 6 as expected" ); |
54 | static_assert(static_cast<size_t>(CryptoKeyUsage::UnwrapKey) == 7, "CryptoKeyUsage::UnwrapKey is not 7 as expected" ); |
55 | ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values)); |
56 | return values[static_cast<size_t>(enumerationValue)]; |
57 | } |
58 | |
59 | template<> JSString* convertEnumerationToJS(ExecState& state, CryptoKeyUsage enumerationValue) |
60 | { |
61 | return jsStringWithCache(&state, convertEnumerationToString(enumerationValue)); |
62 | } |
63 | |
64 | template<> Optional<CryptoKeyUsage> parseEnumeration<CryptoKeyUsage>(ExecState& state, JSValue value) |
65 | { |
66 | auto stringValue = value.toWTFString(&state); |
67 | if (stringValue == "encrypt" ) |
68 | return CryptoKeyUsage::Encrypt; |
69 | if (stringValue == "decrypt" ) |
70 | return CryptoKeyUsage::Decrypt; |
71 | if (stringValue == "sign" ) |
72 | return CryptoKeyUsage::Sign; |
73 | if (stringValue == "verify" ) |
74 | return CryptoKeyUsage::Verify; |
75 | if (stringValue == "deriveKey" ) |
76 | return CryptoKeyUsage::DeriveKey; |
77 | if (stringValue == "deriveBits" ) |
78 | return CryptoKeyUsage::DeriveBits; |
79 | if (stringValue == "wrapKey" ) |
80 | return CryptoKeyUsage::WrapKey; |
81 | if (stringValue == "unwrapKey" ) |
82 | return CryptoKeyUsage::UnwrapKey; |
83 | return WTF::nullopt; |
84 | } |
85 | |
86 | template<> const char* expectedEnumerationValues<CryptoKeyUsage>() |
87 | { |
88 | return "\"encrypt\", \"decrypt\", \"sign\", \"verify\", \"deriveKey\", \"deriveBits\", \"wrapKey\", \"unwrapKey\"" ; |
89 | } |
90 | |
91 | } // namespace WebCore |
92 | |
93 | #endif // ENABLE(WEB_CRYPTO) |
94 | |