forked from cory/tildefriends
Latest libsodium-1.0.18-stable.tar.gz.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4193 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
1
deps/libsodium/test/default/Makefile.am
vendored
1
deps/libsodium/test/default/Makefile.am
vendored
@ -1,5 +1,6 @@
|
||||
|
||||
EXTRA_DIST = \
|
||||
run.sh \
|
||||
cmptest.h \
|
||||
wasi-test-wrapper.sh \
|
||||
wintest.bat \
|
||||
|
1
deps/libsodium/test/default/Makefile.in
vendored
1
deps/libsodium/test/default/Makefile.in
vendored
@ -901,6 +901,7 @@ top_srcdir = @top_srcdir@
|
||||
valgrind_enabled_tools = @valgrind_enabled_tools@
|
||||
valgrind_tools = @valgrind_tools@
|
||||
EXTRA_DIST = \
|
||||
run.sh \
|
||||
cmptest.h \
|
||||
wasi-test-wrapper.sh \
|
||||
wintest.bat \
|
||||
|
70
deps/libsodium/test/default/aead_aes256gcm.c
vendored
70
deps/libsodium/test/default/aead_aes256gcm.c
vendored
@ -3081,6 +3081,7 @@ tv(void)
|
||||
{
|
||||
unsigned char *ad;
|
||||
unsigned char *ciphertext;
|
||||
unsigned char *ciphertext2;
|
||||
unsigned char *decrypted;
|
||||
unsigned char *detached_ciphertext;
|
||||
unsigned char *expected_ciphertext;
|
||||
@ -3210,6 +3211,32 @@ tv(void)
|
||||
printf("Incorrect decryption of test vector #%u\n", (unsigned int) i);
|
||||
}
|
||||
|
||||
ciphertext2 = (unsigned char *) sodium_malloc(ciphertext_len);
|
||||
crypto_aead_aes256gcm_encrypt(ciphertext, &found_ciphertext_len, message,
|
||||
message_len, ad, ad_len, NULL, nonce, key);
|
||||
assert(found_ciphertext_len == ciphertext_len);
|
||||
memcpy(ciphertext2, message, message_len);
|
||||
crypto_aead_aes256gcm_encrypt(ciphertext2, &found_ciphertext_len,
|
||||
ciphertext2, message_len, ad, ad_len, NULL,
|
||||
nonce, key);
|
||||
assert(found_ciphertext_len == ciphertext_len);
|
||||
assert(memcmp(ciphertext, ciphertext2, ciphertext_len) == 0);
|
||||
if (crypto_aead_aes256gcm_decrypt(ciphertext2, &found_message_len, NULL,
|
||||
ciphertext2, ciphertext_len, ad, ad_len,
|
||||
nonce, key) != 0) {
|
||||
printf("In-place decryption of vector #%u failed\n", (unsigned int) i);
|
||||
}
|
||||
assert(found_message_len == message_len);
|
||||
assert(memcmp(ciphertext2, message, message_len) == 0);
|
||||
if (crypto_aead_aes256gcm_decrypt(message, &found_message_len, NULL,
|
||||
ciphertext, ciphertext_len, ad, ad_len,
|
||||
nonce, key) != 0) {
|
||||
printf("Decryption of vector #%u failed\n", (unsigned int) i);
|
||||
}
|
||||
assert(found_message_len == message_len);
|
||||
assert(memcmp(ciphertext2, message, message_len) == 0);
|
||||
|
||||
sodium_free(ciphertext2);
|
||||
sodium_free(message);
|
||||
sodium_free(ad);
|
||||
sodium_free(expected_ciphertext);
|
||||
@ -3225,11 +3252,54 @@ tv(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tv2(void)
|
||||
{
|
||||
unsigned char *ciphertext;
|
||||
unsigned char *message;
|
||||
unsigned char *message2;
|
||||
unsigned char *nonce;
|
||||
unsigned char *key;
|
||||
size_t message_len;
|
||||
size_t ciphertext_len;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 250; i++) {
|
||||
message_len = randombytes_uniform(1000);
|
||||
ciphertext_len = message_len + crypto_aead_aes256gcm_ABYTES;
|
||||
message = (unsigned char *) sodium_malloc(message_len);
|
||||
message2 = (unsigned char *) sodium_malloc(message_len);
|
||||
ciphertext = (unsigned char *) sodium_malloc(ciphertext_len);
|
||||
nonce = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_NPUBBYTES);
|
||||
key = (unsigned char *) sodium_malloc(crypto_aead_aes256gcm_KEYBYTES);
|
||||
|
||||
crypto_aead_aes256gcm_keygen(key);
|
||||
randombytes_buf(nonce, crypto_aead_aes256gcm_NPUBBYTES);
|
||||
randombytes_buf(message, message_len);
|
||||
crypto_aead_aes256gcm_encrypt(ciphertext, NULL, message, message_len,
|
||||
NULL, 0, NULL, nonce, key);
|
||||
if (crypto_aead_aes256gcm_decrypt(message2, NULL, NULL,
|
||||
ciphertext, ciphertext_len,
|
||||
NULL, 0, nonce, key) != 0) {
|
||||
printf("Decryption of random ciphertext failed");
|
||||
}
|
||||
assert(message_len == 0 || memcmp(message, message2, message_len) == 0);
|
||||
sodium_free(key);
|
||||
sodium_free(nonce);
|
||||
sodium_free(ciphertext);
|
||||
sodium_free(message2);
|
||||
sodium_free(message);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
if (crypto_aead_aes256gcm_is_available()) {
|
||||
tv();
|
||||
tv2();
|
||||
}
|
||||
assert(crypto_aead_aes256gcm_keybytes() == crypto_aead_aes256gcm_KEYBYTES);
|
||||
assert(crypto_aead_aes256gcm_nsecbytes() == crypto_aead_aes256gcm_NSECBYTES);
|
||||
|
17
deps/libsodium/test/default/cmptest.h
vendored
17
deps/libsodium/test/default/cmptest.h
vendored
@ -118,16 +118,23 @@ static int mempool_free_all(void)
|
||||
|
||||
static unsigned long long now(void)
|
||||
{
|
||||
struct timeval tp;
|
||||
unsigned long long now;
|
||||
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
|
||||
struct timespec tp;
|
||||
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &tp) != 0) {
|
||||
abort();
|
||||
}
|
||||
return (unsigned long long) tp.tv_sec * 1000000ULL +
|
||||
(unsigned long long) tp.tv_nsec / 1000ULL;
|
||||
#else
|
||||
struct timeval tp;
|
||||
|
||||
if (gettimeofday(&tp, NULL) != 0) {
|
||||
abort();
|
||||
}
|
||||
now = ((unsigned long long) tp.tv_sec * 1000000ULL) +
|
||||
return (unsigned long long) tp.tv_sec * 1000000ULL +
|
||||
(unsigned long long) tp.tv_usec;
|
||||
|
||||
return now;
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
33
deps/libsodium/test/default/misuse.c
vendored
33
deps/libsodium/test/default/misuse.c
vendored
@ -4,12 +4,15 @@
|
||||
|
||||
#ifdef HAVE_CATCHABLE_ABRT
|
||||
# include <signal.h>
|
||||
#ifndef _WIN32
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
static void
|
||||
sigabrt_handler_15(int sig)
|
||||
{
|
||||
(void) sig;
|
||||
exit(0);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
# ifndef SODIUM_LIBRARY_MINIMAL
|
||||
@ -21,7 +24,7 @@ sigabrt_handler_14(int sig)
|
||||
assert(crypto_box_curve25519xchacha20poly1305_easy
|
||||
(guard_page, guard_page, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
|
||||
guard_page, guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -32,7 +35,7 @@ sigabrt_handler_13(int sig)
|
||||
assert(crypto_box_curve25519xchacha20poly1305_easy_afternm
|
||||
(guard_page, guard_page, crypto_stream_xchacha20_MESSAGEBYTES_MAX - 1,
|
||||
guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
# endif
|
||||
|
||||
@ -47,7 +50,7 @@ sigabrt_handler_12(int sig)
|
||||
# endif
|
||||
assert(crypto_pwhash_str_alg((char *) guard_page,
|
||||
"", 0U, 1U, 1U, -1) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -58,7 +61,7 @@ sigabrt_handler_11(int sig)
|
||||
assert(crypto_box_easy(guard_page, guard_page,
|
||||
crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
|
||||
guard_page, guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -69,7 +72,7 @@ sigabrt_handler_10(int sig)
|
||||
assert(crypto_box_easy_afternm(guard_page, guard_page,
|
||||
crypto_stream_xsalsa20_MESSAGEBYTES_MAX,
|
||||
guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -79,7 +82,7 @@ sigabrt_handler_9(int sig)
|
||||
signal(SIGABRT, sigabrt_handler_10);
|
||||
assert(sodium_base642bin(guard_page, 1, (const char *) guard_page, 1,
|
||||
NULL, NULL, NULL, -1) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -89,7 +92,7 @@ sigabrt_handler_8(int sig)
|
||||
signal(SIGABRT, sigabrt_handler_9);
|
||||
assert(sodium_bin2base64((char *) guard_page, 1, guard_page, 1,
|
||||
sodium_base64_VARIANT_ORIGINAL) == NULL);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -99,7 +102,7 @@ sigabrt_handler_7(int sig)
|
||||
signal(SIGABRT, sigabrt_handler_8);
|
||||
assert(sodium_bin2base64((char *) guard_page, 1,
|
||||
guard_page, 1, -1) == NULL);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -108,7 +111,7 @@ sigabrt_handler_6(int sig)
|
||||
(void) sig;
|
||||
signal(SIGABRT, sigabrt_handler_7);
|
||||
assert(sodium_pad(NULL, guard_page, SIZE_MAX, 16, 1) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -119,7 +122,7 @@ sigabrt_handler_5(int sig)
|
||||
assert(crypto_aead_xchacha20poly1305_ietf_encrypt(guard_page, NULL, NULL, UINT64_MAX,
|
||||
NULL, 0, NULL,
|
||||
guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -130,7 +133,7 @@ sigabrt_handler_4(int sig)
|
||||
assert(crypto_aead_chacha20poly1305_ietf_encrypt(guard_page, NULL, NULL, UINT64_MAX,
|
||||
NULL, 0, NULL,
|
||||
guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -141,7 +144,7 @@ sigabrt_handler_3(int sig)
|
||||
assert(crypto_aead_chacha20poly1305_encrypt(guard_page, NULL, NULL, UINT64_MAX,
|
||||
NULL, 0, NULL,
|
||||
guard_page, guard_page) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -154,7 +157,7 @@ sigabrt_handler_2(int sig)
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -164,7 +167,7 @@ sigabrt_handler_1(int sig)
|
||||
signal(SIGABRT, sigabrt_handler_2);
|
||||
assert(crypto_kx_server_session_keys(NULL, NULL, guard_page, guard_page,
|
||||
guard_page) == -1);
|
||||
exit(1);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
int
|
||||
|
22
deps/libsodium/test/default/pwhash_argon2i.c
vendored
22
deps/libsodium/test/default/pwhash_argon2i.c
vendored
@ -290,10 +290,24 @@ str_tests(void)
|
||||
-1) {
|
||||
printf("pwhash_str() with a small opslimit should have failed\n");
|
||||
}
|
||||
if (crypto_pwhash_argon2i_str_verify("$argon2i$m=65536,t=2,p=1c29tZXNhbHQ"
|
||||
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
|
||||
"password", 0x100000000ULL) != -1) {
|
||||
printf("pwhash_str_verify(invalid(0)) failure\n");
|
||||
{
|
||||
const char *str_in_ = "$argon2i$m=65536,t=2,p=1c29tZXNhbHQ"
|
||||
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ";
|
||||
char *str_in = (char *) sodium_malloc(strlen(str_in_) + 1U);
|
||||
|
||||
const char *password_in_ = "password";
|
||||
char *password_in = (char *) sodium_malloc(strlen(password_in_) + 1U);
|
||||
|
||||
memcpy(str_in, str_in_, strlen(str_in_) + 1U);
|
||||
memcpy(password_in, password_in_, strlen(password_in_) + 1U);
|
||||
|
||||
if (crypto_pwhash_argon2i_str_verify(str_in, password_in,
|
||||
0x100000000ULL) != -1) {
|
||||
printf("pwhash_str_verify(invalid(0)) failure\n");
|
||||
}
|
||||
|
||||
sodium_free(password_in);
|
||||
sodium_free(str_in);
|
||||
}
|
||||
if (crypto_pwhash_argon2i_str_verify("$argon2i$m=65536,t=2,p=1c29tZXNhbHQ"
|
||||
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
|
||||
|
22
deps/libsodium/test/default/pwhash_argon2id.c
vendored
22
deps/libsodium/test/default/pwhash_argon2id.c
vendored
@ -304,10 +304,24 @@ str_tests(void)
|
||||
if (crypto_pwhash_str(str_out2, passwd, strlen(passwd), 0, MEMLIMIT) != -1) {
|
||||
printf("pwhash_argon2id_str() with a null opslimit should have failed\n");
|
||||
}
|
||||
if (crypto_pwhash_str_verify("$argon2id$m=65536,t=2,p=1c29tZXNhbHQ"
|
||||
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
|
||||
"password", 0x100000000ULL) != -1) {
|
||||
printf("pwhash_str_verify(invalid(0)) failure\n");
|
||||
{
|
||||
const char *str_in_ ="$argon2id$m=65536,t=2,p=1c29tZXNhbHQ"
|
||||
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ";
|
||||
char *str_in = (char *) sodium_malloc(strlen(str_in_) + 1U);
|
||||
|
||||
const char *password_in_ = "password";
|
||||
char *password_in = (char *) sodium_malloc(strlen(password_in_) + 1U);
|
||||
|
||||
memcpy(str_in, str_in_, strlen(str_in_) + 1U);
|
||||
memcpy(password_in, password_in_, strlen(password_in_) + 1U);
|
||||
|
||||
if (crypto_pwhash_argon2i_str_verify(str_in, password_in,
|
||||
0x100000000ULL) != -1) {
|
||||
printf("pwhash_str_verify(invalid(0)) failure\n");
|
||||
}
|
||||
|
||||
sodium_free(password_in);
|
||||
sodium_free(str_in);
|
||||
}
|
||||
if (crypto_pwhash_str_verify("$argon2id$m=65536,t=2,p=1c29tZXNhbHQ"
|
||||
"$9sTbSlTio3Biev89thdrlKKiCaYsjjYVJxGAL3swxpQ",
|
||||
|
9
deps/libsodium/test/default/run.sh
vendored
Executable file
9
deps/libsodium/test/default/run.sh
vendored
Executable file
@ -0,0 +1,9 @@
|
||||
#! /bin/sh
|
||||
|
||||
find . -type f -perm -100 -print | grep -v run.sh | sort | while read -r x; do
|
||||
echo "[$x]"
|
||||
if ! "$x"; then
|
||||
echo "*** [$x] FAILED" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
6
deps/libsodium/test/default/sodium_core.c
vendored
6
deps/libsodium/test/default/sodium_core.c
vendored
@ -31,11 +31,11 @@ main(void)
|
||||
(void) sodium_runtime_has_rdrand();
|
||||
|
||||
sodium_set_misuse_handler(misuse_handler);
|
||||
#ifndef __EMSCRIPTEN__
|
||||
#if defined(__EMSCRIPTEN__) || defined(__wasm__) || defined(BENCHMARKS)
|
||||
printf("misuse_handler()\n");
|
||||
#else
|
||||
sodium_misuse();
|
||||
printf("Misuse handler returned\n");
|
||||
#else
|
||||
printf("misuse_handler()\n");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
5
deps/libsodium/test/default/sodium_utils2.c
vendored
5
deps/libsodium/test/default/sodium_utils2.c
vendored
@ -6,6 +6,9 @@
|
||||
#ifdef HAVE_CATCHABLE_SEGV
|
||||
# include <signal.h>
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define TEST_NAME "sodium_utils2"
|
||||
#include "cmptest.h"
|
||||
@ -36,7 +39,7 @@ segv_handler(int sig)
|
||||
signal(SIGABRT, SIG_DFL);
|
||||
# endif
|
||||
#endif
|
||||
exit(0);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
|
5
deps/libsodium/test/default/sodium_utils3.c
vendored
5
deps/libsodium/test/default/sodium_utils3.c
vendored
@ -6,6 +6,9 @@
|
||||
#ifdef HAVE_CATCHABLE_SEGV
|
||||
# include <signal.h>
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define TEST_NAME "sodium_utils3"
|
||||
#include "cmptest.h"
|
||||
@ -32,7 +35,7 @@ segv_handler(int sig)
|
||||
signal(SIGABRT, SIG_DFL);
|
||||
# endif
|
||||
#endif
|
||||
exit(0);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
int
|
||||
|
104
deps/libsodium/test/default/wasi-test-wrapper.sh
vendored
104
deps/libsodium/test/default/wasi-test-wrapper.sh
vendored
@ -1,7 +1,5 @@
|
||||
#! /bin/sh
|
||||
|
||||
MAX_MEMORY_TESTS="67108864"
|
||||
|
||||
unset LDFLAGS
|
||||
unset CFLAGS
|
||||
|
||||
@ -9,36 +7,6 @@ if command -v wasm-opt >/dev/null; then
|
||||
wasm-opt -O4 -o "${1}.tmp" "$1" && mv -f "${1}.tmp" "$1"
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wavm" ]; then
|
||||
if command -v wavm >/dev/null; then
|
||||
wavm run --abi=wasi "$1" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmtime" ]; then
|
||||
if command -v wasmtime >/dev/null; then
|
||||
wasmtime run --dir=. "$1" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmer" ]; then
|
||||
if command -v wasmer >/dev/null; then
|
||||
wasmer run "$1" "--${WASMER_BACKEND:-cranelift}" --dir=. && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasm3" ]; then
|
||||
if command -v wasm3 >/dev/null; then
|
||||
wasm3 "$1" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "iwasm" ]; then
|
||||
if iwasm | grep -qi wasi >/dev/null 2>&1; then
|
||||
iwasm "$1" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmedge" ]; then
|
||||
if command -v wasmedgec >/dev/null && command -v wasmedge >/dev/null; then
|
||||
wasmedgec "$1" "${1}.so" &&
|
||||
@ -48,22 +16,84 @@ if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmedge" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmer" ]; then
|
||||
if command -v wasmer >/dev/null; then
|
||||
wasmer run "$1" "--${WASMER_BACKEND:-cranelift}" --dir=. && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmtime" ]; then
|
||||
if command -v wasmtime >/dev/null; then
|
||||
wasmtime run --dir=. "$1" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wavm" ]; then
|
||||
if command -v wavm >/dev/null; then
|
||||
wavm run --abi=wasi "$1" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "bun" ]; then
|
||||
if echo | bun help >/dev/null 2>&1; then
|
||||
{
|
||||
echo "import fs from 'fs'; import { init, WASI } from '@wasmer/wasi';"
|
||||
echo "await init();"
|
||||
echo "const wasi = new WASI({args: process.argv, env: process.env, preopens: {'.':'/'}});"
|
||||
echo "await (async function() {"
|
||||
echo " const wasm = await WebAssembly.compile(fs.readFileSync('${1}'));"
|
||||
echo " await wasi.instantiate(wasm, {});"
|
||||
echo " wasi.start();"
|
||||
echo " console.log(wasi.getStdoutString());"
|
||||
echo "})().catch(e => { console.error(e); process.exit(1); });"
|
||||
} >"${1}.mjs"
|
||||
bun run "${1}.mjs" 2>/tmp/err &&
|
||||
rm -f "${1}.mjs" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "node" ]; then
|
||||
if echo | node --experimental-wasi-unstable-preview1 >/dev/null 2>&1; then
|
||||
{
|
||||
echo "import fs from 'fs'; import { WASI } from 'wasi';"
|
||||
echo "const wasi = new WASI({args: process.argv, env: process.env, preopens: {'.':'.'}});"
|
||||
echo "const importObject = { wasi_snapshot_preview1: wasi.wasiImport };"
|
||||
echo "const wasm = await WebAssembly.compile(fs.readFileSync('${1}'));"
|
||||
echo "const instance = await WebAssembly.instantiate(wasm, importObject);"
|
||||
echo "wasi.start(instance);"
|
||||
echo "await (async function() {"
|
||||
echo " const wasm = await WebAssembly.compile(fs.readFileSync('${1}'));"
|
||||
echo " const instance = await WebAssembly.instantiate(wasm, importObject);"
|
||||
echo " wasi.start(instance);"
|
||||
echo "})().catch(e => { console.error(e); process.exit(1); });"
|
||||
} >"${1}.mjs"
|
||||
cat "${1}.mjs" >/tmp/a
|
||||
node --experimental-wasi-unstable-preview1 "${1}.mjs" 2>/tmp/err &&
|
||||
node --experimental-wasm-bigint --experimental-wasi-unstable-preview1 "${1}.mjs" 2>/tmp/err &&
|
||||
rm -f "${1}.mjs" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasm3" ]; then
|
||||
if command -v wasm3 >/dev/null; then
|
||||
wasm3 "$1" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "iwasm" ]; then
|
||||
if command -v iwasm >/dev/null; then
|
||||
if iwasm | grep -qi wasi >/dev/null 2>&1; then
|
||||
if wamrc --version; then
|
||||
wamrc -o "${1}.o" "$1" >/dev/null &&
|
||||
iwasm --dir=. "${1}.o" && exit 0
|
||||
else
|
||||
iwasm --dir=. "$1" && exit 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wazero" ]; then
|
||||
if command -v wazero >/dev/null; then
|
||||
wazero run -mount .:/ "$1" && exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$WASI_RUNTIME" ] || [ "$WASI_RUNTIME" = "wasmer-js" ]; then
|
||||
if command -v wasmer-js >/dev/null; then
|
||||
wasmer-js run "$1" --dir=. && exit 0
|
||||
|
Reference in New Issue
Block a user