WasmEngine/patch/0001-add-experiments-to-tar.patch
2022-08-10 09:29:37 +08:00

668 lines
20 KiB
Diff

From 6d7bed672d69a3fb60d98ff84182ff5eceb0c452 Mon Sep 17 00:00:00 2001
From: build <build@obs.com>
Date: Tue, 9 Aug 2022 19:06:59 +0800
Subject: [PATCH] add experiments to tar
---
experiments/application/add_one/Cargo.lock | 7 +
experiments/application/add_one/Cargo.toml | 11 ++
experiments/application/add_one/src/lib.rs | 4 +
.../authentication-wasi/Cargo.lock | 74 +++++++++
.../authentication-wasi/Cargo.toml | 10 ++
.../authentication-wasi/src/main.rs | 68 ++++++++
.../application/authentication/Cargo.lock | 154 ++++++++++++++++++
.../application/authentication/Cargo.toml | 18 ++
.../application/authentication/src/lib.rs | 91 +++++++++++
.../application/echo-string/Cargo.lock | 7 +
.../application/echo-string/Cargo.toml | 11 ++
.../application/echo-string/src/lib.rs | 5 +
experiments/application/fibonacci/Cargo.lock | 7 +
experiments/application/fibonacci/Cargo.toml | 8 +
experiments/application/fibonacci/src/main.rs | 18 ++
experiments/application/hello/Cargo.lock | 7 +
experiments/application/hello/Cargo.toml | 8 +
experiments/application/hello/src/main.rs | 3 +
18 files changed, 511 insertions(+)
create mode 100644 experiments/application/add_one/Cargo.lock
create mode 100644 experiments/application/add_one/Cargo.toml
create mode 100644 experiments/application/add_one/src/lib.rs
create mode 100644 experiments/application/authentication-wasi/Cargo.lock
create mode 100644 experiments/application/authentication-wasi/Cargo.toml
create mode 100644 experiments/application/authentication-wasi/src/main.rs
create mode 100644 experiments/application/authentication/Cargo.lock
create mode 100644 experiments/application/authentication/Cargo.toml
create mode 100644 experiments/application/authentication/src/lib.rs
create mode 100644 experiments/application/echo-string/Cargo.lock
create mode 100644 experiments/application/echo-string/Cargo.toml
create mode 100644 experiments/application/echo-string/src/lib.rs
create mode 100644 experiments/application/fibonacci/Cargo.lock
create mode 100644 experiments/application/fibonacci/Cargo.toml
create mode 100644 experiments/application/fibonacci/src/main.rs
create mode 100644 experiments/application/hello/Cargo.lock
create mode 100644 experiments/application/hello/Cargo.toml
create mode 100644 experiments/application/hello/src/main.rs
diff --git a/experiments/application/add_one/Cargo.lock b/experiments/application/add_one/Cargo.lock
new file mode 100644
index 00000000..f33516b5
--- /dev/null
+++ b/experiments/application/add_one/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "authentication"
+version = "0.1.0"
diff --git a/experiments/application/add_one/Cargo.toml b/experiments/application/add_one/Cargo.toml
new file mode 100644
index 00000000..e218947f
--- /dev/null
+++ b/experiments/application/add_one/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "authentication"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+
+[lib]
+crate-type = ["cdylib"]
diff --git a/experiments/application/add_one/src/lib.rs b/experiments/application/add_one/src/lib.rs
new file mode 100644
index 00000000..da5a5692
--- /dev/null
+++ b/experiments/application/add_one/src/lib.rs
@@ -0,0 +1,4 @@
+#[no_mangle]
+pub extern "C" fn add_one(x: i32) -> i32 {
+ x + 1
+}
\ No newline at end of file
diff --git a/experiments/application/authentication-wasi/Cargo.lock b/experiments/application/authentication-wasi/Cargo.lock
new file mode 100644
index 00000000..7aa6e8f4
--- /dev/null
+++ b/experiments/application/authentication-wasi/Cargo.lock
@@ -0,0 +1,74 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "another_json_minimal"
+version = "0.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77ba8341e1396c8a379f62de1b47f31256f2fe0846f5f95e9c60014d2102d9bd"
+
+[[package]]
+name = "authentication-wasi"
+version = "0.1.0"
+dependencies = [
+ "another_json_minimal",
+ "md-5",
+]
+
+[[package]]
+name = "block-buffer"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
+dependencies = [
+ "generic-array",
+]
+
+[[package]]
+name = "digest"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
+dependencies = [
+ "generic-array",
+]
+
+[[package]]
+name = "generic-array"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
+dependencies = [
+ "typenum",
+ "version_check",
+]
+
+[[package]]
+name = "md-5"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
+dependencies = [
+ "block-buffer",
+ "digest",
+ "opaque-debug",
+]
+
+[[package]]
+name = "opaque-debug"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
+
+[[package]]
+name = "typenum"
+version = "1.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
+
+[[package]]
+name = "version_check"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
diff --git a/experiments/application/authentication-wasi/Cargo.toml b/experiments/application/authentication-wasi/Cargo.toml
new file mode 100644
index 00000000..b862de82
--- /dev/null
+++ b/experiments/application/authentication-wasi/Cargo.toml
@@ -0,0 +1,10 @@
+[package]
+name = "authentication-wasi"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+md-5 = { version="0.9", default-features = false }
+another_json_minimal = "0.0.2"
diff --git a/experiments/application/authentication-wasi/src/main.rs b/experiments/application/authentication-wasi/src/main.rs
new file mode 100644
index 00000000..df00eae3
--- /dev/null
+++ b/experiments/application/authentication-wasi/src/main.rs
@@ -0,0 +1,68 @@
+use another_json_minimal::Json;
+use md5::{Digest, Md5};
+use std::{env, fmt::Write};
+
+#[derive(Default)]
+struct Response {
+ status: String,
+ body: String,
+}
+
+fn main() {
+ let args: Vec<String> = env::args().collect();
+ if args.len() != 3 {
+ eprintln!("usage: authentication <URI> <BODY> <SECRET>");
+ return;
+ }
+
+ let arg_uri = &args[0];
+ let arg_body = &args[1];
+ let arg_secret = &args[2];
+
+ let arg_func = "argfunc";
+ let content = format!("{}#{}#{}", arg_uri, arg_body, arg_func);
+
+ // create a Md5 hasher instance
+ let mut hasher = Md5::new();
+ // process input message
+ hasher.update(content.as_bytes());
+ let result = hasher.finalize();
+
+ let slice = result.as_slice();
+ let mut hash = String::with_capacity(slice.len() * 2);
+ for &b in slice {
+ write!(&mut hash, "{:02x}", b).unwrap();
+ }
+
+ let mut r: Response = Response::default();
+ let html: String;
+ if &hash == arg_secret {
+ r.status = "200".to_string();
+ html = "<html><h1>Auth Pass!</h1><p>hash ".to_owned() + &hash + "</p></html>";
+ r.body = html;
+ } else {
+ r.status = "403".to_string();
+ html = "<html><h1>Auth Forbidden!</h1><p>hash ".to_owned()
+ + &hash
+ + " secret "
+ + &arg_secret
+ + "</p></html>";
+ r.body = html;
+ }
+
+ //we use complicated another_json_minimal temporary
+ let mut json = Json::new();
+ let status = Json::OBJECT {
+ name: String::from("status"),
+ value: Box::new(Json::STRING(String::from(&r.status))),
+ };
+ json.add(status);
+ let body = Json::OBJECT {
+ name: String::from("body"),
+ value: Box::new(Json::STRING(String::from(&r.body))),
+ };
+ json.add(body);
+ let serialized = json.print();
+
+ println!("{}", serialized);
+}
diff --git a/experiments/application/authentication/Cargo.lock b/experiments/application/authentication/Cargo.lock
new file mode 100644
index 00000000..9d96c7b1
--- /dev/null
+++ b/experiments/application/authentication/Cargo.lock
@@ -0,0 +1,154 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "another_json_minimal"
+version = "0.0.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "77ba8341e1396c8a379f62de1b47f31256f2fe0846f5f95e9c60014d2102d9bd"
+
+[[package]]
+name = "authentication"
+version = "0.1.0"
+dependencies = [
+ "another_json_minimal",
+ "md-5",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "block-buffer"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
+dependencies = [
+ "generic-array",
+]
+
+[[package]]
+name = "digest"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
+dependencies = [
+ "generic-array",
+]
+
+[[package]]
+name = "generic-array"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817"
+dependencies = [
+ "typenum",
+ "version_check",
+]
+
+[[package]]
+name = "itoa"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
+
+[[package]]
+name = "md-5"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
+dependencies = [
+ "block-buffer",
+ "digest",
+ "opaque-debug",
+]
+
+[[package]]
+name = "opaque-debug"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.34"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1"
+dependencies = [
+ "unicode-xid",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "ryu"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
+
+[[package]]
+name = "serde"
+version = "1.0.132"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b9875c23cf305cd1fd7eb77234cbb705f21ea6a72c637a5c6db5fe4b8e7f008"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.132"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ecc0db5cb2556c0e558887d9bbdcf6ac4471e83ff66cf696e5419024d1606276"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.73"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5"
+dependencies = [
+ "itoa",
+ "ryu",
+ "serde",
+]
+
+[[package]]
+name = "syn"
+version = "1.0.82"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-xid",
+]
+
+[[package]]
+name = "typenum"
+version = "1.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
+
+[[package]]
+name = "unicode-xid"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
+
+[[package]]
+name = "version_check"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
diff --git a/experiments/application/authentication/Cargo.toml b/experiments/application/authentication/Cargo.toml
new file mode 100644
index 00000000..47729792
--- /dev/null
+++ b/experiments/application/authentication/Cargo.toml
@@ -0,0 +1,18 @@
+[package]
+name = "authentication"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+md-5 = { version="0.9", default-features = false }
+another_json_minimal = "0.0.2"
+
+[lib]
+crate-type = ["cdylib"]
+
+[dev-dependencies]
+serde = { version = "1.0", features = ["derive"] }
+serde_json = "1.0"
+
diff --git a/experiments/application/authentication/src/lib.rs b/experiments/application/authentication/src/lib.rs
new file mode 100644
index 00000000..0aa5d980
--- /dev/null
+++ b/experiments/application/authentication/src/lib.rs
@@ -0,0 +1,91 @@
+use std::fmt::Write;
+
+use another_json_minimal::Json;
+use md5::{Digest, Md5};
+
+#[derive(Default)]
+struct Response {
+ status: String,
+ body: String,
+}
+
+#[no_mangle]
+pub fn authentication(data: &str) -> (*mut u8, usize) {
+ // fulfill data p
+ let arg_func = "argfunc";
+ let json = match Json::parse(data.as_bytes()) {
+ Ok(json) => json,
+ Err((position, message)) => {
+ panic!("`{}` at position `{}`!!!", position, message);
+ }
+ };
+ let arg_uri = json.get("arg_uri").unwrap().print();
+ let arg_body = json.get("arg_body").unwrap().print();
+ let arg_secret = json.get("arg_secret").unwrap().print();
+
+ let content = format!("{}#{}#{}", arg_uri, arg_body, arg_func);
+
+ // create a Md5 hasher instance
+ let mut hasher = Md5::new();
+ // process input message
+ hasher.update(content.as_bytes());
+ let result = hasher.finalize();
+
+ let slice = result.as_slice();
+ let mut hash = String::with_capacity(slice.len() * 2);
+ for &b in slice {
+ write!(&mut hash, "{:02x}", b).unwrap();
+ }
+
+ let mut r: Response = Response::default();
+ let html: String;
+ if hash == arg_secret {
+ r.status = "200".to_string();
+ html = "<html><h1>Auth Pass!</h1><p>hash ".to_owned() + &hash + "</p></html>";
+ r.body = html;
+ } else {
+ r.status = "403".to_string();
+ html = "<html><h1>Auth Forbidden!</h1><p>hash ".to_owned()
+ + &hash
+ + " secret "
+ + &arg_secret
+ + "</p></html>";
+ r.body = html;
+ }
+
+ //we use complicated another_json_minimal temporary
+ let mut json = Json::new();
+ let status = Json::OBJECT {
+ name: String::from("status"),
+ value: Box::new(Json::STRING(String::from(&r.status))),
+ };
+
+ json.add(status);
+ let body = Json::OBJECT {
+ name: String::from("body"),
+ value: Box::new(Json::STRING(String::from(&r.body))),
+ };
+ json.add(body);
+
+ let mut serialized = json.print();
+ (serialized.as_mut_ptr(), serialized.len())
+}
+
+#[test]
+fn test_authentication() {
+ use serde::{Deserialize, Serialize};
+ #[derive(Deserialize, Serialize, Default)]
+ struct Data {
+ arg_uri: String,
+ arg_body: String,
+ arg_secret: String,
+ }
+ let p: Data = Data {
+ arg_uri: "uri".to_string(),
+ arg_body: "body".to_string(),
+ arg_secret: "secrect".to_string(),
+ };
+
+ let serialized = serde_json::to_string(&p).unwrap();
+ let (_p, _l) = authentication(&serialized);
+}
diff --git a/experiments/application/echo-string/Cargo.lock b/experiments/application/echo-string/Cargo.lock
new file mode 100644
index 00000000..18266ede
--- /dev/null
+++ b/experiments/application/echo-string/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "echo-string"
+version = "0.1.0"
diff --git a/experiments/application/echo-string/Cargo.toml b/experiments/application/echo-string/Cargo.toml
new file mode 100644
index 00000000..51c4cfa7
--- /dev/null
+++ b/experiments/application/echo-string/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "echo-string"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+
+[lib]
+crate-type = ["cdylib"]
diff --git a/experiments/application/echo-string/src/lib.rs b/experiments/application/echo-string/src/lib.rs
new file mode 100644
index 00000000..56f38f7e
--- /dev/null
+++ b/experiments/application/echo-string/src/lib.rs
@@ -0,0 +1,5 @@
+#[no_mangle]
+pub fn echo_string(input: &str) -> (*const u8, usize) {
+ let r = input.to_owned() + "b";
+ (r.as_ptr(), r.len())
+}
diff --git a/experiments/application/fibonacci/Cargo.lock b/experiments/application/fibonacci/Cargo.lock
new file mode 100644
index 00000000..06a56e63
--- /dev/null
+++ b/experiments/application/fibonacci/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "fibonacci"
+version = "0.1.0"
diff --git a/experiments/application/fibonacci/Cargo.toml b/experiments/application/fibonacci/Cargo.toml
new file mode 100644
index 00000000..9cd048ef
--- /dev/null
+++ b/experiments/application/fibonacci/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "fibonacci"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/experiments/application/fibonacci/src/main.rs b/experiments/application/fibonacci/src/main.rs
new file mode 100644
index 00000000..4c6c79fb
--- /dev/null
+++ b/experiments/application/fibonacci/src/main.rs
@@ -0,0 +1,18 @@
+use std::env;
+
+fn fib(n: u64) -> u64 {
+ if n <= 1 {
+ return n;
+ }
+ fib(n - 1) + fib(n - 2)
+}
+
+fn main() {
+ let args: Vec<String> = env::args().collect();
+
+ if args.len() != 1 {
+ eprintln!("only single parameter is needed");
+ return;
+ }
+ println!("{}", fib(args[0].parse::<u64>().unwrap()))
+}
diff --git a/experiments/application/hello/Cargo.lock b/experiments/application/hello/Cargo.lock
new file mode 100644
index 00000000..c3aedd77
--- /dev/null
+++ b/experiments/application/hello/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "hello"
+version = "0.1.0"
diff --git a/experiments/application/hello/Cargo.toml b/experiments/application/hello/Cargo.toml
new file mode 100644
index 00000000..fb1ec2c9
--- /dev/null
+++ b/experiments/application/hello/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "hello"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/experiments/application/hello/src/main.rs b/experiments/application/hello/src/main.rs
new file mode 100644
index 00000000..b3dbf1ae
--- /dev/null
+++ b/experiments/application/hello/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, Budda!");
+}
--
2.27.0