/src/WasmEdge/include/host/mock/wasi_crypto_module.h
Line | Count | Source (jump to first uncovered line) |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: 2019-2024 Second State INC |
3 | | |
4 | | #pragma once |
5 | | |
6 | | #include "host/mock/wasi_crypto_func.h" |
7 | | #include "runtime/instance/module.h" |
8 | | |
9 | | namespace WasmEdge { |
10 | | namespace Host { |
11 | | |
12 | | class WasiCryptoCommonModuleMock : public Runtime::Instance::ModuleInstance { |
13 | | public: |
14 | | WasiCryptoCommonModuleMock() |
15 | 0 | : Runtime::Instance::ModuleInstance("wasi_ephemeral_crypto_common") { |
16 | 0 | using namespace WasiCryptoMock; |
17 | 0 | addHostFunc("array_output_len", std::make_unique<Common::ArrayOutputLen>()); |
18 | 0 | addHostFunc("array_output_pull", |
19 | 0 | std::make_unique<Common::ArrayOutputPull>()); |
20 | 0 | addHostFunc("options_open", std::make_unique<Common::OptionsOpen>()); |
21 | 0 | addHostFunc("options_close", std::make_unique<Common::OptionsClose>()); |
22 | 0 | addHostFunc("options_set", std::make_unique<Common::OptionsSet>()); |
23 | 0 | addHostFunc("options_set_u64", std::make_unique<Common::OptionsSetU64>()); |
24 | 0 | addHostFunc("options_set_guest_buffer", |
25 | 0 | std::make_unique<Common::OptionsSetGuestBuffer>()); |
26 | 0 | addHostFunc("secrets_manager_open", |
27 | 0 | std::make_unique<Common::SecretsManagerOpen>()); |
28 | 0 | addHostFunc("secrets_manager_close", |
29 | 0 | std::make_unique<Common::SecretsManagerClose>()); |
30 | 0 | addHostFunc("secrets_manager_invalidate", |
31 | 0 | std::make_unique<Common::SecretsManagerInvalidate>()); |
32 | 0 | } |
33 | | }; |
34 | | |
35 | | class WasiCryptoAsymmetricCommonModuleMock |
36 | | : public Runtime::Instance::ModuleInstance { |
37 | | public: |
38 | | WasiCryptoAsymmetricCommonModuleMock() |
39 | 0 | : Runtime::Instance::ModuleInstance( |
40 | 0 | "wasi_ephemeral_crypto_asymmetric_common") { |
41 | 0 | using namespace WasiCryptoMock; |
42 | 0 | addHostFunc("keypair_generate", |
43 | 0 | std::make_unique<AsymmetricCommon::KeypairGenerate>()); |
44 | 0 | addHostFunc("keypair_import", |
45 | 0 | std::make_unique<AsymmetricCommon::KeypairImport>()); |
46 | 0 | addHostFunc("keypair_generate_managed", |
47 | 0 | std::make_unique<AsymmetricCommon::KeypairGenerateManaged>()); |
48 | 0 | addHostFunc("keypair_store_managed", |
49 | 0 | std::make_unique<AsymmetricCommon::KeypairStoreManaged>()); |
50 | 0 | addHostFunc("keypair_replace_managed", |
51 | 0 | std::make_unique<AsymmetricCommon::KeypairReplaceManaged>()); |
52 | 0 | addHostFunc("keypair_id", std::make_unique<AsymmetricCommon::KeypairId>()); |
53 | 0 | addHostFunc("keypair_from_id", |
54 | 0 | std::make_unique<AsymmetricCommon::KeypairFromId>()); |
55 | 0 | addHostFunc("keypair_from_pk_and_sk", |
56 | 0 | std::make_unique<AsymmetricCommon::KeypairFromPkAndSk>()); |
57 | 0 | addHostFunc("keypair_export", |
58 | 0 | std::make_unique<AsymmetricCommon::KeypairExport>()); |
59 | 0 | addHostFunc("keypair_publickey", |
60 | 0 | std::make_unique<AsymmetricCommon::KeypairPublickey>()); |
61 | 0 | addHostFunc("keypair_secretkey", |
62 | 0 | std::make_unique<AsymmetricCommon::KeypairSecretkey>()); |
63 | 0 | addHostFunc("keypair_close", |
64 | 0 | std::make_unique<AsymmetricCommon::KeypairClose>()); |
65 | 0 | addHostFunc("publickey_import", |
66 | 0 | std::make_unique<AsymmetricCommon::PublickeyImport>()); |
67 | 0 | addHostFunc("publickey_export", |
68 | 0 | std::make_unique<AsymmetricCommon::PublickeyExport>()); |
69 | 0 | addHostFunc("publickey_verify", |
70 | 0 | std::make_unique<AsymmetricCommon::PublickeyVerify>()); |
71 | 0 | addHostFunc("publickey_from_secretkey", |
72 | 0 | std::make_unique<AsymmetricCommon::PublickeyFromSecretkey>()); |
73 | 0 | addHostFunc("publickey_close", |
74 | 0 | std::make_unique<AsymmetricCommon::PublickeyClose>()); |
75 | 0 | addHostFunc("secretkey_import", |
76 | 0 | std::make_unique<AsymmetricCommon::SecretkeyImport>()); |
77 | 0 | addHostFunc("secretkey_export", |
78 | 0 | std::make_unique<AsymmetricCommon::SecretkeyExport>()); |
79 | 0 | addHostFunc("secretkey_close", |
80 | 0 | std::make_unique<AsymmetricCommon::SecretkeyClose>()); |
81 | 0 | } |
82 | | }; |
83 | | |
84 | | class WasiCryptoKxModuleMock : public Runtime::Instance::ModuleInstance { |
85 | | public: |
86 | | WasiCryptoKxModuleMock() |
87 | 0 | : Runtime::Instance::ModuleInstance("wasi_ephemeral_crypto_kx") { |
88 | 0 | using namespace WasiCryptoMock; |
89 | 0 | addHostFunc("kx_dh", std::make_unique<Kx::Dh>()); |
90 | 0 | addHostFunc("kx_encapsulate", std::make_unique<Kx::Encapsulate>()); |
91 | 0 | addHostFunc("kx_decapsulate", std::make_unique<Kx::Decapsulate>()); |
92 | 0 | } |
93 | | }; |
94 | | |
95 | | class WasiCryptoSignaturesModuleMock |
96 | | : public Runtime::Instance::ModuleInstance { |
97 | | public: |
98 | | WasiCryptoSignaturesModuleMock() |
99 | 0 | : Runtime::Instance::ModuleInstance("wasi_ephemeral_crypto_signatures") { |
100 | 0 | using namespace WasiCryptoMock; |
101 | 0 | addHostFunc("signature_export", std::make_unique<Signatures::Export>()); |
102 | 0 | addHostFunc("signature_import", std::make_unique<Signatures::Import>()); |
103 | 0 | addHostFunc("signature_state_open", |
104 | 0 | std::make_unique<Signatures::StateOpen>()); |
105 | 0 | addHostFunc("signature_state_update", |
106 | 0 | std::make_unique<Signatures::StateUpdate>()); |
107 | 0 | addHostFunc("signature_state_sign", |
108 | 0 | std::make_unique<Signatures::StateSign>()); |
109 | 0 | addHostFunc("signature_state_close", |
110 | 0 | std::make_unique<Signatures::StateClose>()); |
111 | 0 | addHostFunc("signature_verification_state_open", |
112 | 0 | std::make_unique<Signatures::VerificationStateOpen>()); |
113 | 0 | addHostFunc("signature_verification_state_update", |
114 | 0 | std::make_unique<Signatures::VerificationStateUpdate>()); |
115 | 0 | addHostFunc("signature_verification_state_verify", |
116 | 0 | std::make_unique<Signatures::VerificationStateVerify>()); |
117 | 0 | addHostFunc("signature_verification_state_close", |
118 | 0 | std::make_unique<Signatures::VerificationStateClose>()); |
119 | 0 | addHostFunc("signature_close", std::make_unique<Signatures::Close>()); |
120 | 0 | } |
121 | | }; |
122 | | |
123 | | class WasiCryptoSymmetricModuleMock : public Runtime::Instance::ModuleInstance { |
124 | | public: |
125 | | WasiCryptoSymmetricModuleMock() |
126 | 0 | : Runtime::Instance::ModuleInstance("wasi_ephemeral_crypto_symmetric") { |
127 | 0 | using namespace WasiCryptoMock; |
128 | 0 | addHostFunc("symmetric_key_generate", |
129 | 0 | std::make_unique<Symmetric::KeyGenerate>()); |
130 | 0 | addHostFunc("symmetric_key_import", |
131 | 0 | std::make_unique<Symmetric::KeyImport>()); |
132 | 0 | addHostFunc("symmetric_key_export", |
133 | 0 | std::make_unique<Symmetric::KeyExport>()); |
134 | 0 | addHostFunc("symmetric_key_close", std::make_unique<Symmetric::KeyClose>()); |
135 | 0 | addHostFunc("symmetric_key_generate_managed", |
136 | 0 | std::make_unique<Symmetric::KeyGenerateManaged>()); |
137 | 0 | addHostFunc("symmetric_key_store_managed", |
138 | 0 | std::make_unique<Symmetric::KeyStoreManaged>()); |
139 | 0 | addHostFunc("symmetric_key_replace_managed", |
140 | 0 | std::make_unique<Symmetric::KeyReplaceManaged>()); |
141 | 0 | addHostFunc("symmetric_key_id", std::make_unique<Symmetric::KeyId>()); |
142 | 0 | addHostFunc("symmetric_key_from_id", |
143 | 0 | std::make_unique<Symmetric::KeyFromId>()); |
144 | 0 | addHostFunc("symmetric_state_open", |
145 | 0 | std::make_unique<Symmetric::StateOpen>()); |
146 | 0 | addHostFunc("symmetric_state_clone", |
147 | 0 | std::make_unique<Symmetric::StateClone>()); |
148 | 0 | addHostFunc("symmetric_state_options_get", |
149 | 0 | std::make_unique<Symmetric::StateOptionsGet>()); |
150 | 0 | addHostFunc("symmetric_state_options_get_u64", |
151 | 0 | std::make_unique<Symmetric::StateOptionsGetU64>()); |
152 | 0 | addHostFunc("symmetric_state_close", |
153 | 0 | std::make_unique<Symmetric::StateClose>()); |
154 | 0 | addHostFunc("symmetric_state_absorb", |
155 | 0 | std::make_unique<Symmetric::StateAbsorb>()); |
156 | 0 | addHostFunc("symmetric_state_squeeze", |
157 | 0 | std::make_unique<Symmetric::StateSqueeze>()); |
158 | 0 | addHostFunc("symmetric_state_squeeze_tag", |
159 | 0 | std::make_unique<Symmetric::StateSqueezeTag>()); |
160 | 0 | addHostFunc("symmetric_state_squeeze_key", |
161 | 0 | std::make_unique<Symmetric::StateSqueezeKey>()); |
162 | 0 | addHostFunc("symmetric_state_max_tag_len", |
163 | 0 | std::make_unique<Symmetric::StateMaxTagLen>()); |
164 | 0 | addHostFunc("symmetric_state_encrypt", |
165 | 0 | std::make_unique<Symmetric::StateEncrypt>()); |
166 | 0 | addHostFunc("symmetric_state_encrypt_detached", |
167 | 0 | std::make_unique<Symmetric::StateEncryptDetached>()); |
168 | 0 | addHostFunc("symmetric_state_decrypt", |
169 | 0 | std::make_unique<Symmetric::StateDecrypt>()); |
170 | 0 | addHostFunc("symmetric_state_decrypt_detached", |
171 | 0 | std::make_unique<Symmetric::StateDecryptDetached>()); |
172 | 0 | addHostFunc("symmetric_state_ratchet", |
173 | 0 | std::make_unique<Symmetric::StateRatchet>()); |
174 | 0 | addHostFunc("symmetric_tag_len", std::make_unique<Symmetric::TagLen>()); |
175 | 0 | addHostFunc("symmetric_tag_pull", std::make_unique<Symmetric::TagPull>()); |
176 | 0 | addHostFunc("symmetric_tag_verify", |
177 | 0 | std::make_unique<Symmetric::TagVerify>()); |
178 | 0 | addHostFunc("symmetric_tag_close", std::make_unique<Symmetric::TagClose>()); |
179 | 0 | } |
180 | | }; |
181 | | |
182 | | } // namespace Host |
183 | | } // namespace WasmEdge |