MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / tryFrom

Function tryFrom

plugins/wasi_crypto/utils/hostfunction.cpp:21–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19} // namespace
20
21WasiCryptoExpect<AsymmetricCommon::Algorithm>
22tryFrom(__wasi_algorithm_type_e_t AlgType,
23 std::string_view RawAlgStr) noexcept {
24 std::string AlgStr = toUpper(RawAlgStr);
25 // Delegate to sig and kx.
26 switch (AlgType) {
27 case __WASI_ALGORITHM_TYPE_SIGNATURES: {
28 return tryFrom<Signatures::Algorithm>(AlgStr).map([](auto Alg) noexcept {
29 return std::visit(
30 [](auto Factory) noexcept -> AsymmetricCommon::Algorithm {
31 return Factory;
32 },
33 Alg);
34 });
35 }
36 case __WASI_ALGORITHM_TYPE_KEY_EXCHANGE: {
37 return tryFrom<Kx::Algorithm>(AlgStr).map([](auto Alg) noexcept {
38 return std::visit(
39 [](auto Factory) noexcept -> AsymmetricCommon::Algorithm {
40 return Factory;
41 },
42 Alg);
43 });
44 }
45 case __WASI_ALGORITHM_TYPE_SYMMETRIC:
46 return WasiCryptoUnexpect(__WASI_CRYPTO_ERRNO_INVALID_OPERATION);
47 default:
48 assumingUnreachable();
49 }
50}
51
52template <>
53WasiCryptoExpect<Kx::Algorithm> tryFrom(std::string_view RawAlgStr) noexcept {

Callers 1

bodyMethod · 0.85

Calls 2

toUpperFunction · 0.85
WasiCryptoUnexpectFunction · 0.85

Tested by

no test coverage detected