Compare commits

...

584 Commits

Author SHA1 Message Date
b73fd9e64e feat: add ml kem demo 2025-09-24 23:15:32 +08:00
5ef3b4d3e6 feat: add __security/keyring-demo/ 2025-09-14 17:52:26 +08:00
3dda4e8e5b feat: add pingora-demo 2025-08-17 15:50:54 +08:00
a1024943ff feat: update serde json test 2025-08-03 16:48:22 +08:00
9eba818de9 feat: update serde json 2025-08-03 16:43:05 +08:00
814b5e9442 feat: add clap-test-3 2025-08-03 16:33:52 +08:00
6d7273c6a3 feat: add crypto bcrypt issue test 2025-07-12 21:25:42 +08:00
bd9ea78e53 feat: add __term/tui-markup-demo/ 2025-07-12 18:24:46 +08:00
73d58350c2 feat: udpates 2025-07-12 13:23:01 +08:00
e45d14498c feat: add __wasm/rust-wasm-plugins-examples/ 2025-07-12 13:22:38 +08:00
f2fd57c342 feat: add bc1-btc-address 2025-07-03 00:27:01 +08:00
ed54a7e6ef feat: add orion-demo 2025-06-28 23:22:26 +08:00
7c0865fafd feat: add orion-demo 2025-06-28 23:22:11 +08:00
Hatter Jiang
6e681f0ba1 feat: updates 2025-06-28 09:59:35 +08:00
Hatter Jiang
0dcbb75879 feat: updates 2025-06-28 09:58:50 +08:00
Hatter Jiang
ad25ed2453 feat: add passkey-rs 2025-06-28 09:50:50 +08:00
Hatter Jiang
0491407e58 feat: add passkey-rs 2025-06-28 09:50:38 +08:00
564977aad7 feat: add __alloc 2025-06-27 23:11:48 +08:00
c966ad621d feat: add eth-address 2025-06-25 00:34:06 +08:00
Jiang Hatter
9982409535 feat: reset 2025-06-15 20:10:32 +08:00
Jiang Hatter
9e8cbf557d feat: add tcp-connect-reset 2025-06-15 20:08:54 +08:00
ada9691adc feat: add axum demo 2025-03-16 22:10:36 +08:00
48ad5122f2 add dns-server-tutorial 2025-03-08 21:24:00 +08:00
10672a86b1 feat: rename comfy table 2025-01-06 23:55:15 +08:00
744b16af6c feat: add __args 2025-01-01 09:54:00 +08:00
2ff99a832d feat: update jose-test 2024-11-14 00:23:44 +08:00
4f048b3981 feat: update jose-test 2024-11-14 00:18:55 +08:00
49d91c0dc1 feat: update jose-test 2024-11-14 00:17:29 +08:00
9d9575843c feat: update jose-test 2024-11-14 00:14:25 +08:00
1eb7aeab42 feat: update jose-test 2024-11-14 00:04:36 +08:00
cc4c793835 feat: update jose-test 2024-11-13 23:54:06 +08:00
1b59475ab9 feat: udpate jose-test 2024-11-13 23:10:28 +08:00
0f85300a74 feat: update jose-test 2024-11-13 22:46:58 +08:00
e4f4e70951 feat: rsa jwk 2024-11-13 01:19:06 +08:00
ae8747de70 feat: rsa jwk 2024-11-13 01:14:34 +08:00
2a9d6dfaac feat: jose 2024-11-13 00:15:30 +08:00
9b2c40d662 feat: updates 2024-11-10 22:07:46 +08:00
04a58e9f66 feat: add jost-test 2024-11-10 21:58:37 +08:00
1ae6bb6737 feat: update crypto/aes_ctr_test 2024-08-31 19:39:19 +08:00
8717ca7594 feat: udpate __crypto/aes_ctr_test 2024-08-31 17:35:14 +08:00
09129b38a1 feat: udpate __crypto/aes_ctr_test 2024-08-31 17:34:13 +08:00
7f0e18bbe4 feat: add __crypto/aes_ctr_test/ 2024-08-31 17:11:16 +08:00
22344b6d96 feat: add native db demo 2024-05-04 11:15:28 +08:00
f107f82b7c feat: add concurrent/waitgroup demo 2024-05-01 23:53:06 +08:00
50fa9b5179 feat: add duckdb test 2024-04-13 23:23:22 +08:00
46bbd4859e feat: add duckdb test 2024-04-13 23:23:09 +08:00
e5a56888ad feat: add asn1-der-test 2024-03-30 21:42:04 +08:00
6b752c4a77 feat: add asn1-der-test 2024-03-30 21:33:59 +08:00
18e7545bcf feat: add tests asn1-der-test 2024-03-30 21:33:44 +08:00
37f94aad3f feat: add __crypto/liboqs-rust-demo 2024-03-24 13:30:51 +08:00
f5a41fdb02 feat: add __network/html-crawl-parse, __wasm/wasmtime-serde-demo 2024-03-24 13:15:59 +08:00
8adc5a58bc feat: update readme 2024-03-24 11:32:42 +08:00
31ba44c45e feat: add tokio-cpu-affinity 2024-03-24 11:32:07 +08:00
a3c45895e1 feat: add rust-rawsock-demo,tokio-kcp-demo 2024-03-24 10:40:50 +08:00
051eb5fecc feat: add rust-rawsock-demo 2024-03-24 10:15:37 +08:00
930c35abff feat: add pi 2024-03-24 00:30:31 +08:00
e5748b1e41 feat: add async-fn 2024-03-23 23:34:02 +08:00
bb36536347 feat: add async fn 2024-03-09 13:14:31 +08:00
0d1e08fcd1 feat: add tests 2024-01-20 21:54:12 +08:00
47830618e4 feat: add dialoguer-demo 2024-01-11 00:34:20 +08:00
fe5c16450c feat: update tests 2024-01-08 00:16:29 +08:00
97baed2e2a feat: add tests 2024-01-07 23:51:29 +08:00
7ec4c4a526 feat: add tests 2024-01-07 18:26:09 +08:00
526dd4172b feat: add der_parser_test 2023-11-25 23:40:00 +08:00
11278926bf feat: upate ed25519 verify 2023-10-14 00:30:18 +08:00
d41b499913 feat: add ed25519 verify 2023-10-14 00:29:03 +08:00
55e5b732f6 feat: age 2023-10-05 18:11:31 +08:00
05afe67de7 feat: ecdh with openpgp card x25519 2023-10-05 17:25:25 +08:00
a32ef922c7 feat: updates 2023-09-09 00:33:22 +08:00
11aaa45456 feat: update dependencies 2023-08-26 02:23:18 +08:00
e8b5167490 feat: update justfile 2023-08-26 01:43:59 +08:00
607b78b6b8 feat: add justfile 2023-08-26 01:35:28 +08:00
49c352e84c feat: update version 2023-08-26 01:01:50 +08:00
a26e3e1ffe feat: add secretshare 2023-08-26 00:05:54 +08:00
27ee89dd8a feat: update aegis-test 2023-08-19 23:54:16 +08:00
45eb023741 feat: updat eaegis test 2023-08-19 23:34:41 +08:00
a321aae4d2 feat: aegis-test 2023-08-19 17:30:51 +08:00
12a91e6103 feat: add tests 2023-08-09 01:02:37 +08:00
8904df2753 feat: update fetch-rs 2023-06-11 22:36:04 +08:00
49fefb745c feat: update fetch-rs 2023-06-11 22:21:29 +08:00
38b8fbe37f feat: udpate fetch-rs 2023-06-04 14:20:40 +08:00
8aba71a72b feat: update fetch-rs 2023-06-04 14:09:25 +08:00
c259d6c102 feat: add fetch-rs 2023-06-04 13:54:54 +08:00
2b71b456a3 feat: add cursive-demo/README.md 2023-04-15 21:20:43 +08:00
04914f33ab feat: add cursive-demo 2023-04-15 21:19:55 +08:00
4fb7c049b5 feat: add __crypto README.md 2023-04-15 14:44:50 +08:00
00bedd5ce1 feat: add network ngrok-demo 2023-04-01 20:34:13 +08:00
1defe5958f feat: add object-demo 2023-03-17 00:36:18 +08:00
e7f03687dc feat: use fake random 2023-03-12 22:05:55 +08:00
f7b23d0943 feat: update yubikey-rs-demo 2023-03-12 20:06:10 +08:00
12e24652b7 feat: outputs serial 2023-03-12 08:44:53 +08:00
591154f331 feat: output public key 2023-03-11 14:01:14 +08:00
390a142561 feat: udpate reamde 2023-03-11 11:50:47 +08:00
0f94dae70a feat: read flot meta 2023-03-11 11:50:07 +08:00
8e03973dda feat: add yubikey-rs-demo 2023-03-11 00:32:57 +08:00
9e06880a81 feat: add __network/ipnet-demo 2023-02-26 22:51:19 +08:00
9ec922f965 feat: add __compress/zstd-demo 2023-02-26 22:39:56 +08:00
651c96d658 feat: add rpgp-demo 2023-02-26 16:13:16 +08:00
88c931bc5c feat: add comment 2023-02-18 00:26:45 +08:00
c95a566c58 feat: add aes gcm crypto 2023-02-18 00:12:33 +08:00
8803a8500a feat: add crypto2-demo 2023-02-12 13:37:29 +08:00
d1b1132cc3 feat: add nix demo 2023-01-19 23:23:44 +08:00
2e256c32f8 feat: add reference rust-memalloc 2023-01-19 23:10:49 +08:00
f73e6ce7f8 feat: readme 2023-01-19 23:02:39 +08:00
ead7eddf1f feat: add malloc&free 1 2023-01-19 23:00:54 +08:00
e44aa7f60c feat: update memory 2023-01-19 22:22:47 +08:00
137e04eda0 feat: add __internal/memory 2023-01-19 22:19:54 +08:00
6e4277a53b feat: update epoch interuppt 2023-01-19 00:45:26 +08:00
c173ce8dba feat: add example hello 2023-01-19 00:13:30 +08:00
33cd9b007c feat: add example multi value 2023-01-19 00:11:43 +08:00
e6b985a695 feat: add examples gcd, memory 2023-01-19 00:01:28 +08:00
3eefa3cba1 feat: update examples 2023-01-18 23:57:29 +08:00
d514f80f64 feat: update example4 2023-01-18 23:48:15 +08:00
8862192778 feat: add example4 2023-01-18 23:46:14 +08:00
1bc45c72b1 feat: add example3 2023-01-18 23:34:02 +08:00
14d22ef4ef feat: update wasmtime version 2023-01-18 23:31:15 +08:00
3a98d7da3f feat: add humantime-demo 2023-01-17 23:32:05 +08:00
570b578596 feat: add __fuse/README.md 2023-01-08 12:03:00 +08:00
8f6805f3e3 feat: add crypt4ghfs-rust 2023-01-08 11:48:40 +08:00
c8837b21f6 feat: add sharmir demo 2023-01-01 20:54:02 +08:00
93a8832b36 feat: add daemonize demo 2023-01-01 20:40:01 +08:00
aa50d63aec feat: add a histrical wit-bindgen 2023-01-01 00:25:48 +08:00
01e8f5a959 feat: add fuel 2022-12-31 11:44:33 +08:00
ea815f1c0d feat: udpate readme 2022-12-31 10:35:55 +08:00
34c04da05d feat: update readme, add regexp test 2022-12-31 00:16:59 +08:00
a0359637e2 feat: update boa_engine 2022-12-31 00:01:47 +08:00
2a3d63d1e8 feat: add readme 2022-12-30 23:04:15 +08:00
448f7e42ac fix: compile warning 2022-12-30 22:24:44 +08:00
060c6b2263 feat: add calltoc 2022-12-30 13:04:31 +08:00
b98542fff3 feat: update lock 2022-12-29 21:02:05 +08:00
1098220058 feat: extism works 2022-12-04 15:00:28 +08:00
78561aec5b feat: extism 2022-12-04 14:40:25 +08:00
78db54db6c feat: add extism 2022-12-04 14:25:05 +08:00
4efe9d4a12 feat: update readme 2022-11-20 20:41:55 +08:00
820417832b feat: add external vcard-cli 2022-11-20 20:39:30 +08:00
8979029e29 feat: add fast-qr 2022-11-20 20:36:56 +08:00
3a4d6b2d62 feat: add efficient_sm2 2022-11-13 20:21:57 +08:00
acb1878e8d feat: update dubbo-rust readme 2022-10-29 00:40:01 +08:00
c18b025ac4 feat: update readme 2022-10-29 00:38:54 +08:00
cb12afd2da feat: add __rpc 2022-10-28 00:50:48 +08:00
6873d68129 feat: update README 2022-10-16 21:16:56 +08:00
a49d639b18 feat: add keychain-services 2022-10-16 21:16:13 +08:00
9ab7685f2d feat: add security-framework 2022-10-16 19:45:34 +08:00
e972998e09 feat: add highwayhash 2022-10-07 23:05:32 +08:00
2f4df9395d feat: add icalendar 2022-10-07 20:58:32 +08:00
2bb467898e feat: update hatter test 2022-10-07 14:07:51 +08:00
fe3f2af4e9 feat: add hatter-test/cargo lock 2022-10-07 00:36:39 +08:00
5337f7f61d feat: add hatter-test 2022-10-07 00:31:00 +08:00
20cd2d6877 feat: add __shuttle 2022-10-07 00:24:42 +08:00
50a4d71ad8 feat: add secrets 2022-10-03 18:34:27 +08:00
dc213c4055 feat: add java&rust 2022-09-26 00:23:56 +08:00
36e1609002 feat: update ssh-rs 2022-09-04 16:54:01 +08:00
338d2720ac feat: add ssh-rs 2022-09-02 23:58:14 +08:00
bce6338c2b feat: update readme 2022-08-28 11:52:08 +08:00
4c5d44d553 chore: reorg 2022-08-28 11:49:05 +08:00
0b0d4f2f9c feat: add __lang/rusty_jsc/, build_readme.rs 2022-08-28 11:40:00 +08:00
5d1372905f feat: update quinn 2022-08-25 01:35:27 +08:00
60eb54ca49 feat: works 2022-08-25 00:52:26 +08:00
8e29384cb2 feat: add ec 2022-08-01 00:02:03 +08:00
6833f7b86a feat: add __lang readme 2022-07-31 19:33:49 +08:00
acf61e1520 feat: add secmm-proc 2022-07-27 23:25:03 +08:00
3e755b465c feat: add readme 2022-07-27 00:26:38 +08:00
1eb9b95070 feat: update 2022-07-27 00:19:28 +08:00
4b32063d93 feat: add seckey 2022-07-27 00:14:34 +08:00
e4af4e6e25 feat: add sensitive 2022-07-27 00:07:33 +08:00
debc750e2f feat: container 2022-07-24 01:06:59 +08:00
842c5b4579 feat: container 2022-07-23 16:54:36 +08:00
b908736c1c feat: add container timing outputs 2022-07-23 14:44:14 +08:00
46b730e235 feat: update container 2022-07-23 13:03:43 +08:00
c40ac23cf5 feat: update container 2022-07-23 12:50:05 +08:00
1c9669a4a7 feat: update container 2022-07-23 12:48:43 +08:00
f0c3aa9df5 feat: update wit-bindgen-sample 2022-07-23 10:58:45 +08:00
4b4eacf3f4 feat: update wit-bindgen-sample 2022-07-23 10:50:20 +08:00
7d769d3a0f feat: wit-bindgen-sample 2022-07-23 10:48:31 +08:00
a116b1c2e6 feat: update container 2022-07-23 00:21:43 +08:00
0415152500 feat: update container 2022-07-23 00:21:32 +08:00
d90b1e69ea feat: update fetch 2022-07-22 23:54:20 +08:00
ca32d8701c feat: udpate container 2022-07-21 01:18:42 +08:00
b80d8b1859 feat: update readme 2022-07-17 20:10:04 +08:00
05ebf862fd feat: patch js-wasm 2022-07-17 19:41:12 +08:00
1de8f9499a fix: js-wasm 2022-07-17 19:40:16 +08:00
9f61cc748a feat: add js-wasm 2022-07-17 19:39:28 +08:00
30ac42001b feat: update to sjon 2022-07-17 12:55:15 +08:00
0741768d29 feat: reqwest 2022-07-17 12:46:24 +08:00
15bd8076b1 feat: add fetch timeout 2022-07-17 11:59:13 +08:00
cbc05226e0 feat: update us 2022-07-17 11:41:59 +08:00
4e88c90fd4 feat: update continer 2022-07-17 11:38:27 +08:00
2d6b1e3a1b feat: test script 2022-07-17 10:48:23 +08:00
6890520435 feat: fetch 2022-07-17 10:37:34 +08:00
74a202f1ed feat: works 2022-07-17 10:11:20 +08:00
4ba63b4c2e feat: add wit-bindgen-sample container 2022-07-17 00:06:54 +08:00
b0e1a89020 feat: add wit-bindgen-sample 2022-07-16 23:38:51 +08:00
dd45671b35 feat: update wasmtime 2022-07-16 16:18:16 +08:00
51685c6284 feat: update wasmtime 2022-07-16 16:03:51 +08:00
4d45c2dbcf feat: update wasmtime 2022-07-16 16:00:31 +08:00
fdee5bef03 feat: update wasmtime justfile 2022-07-10 14:57:36 +08:00
2a6b904c2a feat: wasmtime 2022-07-10 14:48:03 +08:00
6160185ace feat: add obfstr 2022-07-09 23:19:00 +08:00
a8a284163d feat: add boas wasn js engine 2022-07-09 19:59:06 +08:00
d17c718ee8 feat: udpate boa test 2022-07-08 00:58:22 +08:00
e2d6b9c54f feat: add deno_rust_wasm_import_functions 2022-07-08 00:36:47 +08:00
09c20602e9 feat: add result output 2022-07-06 00:56:20 +08:00
206470cdb3 feat: update justfile 2022-07-04 00:09:55 +08:00
89ce27b02f feat: html but not works 2022-07-04 00:08:41 +08:00
46783e8398 feat: update just file 2022-07-03 22:58:11 +08:00
e0b2b59858 feat: works better 2022-07-03 22:54:11 +08:00
4359817513 feat: add deno_rust_wasm_qr_decode 2022-07-03 00:34:15 +08:00
713e1424f9 feat: add wasmtime 2022-07-02 22:38:05 +08:00
f90941f497 feat: add wasmtime 2022-07-02 22:37:49 +08:00
22e77db82c feat: update tabled 2022-06-24 00:35:45 +08:00
af706d9abb feat: add select3 2022-06-18 23:53:19 +08:00
9ceaf9a789 feat: add fuser 2022-06-11 17:32:21 +08:00
fc23a5959b feat: add fuser 2022-06-11 17:32:07 +08:00
8ae8a57671 feat: add bonsaidb 2022-06-11 17:23:13 +08:00
d74850d236 feat: update mailsend 2022-06-06 00:18:09 +08:00
d181d970de feat: add mailsend 2022-06-06 00:05:36 +08:00
fbfe58c0e7 feat: update readme 2022-06-03 19:35:12 +08:00
cf46e8f119 feat: update monkey-rs 2022-06-02 00:39:33 +08:00
44759d1a67 feat: update monkey-rs 2022-06-02 00:39:22 +08:00
0488154e6f feat: update monkey-rs 2022-06-02 00:33:31 +08:00
2330a646b7 feat: add monkey-rs 2022-06-02 00:32:03 +08:00
6a8d8ca043 feat: add tabled 2022-05-21 21:44:38 +08:00
fe46aef388 feat: add sqlite extersion 2022-05-21 21:20:45 +08:00
7034c0b86c feat: add ureq 2022-05-14 01:29:43 +08:00
92bfe1819a feat: btc-address add current 2022-05-02 19:09:24 +08:00
6517457d0d feat: update btc-address 2022-05-02 19:01:30 +08:00
fc2a5217b3 feat: update druid 2022-05-02 10:42:42 +08:00
5538db42d9 feat: update readme 2022-04-15 23:50:38 +08:00
791c18ea77 feat: add dingo link 2022-04-15 23:49:53 +08:00
fe2f615943 feat: s2n quic test 2022-04-15 01:05:16 +08:00
72a8969453 feat: add hmac_sha1 2022-04-03 22:30:16 +08:00
46d24a8e24 feat: add gob 2022-03-26 10:47:58 +08:00
2b3e2a7c87 feat: bytes 2022-03-25 23:20:23 +08:00
f104c9dec9 feat: update bytes 2022-03-25 23:13:08 +08:00
8fa4284e6c feat: tokio stream 2022-03-22 00:43:39 +08:00
3f38ba99f7 feat: update mini tokio 2022-03-20 23:53:57 +08:00
18b7b4707a feat: add mini tokio 2022-03-20 23:46:17 +08:00
3684ae79da feat: add select2 2022-03-20 09:58:06 +08:00
779ecc08f2 feat: add select 2022-03-20 01:20:55 +08:00
0b0c1e4f11 refactor: rename handles 2022-03-19 23:59:33 +08:00
cbb8f43ad3 feat: add README.md 2022-03-19 23:45:47 +08:00
7007a77334 refactor: methods 2022-03-19 23:36:45 +08:00
effb8587b1 chore:rename 2022-03-19 23:17:40 +08:00
87f21a0b93 chore: clean code 2022-03-19 23:05:03 +08:00
e0b7a148ba feat: multiple stream by channel 2022-03-19 22:55:26 +08:00
db42a77035 feat: multiple message 2022-03-19 22:39:55 +08:00
43bd89f477 feat: add stream fork/join 2022-03-19 21:06:39 +08:00
f1fcb8d6f4 feat: update async study 2022-03-19 17:43:50 +08:00
03c3e1dab5 feat: works 2022-03-19 12:13:59 +08:00
0534c43968 feat: add async study 2022-03-19 10:47:04 +08:00
3486a5aae2 feat: add bunt 2022-02-05 18:32:58 +08:00
aca23fa6fd feat: add qcell 2022-02-03 22:02:18 +08:00
315ccf100e feat: add qcell 2022-02-03 22:01:55 +08:00
8339336888 feat: add orbtk 2021-08-15 17:45:29 +08:00
4a873ab1f6 feat: add pretty print 2021-08-08 11:14:32 +08:00
c20df9c739 feat: sign data 2021-07-17 12:46:49 +08:00
f967a24351 chore: pass 2021-07-17 11:43:15 +08:00
259115dea4 feat: init commit __hid 2021-07-17 11:28:09 +08:00
f97124884b feat: gobin 2021-06-12 18:55:18 +08:00
7331163c2b feat: add goblin 2021-06-12 18:33:24 +08:00
85714fd86d feat: add quinn 2021-05-09 00:32:26 +08:00
0328bc17d6 chore: comment 2021-05-05 23:18:19 +08:00
084166e0bd feat: main 2021-05-05 19:55:54 +08:00
355fcc1b9d feat: add build.rs 2021-05-05 19:46:56 +08:00
134c0dc166 feat: add sciter 2021-05-05 19:36:02 +08:00
1addcd26ea feat: add durid 2021-05-01 13:20:30 +08:00
ba796dd652 feat: add native dialog 2021-05-01 12:31:13 +08:00
813a7d5b2f feat: add tide 2021-04-29 23:14:05 +08:00
2b82801053 feat: add hyper_rustls 2021-04-29 22:17:53 +08:00
19a03e85d5 feat: add stream 2021-04-29 21:44:02 +08:00
4bbb7b9578 feat: add tun/tap for mac 2021-04-23 00:45:02 +08:00
5f880886ba feat: update libmacchina 2021-04-18 22:34:46 +08:00
1c58c1cfd2 feat: add libmacchina 2021-04-18 22:29:11 +08:00
d09b72468e feat: add readme 2021-04-11 14:45:05 +08:00
87327c8b11 feat: add iptables 2021-04-11 14:44:24 +08:00
1d02fda724 feat: update readm 2021-04-11 14:07:59 +08:00
ca1fe72030 feat: use buildj :::javac and :::java 2021-04-10 00:30:25 +08:00
f8c96be6a9 feat: robusta_jni 2021-04-10 00:12:55 +08:00
8b2c84b8bc feat: add rocket rs 2021-04-07 00:40:03 +08:00
521fc4f369 feat: add static dir 2021-04-07 00:30:53 +08:00
6bc61da148 feat: add salvo 2021-04-07 00:18:52 +08:00
2dd0c00c03 feat: add regex 2021-04-03 11:47:58 +08:00
a2afc118e2 feat: add gtk 2021-04-02 23:10:31 +08:00
29618a99ec feat: add gtk 2021-04-02 23:10:03 +08:00
dceda46ae8 feat: add bytes 2021-03-21 20:46:27 +08:00
67f62ee869 feat: add sqlx readme 2021-03-21 17:46:32 +08:00
b4f8d33e64 feat: add sqlx 2021-03-21 17:45:27 +08:00
dd05e11b30 feat: add ipipe 2021-03-21 17:36:51 +08:00
e55f773860 feat: add retranslate 2021-03-21 14:58:39 +08:00
d7967ce520 feat: add https://github.com/tikv/async-speed-limit 2021-02-17 22:49:01 +08:00
38439e4204 feat: add rust tcp 2021-02-17 12:10:11 +08:00
ed41681faf feat: add mysql svr 2021-02-17 12:01:37 +08:00
4c5ee6f908 feat: insert works 2021-02-12 23:17:00 +08:00
fb84b0f85e feat: add diesel, but not works 2021-02-12 23:06:29 +08:00
d383b36f00 feat: add password-hash 2021-02-11 14:53:25 +08:00
bf7b9275c1 feat: add message-io 2021-02-11 00:27:09 +08:00
03c5919538 feat: add thiserror anyhow 2021-02-09 23:22:46 +08:00
6f36859a4e feat: add shadow-rs 2021-01-31 23:41:00 +08:00
b131013b3e feat: add reed-solomon 2021-01-31 12:02:59 +08:00
452b41d51a feat: add uint 2021-01-30 10:55:42 +08:00
6769322905 feat: use cap 100 2021-01-24 23:48:44 +08:00
a8c9c92f75 feat: add example multi chan 2021-01-24 23:46:49 +08:00
980d52ad07 feat: rm unused code 2021-01-24 23:17:03 +08:00
c6e36fb414 feat: add rust link a 2021-01-24 23:10:46 +08:00
db388a6e37 feat: update version 2021-01-23 00:12:25 +08:00
db6bcfa7b9 chore: add gui readme 2021-01-17 21:49:37 +08:00
6a2001a0db feat: add gluesql 2021-01-11 23:53:10 +08:00
a52e5192f0 feat: add sqlparser 2021-01-11 23:48:12 +08:00
9c33fca074 feat: crypto/ring 2021-01-10 23:02:37 +08:00
e73575f62e chore: comments 2021-01-10 19:06:06 +08:00
58ea520a63 feat: dotalib 2021-01-10 18:21:01 +08:00
9dc7182b86 feat: add ffi readme 2021-01-10 15:28:06 +08:00
505f44df42 feat: move .a lib 2021-01-10 15:17:22 +08:00
bbc0adf1fa chore: readme 2021-01-10 15:16:00 +08:00
316ba7b338 feat: add test.c 2021-01-10 15:15:38 +08:00
dee3033007 feat: add dota lib 2021-01-10 15:10:53 +08:00
394e76ba29 feat: v0.6.27 2021-01-03 11:06:51 +08:00
740d5baf65 feat: use rust_util use_clap 2021-01-03 10:58:29 +08:00
8b70dfa145 feat: add barrel 2021-01-02 18:49:02 +08:00
42a261af55 feat: add rustyline 2021-01-02 18:37:31 +08:00
257906518e feat: add boa 2021-01-02 18:33:38 +08:00
d7488c82d7 feat: add rayon 2021-01-02 18:26:00 +08:00
695561da70 style: code style 2021-01-01 23:42:15 +08:00
eb1be1caf2 style: code style 2021-01-01 23:31:31 +08:00
0094ce2e5c style: code style 2021-01-01 23:31:18 +08:00
2a2d33be2c style: remove unused fn 2021-01-01 22:40:41 +08:00
bfe461a2b7 style: new line 2021-01-01 22:39:52 +08:00
0941f9e340 chore: log 2021-01-01 22:38:28 +08:00
de0184e253 style: format 2021-01-01 22:34:57 +08:00
ba35489cdf style: credit contract style 2021-01-01 22:31:05 +08:00
602e14071b style: style 2021-01-01 22:28:04 +08:00
24150ca0f1 feat: works 2021-01-01 22:16:11 +08:00
601f11efe6 feat: add name 2021-01-01 20:57:48 +08:00
6fef958a70 feat: use rust_util 2021-01-01 19:03:40 +08:00
54856504a2 feat: add simple contract 2021-01-01 18:35:28 +08:00
6386371a69 feat: add single file string.rs 2020-12-29 23:49:15 +08:00
c49f432208 chore: add comments 2020-12-29 23:40:40 +08:00
95917efa2d feat: serde_json camelCase 2020-12-29 23:35:28 +08:00
ffaba9fe48 feat: add no_proto 2020-12-27 21:31:46 +08:00
f0958ac291 feat: add ffi c 2020-12-27 15:09:31 +08:00
784be79abf feat: add glommio 2020-12-27 14:56:36 +08:00
cc10c8effd style: code style 2020-12-27 14:51:24 +08:00
8d34b85a9c feat: add abi stable crates 2020-12-27 14:43:46 +08:00
cd4a02f513 feat: add prost, but build failed 2020-12-27 14:12:43 +08:00
ec29c2368c feat: add handlebars 2020-12-26 09:58:53 +08:00
9a0434868b feat: add structopt 2020-12-26 09:48:03 +08:00
895385a2b5 feat: add fern 2020-12-26 09:45:28 +08:00
88c4ba5c94 feat: add socket2 2020-12-26 09:39:37 +08:00
e3ac142ead feat: parking_lot 2020-12-26 09:20:48 +08:00
6843d69daf feat: add crossbeam_n_parking_lot 2020-12-26 00:52:05 +08:00
64ea4ba82e chore: add readme 2020-12-06 11:50:12 +08:00
6a6cfae137 feat: add gui/winit 2020-12-06 11:49:06 +08:00
14a473103a feat: add crypto/pkcs8,ssh-keys 2020-12-06 11:41:37 +08:00
8b5e9e54c1 feat: add template 2020-12-06 11:08:07 +08:00
0e9b83fad1 chore: add readme 2020-12-05 11:01:46 +08:00
9884ea62f3 feat: add image/plotters 2020-12-05 10:46:43 +08:00
907c894dbc feat: add ml/rusty-mathine 2020-12-05 10:28:57 +08:00
5157903b3a feat: add misc/better_panic 2020-11-30 00:37:15 +08:00
4948dc547e feat: add persy 2020-11-29 16:27:40 +08:00
d1db369f44 feat: add c 2020-11-29 16:10:48 +08:00
a5571a138b feat: add ser/configrs 2020-11-29 13:50:22 +08:00
41447e002e feat: add hjson 2020-11-29 13:37:16 +08:00
1f47486d52 feat: use public-collect quickjs 2020-11-28 13:34:23 +08:00
6220da35a0 feat: rm: extern quickjs 2020-11-28 13:31:14 +08:00
113911b6ac feat: add fancy-regex 2020-11-24 23:52:30 +08:00
9eecc77ac0 feat: add code.zip clear 2020-11-21 21:33:21 +08:00
d510963203 feat: add alibabacloudfn 2020-11-21 21:26:57 +08:00
456a036b23 feat: add shell ssh2 2020-11-21 14:37:55 +08:00
9688a0ccef feat: add main5 2020-11-21 00:15:03 +08:00
30dc4a1416 feat: add main4 2020-11-20 23:50:29 +08:00
6488b111d7 feat: add ffi c_layout 2020-11-20 23:41:58 +08:00
220a582122 feat: add __rule, but cannot run 2020-11-17 01:07:31 +08:00
f017ee9dc1 feat: add linux unixsocket readme 2020-11-14 12:29:40 +08:00
86557359a5 feat: add unixsocket 2020-11-14 00:14:13 +08:00
895b7e03c8 feat: add rocksdb 2020-11-09 00:10:33 +08:00
22ee698955 feat: add rocks db 2020-11-09 00:10:04 +08:00
afb948c48c feat: add cbor 2020-11-08 23:46:21 +08:00
c03b7d75a3 chore: use code style 2020-11-08 20:14:19 +08:00
6f8c83fe26 feat: add curve25519 2020-11-08 20:13:45 +08:00
1b3cb499b4 feat: add log/log4rs 2020-11-08 17:01:18 +08:00
b02111ecd5 feat: add misc/human panice 2020-11-08 16:44:29 +08:00
dd53462cfb feat: add call_fn 2020-11-08 00:34:34 +08:00
7650b3c939 feat: add http status 2020-11-08 00:25:45 +08:00
228e006fb5 feat: deal with unwrap() 2020-11-08 00:02:03 +08:00
cad9dfe606 feat: use json verify json 2020-11-07 23:52:11 +08:00
8bc89e80bb style: code style 2020-11-07 23:43:15 +08:00
939861e987 chore: use pretty 2020-11-07 23:18:49 +08:00
6f7b3ecce8 feat: add publish, and rpc 2020-11-07 23:15:40 +08:00
297dca28f3 feat: add args 2020-11-07 21:41:04 +08:00
76beb992a3 feat: add verify file 2020-11-07 19:52:00 +08:00
3321c4720d feat: add examples 2020-11-07 19:37:36 +08:00
c51d2bb576 feat: rm run_js 2020-11-07 16:14:24 +08:00
56b44d1a8f feat: can run qjs 2020-11-07 16:12:21 +08:00
5110732561 feat: read/write from file 2020-11-07 15:00:26 +08:00
7e8d1e7884 chore: update README 2020-11-07 13:50:21 +08:00
b09f526c10 chore: update README 2020-11-07 13:49:09 +08:00
79efa59a34 feat: add __performance 2020-11-07 12:23:25 +08:00
e6917877cc feat: add __concurrent/green-threads 2020-11-07 12:19:49 +08:00
1bd0f3e5c9 feat: add cpu 2020-11-07 12:04:13 +08:00
24c7f80367 chore: add __network/n_pcap/README.md 2020-11-07 11:24:29 +08:00
afcbb3a8a2 feat: add __networks 2020-11-07 11:23:11 +08:00
73eddfbd5b feat: add pcap 2020-11-07 11:21:53 +08:00
82bb330b3c feat: rm pcap 2020-11-07 11:21:26 +08:00
e126c953a0 feat: add pcap 2020-11-07 11:19:46 +08:00
47eb944308 feat: add xshell 2020-11-07 10:55:52 +08:00
743c38725f feat: add ip 2020-11-06 00:04:41 +08:00
47f94a6544 feat: add enclave 2020-11-05 23:31:14 +08:00
691f77cf47 feat: update readme 2020-11-05 09:00:09 +08:00
0c312ef7f7 feat: add nfqueue 2020-11-05 08:56:32 +08:00
9c8c467fea feat: add __concurrent/arc-swap 2020-11-04 01:04:22 +08:00
5c9a439fe1 feat: add rsa 2020-11-01 19:19:03 +08:00
dfcdd02d27 feat: new 2020-11-01 14:05:31 +08:00
990f2dac41 feat: can run 2020-10-31 22:46:39 +08:00
e447b4e96d feat: add __fs/fuse 2020-10-31 22:38:24 +08:00
93ff5a519e feat: add notify 2020-10-22 21:49:04 +08:00
6e8bb9e33f chore: move __c_cpp/* to __ffi 2020-10-17 16:08:00 +08:00
a9df08bc6d chore: move __c_cpp/* to __ffi 2020-10-17 16:07:46 +08:00
754ff1ed60 chore: rebuild readmd 2020-10-17 12:39:54 +08:00
084a74f9c7 feat: add sysinfo 2020-10-17 12:38:59 +08:00
1eb86656bf feat: add psutil 2020-10-17 12:30:27 +08:00
269d087daa chore: reformat readme 2020-10-17 12:22:17 +08:00
9430fd5b1a chore: rebuild readmd 2020-10-17 12:14:53 +08:00
f1d3ca5969 chore: rebuild summary 2020-10-17 12:07:14 +08:00
07c2855586 chore: reorg 2020-10-17 12:05:51 +08:00
004599c8e4 chore: reorg 2020-10-17 12:03:44 +08:00
bf1a0343cc chore: reorg 2020-10-17 12:01:53 +08:00
0e7cc78585 chore: reorg 2020-10-17 11:59:10 +08:00
974545fc7c chore: reorg 2020-10-17 11:57:50 +08:00
5e48a69aa0 chore: reorg 2020-10-17 11:57:26 +08:00
347ea202e1 chore: reorg 2020-10-17 11:54:43 +08:00
af97622c79 chore: reorg 2020-10-17 11:53:39 +08:00
899428370b chore: reorg 2020-10-17 11:52:17 +08:00
d88ab2580a chore: reorg 2020-10-17 11:51:44 +08:00
9b6fb8b292 chore: reorg 2020-10-17 11:50:52 +08:00
bb6762ab81 chore: reorg 2020-10-17 11:50:12 +08:00
a034988643 chore: reorg 2020-10-17 11:47:07 +08:00
9d4d830115 chore: reorg 2020-10-17 11:47:03 +08:00
fc670d54b1 feat: add pwhash 2020-10-17 11:32:05 +08:00
dbb00a88b0 feat: add certs 2020-10-10 22:38:07 +08:00
6d3713f35e feat: add actix with rustls 2020-10-10 22:13:01 +08:00
b685938431 feat: add sincere 2020-10-09 23:40:19 +08:00
3ab0c24cf6 feat: add pencil, but build failed 2020-10-01 15:36:18 +08:00
d169e5a9fc chore: update ringt - eddsa 2020-10-01 09:48:27 +08:00
1f6df84c2a feat: add ring - eddsa 2020-10-01 09:43:49 +08:00
d5414661fc chore: mv smartstring 2020-10-01 07:58:29 +08:00
e987a9de3b feat: add smartstring 2020-10-01 07:57:43 +08:00
072dd9f9a4 chore: add pdf url 2020-10-01 00:16:41 +08:00
70459e0c90 feat: add .. 2020-10-01 00:12:10 +08:00
ce1b7dd4fb feat: add greet-rs 2020-10-01 00:03:03 +08:00
9f605830d2 feat: add load.c 2020-09-30 23:55:04 +08:00
8f8bc6eca9 feat: add files 2020-09-30 23:52:26 +08:00
820a5707fa feat: rename 2020-09-30 23:47:59 +08:00
443ab2c47f feat: add live reload rust 2020-09-30 23:45:41 +08:00
37c0a30a99 chore: update crates 2020-09-20 23:26:20 +08:00
81a0145be4 feat: add num_cpus 2020-09-20 23:11:30 +08:00
ccc820145e feat: add bytes 2020-09-20 23:02:17 +08:00
d55b768421 feat: add fiels 2020-08-30 00:52:01 +08:00
52ef0eaae1 feat: add udp_laminar udp_server_client 2020-08-30 00:50:12 +08:00
9eaaa185ca chore: sytle 2020-08-30 00:37:28 +08:00
e8dc9a49fb feat: add udp laminar 2020-08-30 00:02:12 +08:00
cebee53c4b chore: rename 2020-08-30 00:00:07 +08:00
3a9904d555 chore: style 2020-08-29 23:58:25 +08:00
42cab3e274 feat: add udp 2020-08-29 23:56:39 +08:00
5ece072af9 feat: add warp 2020-08-29 10:23:30 +08:00
6e7909f04d feat: add sana 2020-08-16 10:55:12 +08:00
b92afd290f feat: add jwt 2020-08-16 10:49:26 +08:00
2a40ee13ac style: change code style 2020-07-26 14:03:12 +08:00
b8cfa97481 style: code style 2020-07-19 22:06:16 +08:00
a4ec0c9d53 style: code style 2020-07-19 22:02:04 +08:00
399ba16771 chore(commit-msg.crs): add verbose output 2020-07-19 22:00:53 +08:00
7cdb6c25e5 style: code style 2020-07-19 21:43:40 +08:00
be2b083c02 style: code style 2020-07-19 21:38:11 +08:00
8e5596472d chore: not completed 2020-07-19 17:49:16 +08:00
2085babe94 chore: not completed 2020-07-19 17:49:08 +08:00
aa145d6912 feat: add colored_msg 2020-07-19 17:37:00 +08:00
39116a062d refactor: add get_home_e() 2020-07-19 16:58:48 +08:00
4471f05906 feat(commit-msg.crs): add custom regexp and usage support 2020-07-19 16:55:07 +08:00
27ce15e61a style(commit-msg): code style format 2020-07-12 17:55:11 +08:00
69fd44e857 feat(single-file-tests): add make executable 2020-07-12 17:44:36 +08:00
2d8ddb71e1 feat(commit-msg): use set mode replace of chmod command 2020-07-12 17:44:00 +08:00
c8fa72fca8 feat(commit-msg): if crs script file not exists use binaray file 2020-07-12 17:02:36 +08:00
90cc2d33f9 style(commit-msg): clean format 2020-07-12 14:51:04 +08:00
dc7bed5b2d feat(single-file-tests): add format sample 2020-07-12 14:42:13 +08:00
1a2df8c4e7 feat(quickjs): add backend console log support 2020-07-12 13:46:36 +08:00
bc73717adb feat(quickjs): add quickjs sample 2020-07-12 13:16:00 +08:00
ae0b65aef3 feat(quickjs): add quickjs
from: https://crates.io/crates/quick-js
2020-07-12 12:53:57 +08:00
2ff135faaa feat(commit-msg): supports installforce, or install-force 2020-07-12 12:49:35 +08:00
4d7fb7c650 docs(commit-msg): add usage, install sample 2020-07-12 12:46:16 +08:00
dcafa8f05f docs(commit-msg): add comment 2020-07-12 12:43:38 +08:00
55af07b4d4 feat: add usage for commit-msg 2020-07-12 00:42:34 +08:00
340373f69f feat: add format, and add mirror url 2020-07-12 00:36:49 +08:00
410bdc03be feat: add script/commit-msg.crs 2020-07-12 00:26:33 +08:00
11aae6799e add peg 2020-07-05 15:53:02 +08:00
2b00af0aa8 add pest 2020-07-04 10:15:54 +08:00
90f93df98a add diffy, prettydiff 2020-07-04 01:09:01 +08:00
1ec2a1c20c add encode url 2020-06-27 21:33:34 +08:00
3e7d62bdcf add get_2bytes 2020-06-27 21:23:10 +08:00
67787c3399 update fbs 2020-06-26 00:41:07 +08:00
fa722f19cf add flatbuffers 2020-06-25 23:22:18 +08:00
b8c99ede5b ad 99.rs 2020-06-25 17:15:19 +08:00
6cd7358f3b add match.rs 2020-06-25 16:54:48 +08:00
42d9b3d76a add print log 2020-05-30 23:40:01 +08:00
d944bb681d add tantivy 2020-05-30 23:37:54 +08:00
cd46285547 add simsearch 2020-05-30 23:23:14 +08:00
3cfedd9348 add core_macro.rs, sample.txt 2020-05-24 09:31:03 +08:00
7fff5d2a02 add svg file 2020-05-24 09:21:24 +08:00
d0ce80d3c3 add svg 2020-05-24 01:05:37 +08:00
6866bfdfa9 add svg 2020-05-24 01:02:59 +08:00
53ae14f357 add svg 2020-05-24 01:01:06 +08:00
d571380e59 add comment 2020-05-20 00:52:33 +08:00
b72dc883a7 add sled 2020-05-20 00:51:50 +08:00
489463ef84 add lifecycle str 2020-05-16 00:40:26 +08:00
ce657011e8 add ring::sha256 2020-05-15 01:04:23 +08:00
b4c30ec23c add hmac 2020-05-15 01:00:07 +08:00
0fb4016d00 add ring 2020-05-15 00:27:46 +08:00
9f43983660 add sample 2020-05-12 01:10:22 +08:00
99a0486e26 ref vec 2020-05-10 13:29:44 +08:00
48408e8963 ref 2020-05-05 21:33:30 +08:00
80926e99ab add regex 2020-05-05 21:28:39 +08:00
905f55382c add outputs 2020-05-05 13:01:22 +08:00
dc549fa4dc ? 2020-05-03 13:23:16 +08:00
6776ea7b5a update reqwest 2020-05-03 13:12:30 +08:00
609d89ee4e add reqwest 2020-05-03 12:50:43 +08:00
d6df92636b add cyrpto 2020-05-03 01:32:48 +08:00
2e5d18c15e add format 2020-05-03 01:19:57 +08:00
dd56187902 add closure 2020-05-03 01:10:29 +08:00
b2ac227e4c add to map 2020-05-03 01:00:39 +08:00
0b973718b5 add iter 2020-05-03 00:56:07 +08:00
4ac2e99f38 add num_cpus 2020-05-03 00:35:33 +08:00
d46efafbfe add comment 2020-05-03 00:29:08 +08:00
73dbc04bb6 add chrono 2020-05-03 00:28:01 +08:00
bf2f89ea6c add rand 2020-05-03 00:13:51 +08:00
a37d39572f sleep_sort 2020-05-01 21:20:13 +08:00
521b23770c sleep sort 2020-05-01 21:03:10 +08:00
bd1e807083 add &u[8] 2020-05-01 20:50:14 +08:00
5cf37e5b3b add get_csv_u8_slice 2020-05-01 20:46:56 +08:00
3cd720c68e add gbk_to_utf8_bytes 2020-05-01 20:40:09 +08:00
f5e9e1b13d update main.rs 2020-05-01 10:22:29 +08:00
d72d649d12 add encoding 2020-05-01 10:20:04 +08:00
2f0f0ac68e add csv 2020-05-01 10:13:33 +08:00
1d185745ec add flush 2020-04-20 01:20:37 +08:00
edb0eeb12c flush ? 2020-04-20 01:19:38 +08:00
f871911c6d add input.rs 2020-04-20 01:13:56 +08:00
9665da5030 fix spell 2020-04-20 00:59:53 +08:00
667608fa3a add inline 2020-04-20 00:35:36 +08:00
ea6c70a305 add calc_hash 2020-04-20 00:34:51 +08:00
dbb46bc18a use Arc 2020-04-20 00:19:05 +08:00
4eea25af9d use multi thread 2020-04-19 23:34:55 +08:00
0946d22fd9 make btc address 2020-04-19 23:16:36 +08:00
b1ab9bde74 add secp256k1 2020-04-19 08:40:31 +08:00
4314fcfca0 add btc-address 2020-04-19 08:06:48 +08:00
7686b2418c add chain 2020-04-18 23:06:52 +08:00
f686de081d use r# 2020-04-14 10:50:05 +08:00
a0e32adb01 rc.rs 2020-04-18 09:19:56 +08:00
e4603f9d4a add c 2020-04-18 09:06:25 +08:00
222e172c17 update use 2020-04-18 02:27:30 +08:00
1267c4ed30 add actix-web 2020-04-18 02:26:07 +08:00
ef06866d10 use custome log 2020-04-18 02:13:14 +08:00
4ac22d6800 add log 2020-04-18 02:06:50 +08:00
768e26f239 add hyperrs 2020-04-18 01:36:09 +08:00
9f97aa2823 &s and ref s 2020-04-17 08:21:54 +08:00
d532226133 add ref and & test 2020-04-17 08:18:26 +08:00
11e332e30f add display 2020-03-29 00:03:11 +08:00
a811d3d8fd add for 2020-03-22 19:37:00 +08:00
341f8b46bf add while 2020-03-22 19:16:47 +08:00
dcc99b7f12 add loop 2020-03-22 19:07:21 +08:00
75682bb6c7 add list 2020-03-22 18:59:56 +08:00
72f6e24bb9 add meter_proxy, a TCP proxy 2020-02-22 21:58:51 +08:00
0c615fecb5 update lock file 2020-02-10 22:25:18 +08:00
924a3385b5 add lock 2020-02-10 22:17:43 +08:00
2738efbf8e update cpp, cpp_build version to 0.5.4wq 2020-02-10 22:13:41 +08:00
793e47a759 add rusqlite 2020-02-10 22:05:45 +08:00
55f30e06ee add quick_error 2020-02-10 21:32:49 +08:00
46b1ca7af2 add from, into, try_from, try_into 2020-02-10 21:08:27 +08:00
9aaa53b09a add secp256k1 2020-02-10 20:20:10 +08:00
9909b06a5e fix is leap year 2020-02-04 20:03:11 +08:00
f362fce89c add lock files 2020-02-02 22:25:50 +08:00
925f224357 rename 2020-01-31 01:10:23 +08:00
8f311fc137 rename 2020-01-31 01:07:46 +08:00
a507b0452e rm crate time 2020-01-31 00:03:49 +08:00
963406635f add iron 2020-01-31 00:03:12 +08:00
92f714cab7 add rweb 2020-01-30 23:39:45 +08:00
ddd07c2166 add walkdir 2020-01-30 22:23:06 +08:00
3c70fdf3b9 add lazy_static 2020-01-30 22:15:35 +08:00
2297 changed files with 415008 additions and 22 deletions

13
.gitignore vendored
View File

@@ -1,14 +1,17 @@
.idea/
# ---> Rust # ---> Rust
# Generated by Cargo # Generated by Cargo
# will have compiled files and executables # will have compiled files and executables
target/ target/
99.htm
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
wasm/pkg/ wasm/pkg/
code.zip
linux_target/
node_modules/ node_modules/
*.o
*.so
pluginlibs
# These are backup files generated by rustfmt # These are backup files generated by rustfmt
**/*.rs.bk **/*.rs.bk

316
README.md
View File

@@ -1,3 +1,319 @@
# simple-rust-tests # simple-rust-tests
Simple Rust Tests Simple Rust Tests
Project or files:
```
.
├── __alloc
│   └── zeroizing-alloc-demo
├── __args
│   ├── argh-test
│   ├── clap-test
│   └── clap-test-2
├── __bin
│   ├── goblin
│   └── object-demo
├── __compress
│   └── zstd-demo
├── __concurrent
│   ├── arc-swap
│   ├── async_study
│   ├── async-fn-resumed-after-completion
│   ├── crossbeam_n_parking_lot
│   ├── glommio
│   ├── green-threads
│   ├── qcell
│   ├── rayon
│   └── waitgroup-demo
├── __cpu
│   └── x86
├── __crypto
│   ├── aegis-test
│   ├── aes_ctr_test
│   ├── aes_gcm_crypto
│   ├── asn1-der-test
│   ├── bc1-btc-address
│   ├── btc-address
│   ├── crypto
│   ├── crypto2-demo
│   ├── curve25519
│   ├── efficient_sm2
│   ├── eth-address
│   ├── highwayhash
│   ├── hmac_sha1
│   ├── jose-test
│   ├── jsonwebtoken
│   ├── liboqs-rust-demo
│   ├── ml-kem-demo
│   ├── okta-bcrypt-issue
│   ├── orion-demo
│   ├── passkey-rs-demo
│   ├── password-hash
│   ├── pkcs8
│   ├── pwhash
│   ├── random
│   ├── ring
│   ├── rpgp-demo
│   ├── rsa
│   ├── secp256k1
│   ├── secretshare
│   ├── shamir-demo
│   ├── simple_contract
│   ├── ssh-keys
│   ├── totp
│   └── yubikey-rs-demo
├── __database
│   ├── barrel
│   ├── bonsaidb
│   ├── diesel
│   ├── duckdb-demo
│   ├── gluesql
│   ├── mysqlsvr
│   ├── native_db-demo
│   ├── persy
│   ├── rocksdb
│   ├── rusqlite
│   ├── sled
│   ├── sqlite_extersion
│   ├── sqlparser
│   └── sqlx
├── __diff
│   ├── diffy
│   ├── prettydiff
├── __enclave
│   └── virt_enclave
├── __err
│   ├── err_derive
│   ├── quick_error
│   └── thiserror_anyhow
├── __external
│   └── vcard-qr
├── __ffi
│   ├── abi_stable_crates
│   ├── c
│   ├── c_export
│   ├── c_layout
│   ├── c2
│   ├── calltoc
│   ├── cpp
│   ├── dotalib
│   ├── jni
│   ├── live-reload-rust
│   ├── robusta_jni
│   └── rust_link_a
├── __fs
│   ├── crypt4ghfs-rust
│   ├── fuse
│   ├── fuser
├── __gui
│   ├── druid
│   ├── gtk
│   ├── native-dialog
│   ├── orbtk
│   ├── sciter
│   └── winit
├── __hid
│   └── yubikey_rs
├── __image
│   ├── plotters
│   └── svg
├── __internal
│   └── memory
├── __lang
│   ├── boa
│   ├── java
│   ├── monkey-rs
│   ├── peg
│   ├── pest
│   ├── quickjs
│   ├── rusty_jsc
│   └── sana
├── __linux
│   ├── ipipe
│   ├── nix-demo
│   ├── notify
│   ├── psutil
│   ├── sysinfo
│   └── unixsocket
├── __log
│   ├── fern
│   └── log4rs
├── __machinelearning
│   └── rusty-machine
├── __misc
│   ├── better_panic
│   ├── bytes
│   ├── daemonize-demo
│   ├── erasure-coding
│   ├── fancy-regex
│   ├── fastqr
│   ├── human_panic
│   ├── icalendar
│   ├── lazy_static
│   ├── libmacchina
│   ├── num_cpus
│   ├── obfstr
│   ├── reed-solomon
│   ├── regex
│   ├── shadowrs
│   ├── smartstring
│   ├── uint
│   └── walkdir
├── __network
│   ├── async-speed-limit
│   ├── axum-demo
│   ├── dingo
│   ├── dns-server-tutorial
│   ├── fetch-rs
│   ├── fuso-socks5-test
│   ├── html-crawl-parse
│   ├── ip
│   ├── ipnet-demo
│   ├── iptables
│   ├── kcp-test
│   ├── mailsend
│   ├── message_io
│   ├── n_pcap
│   ├── nfqueue
│   ├── ngrok-demo
│   ├── pcap
│   ├── pingora-demo
│   ├── quinn
│   ├── rust_tcp
│   ├── rust-rawsock-demo
│   ├── s2n_quic
│   ├── socket2
│   ├── tcp
│   ├── tcp-connect-reset
│   ├── tokio-kcp-demo
│   ├── tuntapmac
│   ├── udp_laminar
│   └── ureq
├── __performance
│   └── print_perf
├── __regex
│   └── hyperscan
├── __rpc
│   └── dubbo-rust
├── __rule
│   └── json-rules-engine
├── __search
│   ├── simsearch
│   └── tantivy
├── __security
│   ├── keychain-services
│   ├── keyring-demo
│   ├── seckey
│   ├── secmem-proc
│   ├── secrets
│   ├── security-framework
│   └── sensitive
├── __serialization
│   ├── bytes
│   ├── cbor
│   ├── configrs
│   ├── csv
│   ├── der_parser_test
│   ├── encoding
│   ├── flatbuffers
│   ├── gob
│   ├── hjson
│   ├── no_proto
│   ├── prost
│   └── serde_json
├── __shell
│   ├── ssh2
│   ├── sshrs
│   └── xshell
├── __shuttle
│   ├── hatter-test
├── __std
│   ├── async_await
│   ├── async-fn
│   ├── into
│   ├── iter
│   ├── misc
│   ├── ops
│   ├── pi
│   ├── thread
│   └── tokio-cpu-affinity
├── __template
│   ├── askama
│   └── handlebars-rust
├── __term
│   ├── bunt
│   ├── colored_msg
│   ├── comfy_table
│   ├── cursive-demo
│   ├── dialoguer-demo
│   ├── indicatif
│   ├── prettyprint
│   ├── rustyline
│   ├── structopt
│   ├── tabled
│   ├── term
│   └── tui-markup-demo
├── __time
│   ├── chrono
│   ├── humantime-demo
│   └── iron
├── __translate
│   └── retranslate
├── __wasm
│   ├── deno_rust_wasm_import_functions
│   ├── deno_rust_wasm_js_sandbox
│   ├── deno_rust_wasm_qr_decode
│   ├── extism
│   ├── js-wasm
│   ├── rust-wasm-plugins-examples
│   ├── wasi
│   ├── wasm
│   ├── wasmtime
│   ├── wasmtime-serde-demo
│   └── wit-bindgen-sample
├── __web
│   ├── actix_rustls
│   ├── actix-web
│   ├── alibabacloundfn
│   ├── hyper_rustls
│   ├── hyperrs
│   ├── meter_proxy
│   ├── pencil
│   ├── reqwest
│   ├── rocketrs
│   ├── rweb
│   ├── salvo
│   ├── sincere
│   ├── tide
│   └── warp
├── build_readme.rs -> scripts/build_readme_rs/src/main.rs
├── README_2.md
├── scripts
│   ├── build_readme_rs
└── single_file_tests
├── 99.rs
├── chain.rs
├── closure.rs
├── core_macro.rs
├── display.rs
├── for.rs
├── format.rs
├── input.rs
├── lifecycle_str.rs
├── list.rs
├── loop.rs
├── make_executable.rs
├── match.rs
├── rc.rs
├── ref_n_and.rs
├── sample.txt
├── slice.rs
├── string.rs
├── time.rs
├── vec.rs
└── while.rs
286 directories, 38 files
```

9
README_2.md Normal file
View File

@@ -0,0 +1,9 @@
GitHubs:
* https://github.com/tafia
Projects:
* https://github.com/tafia/hyper-proxy
* https://github.com/rusticata/x509-parser

9
README_template.md Normal file
View File

@@ -0,0 +1,9 @@
# simple-rust-tests
Simple Rust Tests
Project or files:
```
$$TREE_L2$$
```

16
__alloc/zeroizing-alloc-demo/Cargo.lock generated Normal file
View File

@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "zeroizing-alloc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebff5e6b81c1c7dca2d0bd333b2006da48cb37dbcae5a8da888f31fcb3c19934"
[[package]]
name = "zeroizing-alloc-demo"
version = "0.1.0"
dependencies = [
"zeroizing-alloc",
]

View File

@@ -0,0 +1,7 @@
[package]
name = "zeroizing-alloc-demo"
version = "0.1.0"
edition = "2024"
[dependencies]
zeroizing-alloc = "0.1.0"

View File

@@ -0,0 +1,8 @@
use zeroizing_alloc::ZeroAlloc;
#[global_allocator]
static ALLOC: ZeroAlloc<std::alloc::System> = ZeroAlloc(std::alloc::System);
fn main() {
println!("Hello, world!");
}

103
__args/argh-test/Cargo.lock generated Normal file
View File

@@ -0,0 +1,103 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "argh"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34ff18325c8a36b82f992e533ece1ec9f9a9db446bd1c14d4f936bac88fcd240"
dependencies = [
"argh_derive",
"argh_shared",
"rust-fuzzy-search",
]
[[package]]
name = "argh-test"
version = "0.1.0"
dependencies = [
"argh",
]
[[package]]
name = "argh_derive"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb7b2b83a50d329d5d8ccc620f5c7064028828538bdf5646acd60dc1f767803"
dependencies = [
"argh_shared",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "argh_shared"
version = "0.1.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a464143cc82dedcdc3928737445362466b7674b5db4e2eb8e869846d6d84f4f6"
dependencies = [
"serde",
]
[[package]]
name = "proc-macro2"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rust-fuzzy-search"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a157657054ffe556d8858504af8a672a054a6e0bd9e8ee531059100c0fa11bb2"
[[package]]
name = "serde"
version = "1.0.217"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.217"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "2.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"

View File

@@ -0,0 +1,7 @@
[package]
name = "argh-test"
version = "0.1.0"
edition = "2021"
[dependencies]
argh = "0.1.13"

View File

@@ -0,0 +1,22 @@
use argh::FromArgs;
#[derive(Debug, FromArgs)]
/// Reach new heights.
struct GoUp {
/// whether or not to jump
#[argh(switch, short = 'j')]
jump: bool,
/// how high to go
#[argh(option)]
height: usize,
/// an optional nickname for the pilot
#[argh(option)]
pilot_nickname: Option<String>,
}
fn main() {
let up: GoUp = argh::from_env();
println!("{:#?}", up);
}

261
__args/clap-test-2/Cargo.lock generated Normal file
View File

@@ -0,0 +1,261 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anstream"
version = "0.6.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
[[package]]
name = "anstyle-parse"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]]
name = "clap"
version = "4.5.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap-test-2"
version = "0.1.0"
dependencies = [
"clap",
"clap-verbosity-flag",
]
[[package]]
name = "clap-verbosity-flag"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eeab6a5cdfc795a05538422012f20a5496f050223c91be4e5420bfd13c641fb1"
dependencies = [
"clap",
"log",
]
[[package]]
name = "clap_builder"
version = "4.5.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "log"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "once_cell_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]]
name = "proc-macro2"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

View File

@@ -0,0 +1,8 @@
[package]
name = "clap-test-2"
version = "0.1.0"
edition = "2024"
[dependencies]
clap = { version = "4.5.42", features = ["derive", "env"] }
clap-verbosity-flag = "3"

View File

@@ -0,0 +1,158 @@
use clap::Parser;
// https://github.com/fastn-stack/kulfi/blob/main/malai/src/main.rs
fn main() {
let cli = Cli::parse();
println!("{:?}", cli);
}
#[derive(clap::Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Cli {
#[command(flatten)]
verbose: clap_verbosity_flag::Verbosity,
#[command(subcommand)]
pub command: Option<Command>,
// adding these two because when we run `cargo tauri dev,` it automatically passes these
// arguments. need to figure out why and how to disable that, till then this is a workaround
#[arg(default_value = "true", long, hide = true)]
no_default_features: bool,
#[arg(default_value = "auto", long, hide = true)]
color: String,
}
#[derive(clap::Subcommand, Debug)]
pub enum Command {
// TODO: add this to the docs when we have ACL
// By default it allows any peer to connect to the HTTP(s) service. You can pass --what-to-do
// argument to specify a What To Do service that can be used to add access control."
#[clap(about = "Expose HTTP Service on kulfi, connect using kulfi or browser")]
Http {
port: u16,
#[arg(
long,
default_value = "127.0.0.1",
help = "Host serving the http service."
)]
host: String,
#[arg(
long,
default_value = "kulfi.site",
help = "Use this for the HTTP bridge. To run an HTTP bridge, use `malai http-bridge`",
env = "MALAI_HTTP_BRIDGE"
)]
bridge: String,
#[arg(
long,
help = "Make the exposed service public. Anyone will be able to access."
)]
public: bool,
// #[arg(
// long,
// default_value_t = false,
// help = "Use this if the service is HTTPS"
// )]
// secure: bool,
// #[arg(
// long,
// help = "The What To Do Service that can be used to add access control."
// )]
// this will be the id52 of the identity server that should be consulted
// what_to_do: Option<String>,
},
#[clap(about = "Browse a kulfi site.")]
Browse {
#[arg(help = "The Kulfi URL to browse. Should look like kulfi://<id52>/<path>")]
url: String,
},
#[clap(about = "Expose TCP Service on kulfi.")]
Tcp {
port: u16,
#[arg(
long,
default_value = "127.0.0.1",
help = "Host serving the TCP service."
)]
host: String,
#[arg(
long,
help = "Make the exposed service public. Anyone will be able to access."
)]
public: bool,
},
#[clap(
about = "Run an http server that forwards requests to the given id52 taken from the HOST header"
)]
HttpBridge {
#[arg(
long,
short('t'),
help = "The id52 to which this bridge will forward incoming HTTP request. By default it forwards to every id52."
)]
proxy_target: Option<String>,
#[arg(
long,
short('p'),
help = "The port on which this bridge will listen for incoming HTTP requests. If you pass 0, it will bind to a random port.",
default_value = "0"
)]
port: u16,
},
#[clap(about = "Run a TCP server that forwards incoming requests to the given id52.")]
TcpBridge {
#[arg(help = "The id52 to which this bridge will forward incoming TCP request.")]
proxy_target: String,
#[arg(
help = "The port on which this bridge will listen for incoming TCP requests. If you pass 0, it will bind to a random port.",
default_value = "0"
)]
port: u16,
},
#[clap(about = "Expose a folder to kulfi network")]
Folder {
#[arg(help = "The folder to expose.")]
path: String,
#[arg(
long,
default_value = "kulfi.site",
help = "Use this for the HTTP bridge. To run an HTTP bridge, use `malai http-bridge`",
env = "MALAI_HTTP_BRIDGE"
)]
bridge: String,
#[arg(long, help = "Make the folder public. Anyone will be able to access.")]
public: bool,
},
#[clap(about = "Run all the services")]
Run {
#[arg(long, help = "Malai Home", env = "MALAI_HOME")]
home: Option<String>,
},
#[clap(about = "Run an iroh remote server that handles requests from http-proxy.")]
HttpProxyRemote {
#[arg(long, help = "Make the proxy public. Anyone will be able to access.")]
public: bool,
},
#[clap(about = "Run a http proxy server that forwards incoming requests to http-proxy-remote.")]
HttpProxy {
#[arg(help = "The id52 of remote to which this http proxy will forward request to.")]
remote: String,
#[arg(
help = "The port on which this proxy will listen for incoming TCP requests. If you pass 0, it will bind to a random port.",
default_value = "0"
)]
port: u16,
},
#[clap(about = "Generate a new identity.")]
Keygen {
#[arg(
long,
short,
num_args=0..=1,
//default_missing_value=kulfi_utils::SECRET_KEY_FILE,
help = "The file where the private key of the identity will be stored. If not provided, the private key will be printed to stdout."
)]
file: Option<String>,
},
}

237
__args/clap-test/Cargo.lock generated Normal file
View File

@@ -0,0 +1,237 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "clap"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap-test"
version = "0.1.0"
dependencies = [
"clap",
]
[[package]]
name = "clap_builder"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "proc-macro2"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
dependencies = [
"proc-macro2",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"

View File

@@ -0,0 +1,7 @@
[package]
name = "clap-test"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "4.5.23", features = ["derive"] }

View File

@@ -0,0 +1,165 @@
use std::ffi::OsStr;
use std::ffi::OsString;
use std::path::PathBuf;
use clap::{Args, Parser, Subcommand, ValueEnum};
/// A fictional versioning CLI
#[derive(Debug, Parser)] // requires `derive` feature
#[command(name = "git")]
#[command(about = "A fictional versioning CLI", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Debug, Subcommand)]
enum Commands {
/// Clones repos
#[command(arg_required_else_help = true)]
Clone {
/// The remote to clone
remote: String,
},
/// Compare two commits
Diff {
#[arg(value_name = "COMMIT")]
base: Option<OsString>,
#[arg(value_name = "COMMIT")]
head: Option<OsString>,
#[arg(last = true)]
path: Option<OsString>,
#[arg(
long,
require_equals = true,
value_name = "WHEN",
num_args = 0..=1,
default_value_t = ColorWhen::Auto,
default_missing_value = "always",
value_enum
)]
color: ColorWhen,
},
/// pushes things
#[command(arg_required_else_help = true)]
Push {
/// The remote to target
remote: String,
},
/// adds things
#[command(arg_required_else_help = true)]
Add {
/// Stuff to add
#[arg(required = true)]
path: Vec<PathBuf>,
},
Stash(StashArgs),
#[command(external_subcommand)]
External(Vec<OsString>),
}
#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)]
enum ColorWhen {
Always,
Auto,
Never,
}
impl std::fmt::Display for ColorWhen {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.to_possible_value()
.expect("no values are skipped")
.get_name()
.fmt(f)
}
}
#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
struct StashArgs {
#[command(subcommand)]
command: Option<StashCommands>,
#[command(flatten)]
push: StashPushArgs,
}
#[derive(Debug, Subcommand)]
enum StashCommands {
Push(StashPushArgs),
Pop { stash: Option<String> },
Apply { stash: Option<String> },
}
#[derive(Debug, Args)]
struct StashPushArgs {
#[arg(short, long)]
message: Option<String>,
}
fn main() {
let args = Cli::parse();
match args.command {
Commands::Clone { remote } => {
println!("Cloning {remote}");
}
Commands::Diff {
mut base,
mut head,
mut path,
color,
} => {
if path.is_none() {
path = head;
head = None;
if path.is_none() {
path = base;
base = None;
}
}
let base = base
.as_deref()
.map(|s| s.to_str().unwrap())
.unwrap_or("stage");
let head = head
.as_deref()
.map(|s| s.to_str().unwrap())
.unwrap_or("worktree");
let path = path.as_deref().unwrap_or_else(|| OsStr::new(""));
println!(
"Diffing {}..{} {} (color={})",
base,
head,
path.to_string_lossy(),
color
);
}
Commands::Push { remote } => {
println!("Pushing to {remote}");
}
Commands::Add { path } => {
println!("Adding {path:?}");
}
Commands::Stash(stash) => {
let stash_cmd = stash.command.unwrap_or(StashCommands::Push(stash.push));
match stash_cmd {
StashCommands::Push(push) => {
println!("Pushing {push:?}");
}
StashCommands::Pop { stash } => {
println!("Popping {stash:?}");
}
StashCommands::Apply { stash } => {
println!("Applying {stash:?}");
}
}
}
Commands::External(args) => {
println!("Calling out to {:?} with {:?}", &args[0], &args[1..]);
}
}
// Continued program logic goes here...
}

232
__bin/goblin/Cargo.lock generated Normal file
View File

@@ -0,0 +1,232 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "dirs-next"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1"
dependencies = [
"cfg-if",
"dirs-sys-next",
]
[[package]]
name = "dirs-sys-next"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
name = "getrandom"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "goblin"
version = "0.1.0"
dependencies = [
"goblin 0.4.1",
"rust_util",
]
[[package]]
name = "goblin"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee05c709047abe5eb0571880d2887ac77299c5f0835f8e6b7f4d5404f8962921"
dependencies = [
"log",
"plain",
"scroll",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
[[package]]
name = "log"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if",
]
[[package]]
name = "plain"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
[[package]]
name = "proc-macro2"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d8caf72986c1a598726adc988bb5984792ef84f5ee5aa50209145ee8077038"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "742739e41cd49414de871ea5e549afb7e2a3ac77b589bcbebe8c82fab37147fc"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_users"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
dependencies = [
"getrandom",
"redox_syscall",
]
[[package]]
name = "rust_util"
version = "0.6.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21b1ebfe593930e71805e37c914bf2dc48c2194b9dff7f0f1af8c59f92c5cff5"
dependencies = [
"lazy_static",
"libc",
"term",
"term_size",
]
[[package]]
name = "rustversion"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088"
[[package]]
name = "scroll"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fda28d4b4830b807a8b43f7b0e6b5df875311b3e7621d84577188c175b6ec1ec"
dependencies = [
"scroll_derive",
]
[[package]]
name = "scroll_derive"
version = "0.10.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aaaae8f38bb311444cfb7f1979af0bc9240d95795f75f9ceddf6a59b79ceffa0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "term"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f"
dependencies = [
"dirs-next",
"rustversion",
"winapi",
]
[[package]]
name = "term_size"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

12
__bin/goblin/Cargo.toml Normal file
View File

@@ -0,0 +1,12 @@
[package]
name = "goblin"
version = "0.1.0"
authors = ["Hatter Jiang@Pixelbook <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rust_util = "0.6.39"
goblin = "0.4.1"

32
__bin/goblin/src/main.rs Normal file
View File

@@ -0,0 +1,32 @@
#[macro_use] extern crate rust_util;
use std::path::Path;
use goblin::Object;
fn main() {
let file = std::env::args().nth(1);
match file {
None => failure_and_exit!("Must assign a file"),
Some(f) => {
let path = Path::new(&f);
let buff = std::fs::read(path).unwrap_or_else(|e| failure_and_exit!("Read file: {}, failed: {}", f, e));
match Object::parse(&buff).unwrap_or_else(|e| failure_and_exit!("Read file: {}, failed: {}", f , e)) {
Object::Elf(elf) => {
success!("Found elf file: {:?}", elf.header);
}
Object::PE(pe) => {
success!("Found PE file: {:?}", pe);
}
Object::Mach(mach) => {
success!("Found mach file: {:?}", mach);
}
Object::Archive(archive) => {
success!("Fund linux archive file: {:?}", archive);
}
Object::Unknown(magic) => {
failure!("Unknown file, magic: {}", magic);
}
}
}
}
}

82
__bin/object-demo/Cargo.lock generated Normal file
View File

@@ -0,0 +1,82 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "crc32fast"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [
"cfg-if",
]
[[package]]
name = "flate2"
version = "1.0.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
dependencies = [
"crc32fast",
"miniz_oxide",
]
[[package]]
name = "libc"
version = "0.2.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memmap2"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327"
dependencies = [
"libc",
]
[[package]]
name = "miniz_oxide"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa"
dependencies = [
"adler",
]
[[package]]
name = "object"
version = "0.30.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439"
dependencies = [
"flate2",
"memchr",
]
[[package]]
name = "object-demo"
version = "0.1.0"
dependencies = [
"memmap2",
"object",
]

View File

@@ -0,0 +1,10 @@
[package]
name = "object-demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
memmap2 = "0.5.10"
object = "0.30.3"

View File

@@ -0,0 +1,323 @@
use std::io::{Result, Write};
use object::{Endianness, Object, ObjectComdat, ObjectSection, ObjectSymbol};
use object::read::archive::ArchiveFile;
use object::read::macho::{DyldCache, FatArch, FatHeader};
use std::{env, fs, io, process};
fn main() {
let mut args = env::args();
let cmd = args.next().unwrap();
if args.len() == 0 {
eprintln!("Usage: {} <file> [<member>...]", cmd);
process::exit(1);
}
let file_path = args.next().unwrap();
let member_names: Vec<_> = args.collect();
let file = match fs::File::open(&file_path) {
Ok(file) => file,
Err(err) => {
eprintln!("Failed to open file '{}': {}", file_path, err,);
process::exit(1);
}
};
let extra_files = open_subcaches_if_exist(&file_path);
let file = match unsafe { memmap2::Mmap::map(&file) } {
Ok(mmap) => mmap,
Err(err) => {
eprintln!("Failed to map file '{}': {}", file_path, err,);
process::exit(1);
}
};
let extra_files: Vec<_> = extra_files
.into_iter()
.map(
|subcache_file| match unsafe { memmap2::Mmap::map(&subcache_file) } {
Ok(mmap) => mmap,
Err(err) => {
eprintln!("Failed to map file '{}': {}", file_path, err,);
process::exit(1);
}
},
)
.collect();
let extra_file_data: Vec<&[u8]> = extra_files.iter().map(|f| &**f).collect();
let stdout = io::stdout();
let stderr = io::stderr();
print(
&mut stdout.lock(),
&mut stderr.lock(),
&*file,
&extra_file_data,
member_names,
)
.unwrap();
}
// If the file is a dyld shared cache, and we're on macOS 12 or later,
// then there will be one or more "subcache" files next to this file,
// with the names filename.1, filename.2 etc.
// Read those files now, if they exist, even if we don't know that
// we're dealing with a dyld shared cache. By the time we know what
// we're dealing with, it's too late to read more files.
fn open_subcaches_if_exist(path: &str) -> Vec<fs::File> {
let mut files = Vec::new();
for i in 1.. {
let subcache_path = format!("{}.{}", path, i);
match fs::File::open(&subcache_path) {
Ok(subcache_file) => files.push(subcache_file),
Err(_) => break,
};
}
let symbols_subcache_path = format!("{}.symbols", path);
if let Ok(subcache_file) = fs::File::open(&symbols_subcache_path) {
files.push(subcache_file);
};
files
}
pub fn print<W: Write, E: Write>(
w: &mut W,
e: &mut E,
file: &[u8],
extra_files: &[&[u8]],
member_names: Vec<String>,
) -> Result<()> {
let mut member_names: Vec<_> = member_names.into_iter().map(|name| (name, false)).collect();
if let Ok(archive) = ArchiveFile::parse(file) {
writeln!(w, "Format: Archive (kind: {:?})", archive.kind())?;
for member in archive.members() {
match member {
Ok(member) => {
if find_member(&mut member_names, member.name()) {
writeln!(w)?;
writeln!(w, "{}:", String::from_utf8_lossy(member.name()))?;
if let Ok(data) = member.data(file) {
dump_object(w, e, data)?;
}
}
}
Err(err) => writeln!(e, "Failed to parse archive member: {}", err)?,
}
}
} else if let Ok(arches) = FatHeader::parse_arch32(file) {
writeln!(w, "Format: Mach-O Fat 32")?;
for arch in arches {
writeln!(w)?;
writeln!(w, "Fat Arch: {:?}", arch.architecture())?;
match arch.data(file) {
Ok(data) => dump_object(w, e, data)?,
Err(err) => writeln!(e, "Failed to parse Fat 32 data: {}", err)?,
}
}
} else if let Ok(arches) = FatHeader::parse_arch64(file) {
writeln!(w, "Format: Mach-O Fat 64")?;
for arch in arches {
writeln!(w)?;
writeln!(w, "Fat Arch: {:?}", arch.architecture())?;
match arch.data(file) {
Ok(data) => dump_object(w, e, data)?,
Err(err) => writeln!(e, "Failed to parse Fat 64 data: {}", err)?,
}
}
} else if let Ok(cache) = DyldCache::<Endianness>::parse(file, extra_files) {
writeln!(w, "Format: dyld cache {:?}-endian", cache.endianness())?;
writeln!(w, "Architecture: {:?}", cache.architecture())?;
for image in cache.images() {
let path = match image.path() {
Ok(path) => path,
Err(err) => {
writeln!(e, "Failed to parse dydld image name: {}", err)?;
continue;
}
};
if !find_member(&mut member_names, path.as_bytes()) {
continue;
}
writeln!(w)?;
writeln!(w, "{}:", path)?;
let file = match image.parse_object() {
Ok(file) => file,
Err(err) => {
writeln!(e, "Failed to parse file: {}", err)?;
continue;
}
};
dump_parsed_object(w, e, &file)?;
}
} else {
dump_object(w, e, file)?;
}
for (name, found) in member_names {
if !found {
writeln!(e, "Failed to find member '{}", name)?;
}
}
Ok(())
}
fn find_member(member_names: &mut [(String, bool)], name: &[u8]) -> bool {
if member_names.is_empty() {
return true;
}
match member_names.iter().position(|x| x.0.as_bytes() == name) {
Some(i) => {
member_names[i].1 = true;
true
}
None => false,
}
}
fn dump_object<W: Write, E: Write>(w: &mut W, e: &mut E, data: &[u8]) -> Result<()> {
match object::File::parse(data) {
Ok(file) => {
dump_parsed_object(w, e, &file)?;
}
Err(err) => {
writeln!(e, "Failed to parse file: {}", err)?;
}
}
Ok(())
}
fn dump_parsed_object<W: Write, E: Write>(w: &mut W, e: &mut E, file: &object::File) -> Result<()> {
writeln!(
w,
"Format: {:?} {:?}-endian {}-bit",
file.format(),
file.endianness(),
if file.is_64() { "64" } else { "32" }
)?;
writeln!(w, "Kind: {:?}", file.kind())?;
writeln!(w, "Architecture: {:?}", file.architecture())?;
writeln!(w, "Flags: {:x?}", file.flags())?;
writeln!(
w,
"Relative Address Base: {:x?}",
file.relative_address_base()
)?;
writeln!(w, "Entry Address: {:x?}", file.entry())?;
match file.mach_uuid() {
Ok(Some(uuid)) => writeln!(w, "Mach UUID: {:x?}", uuid)?,
Ok(None) => {}
Err(err) => writeln!(e, "Failed to parse Mach UUID: {}", err)?,
}
match file.build_id() {
Ok(Some(build_id)) => writeln!(w, "Build ID: {:x?}", build_id)?,
Ok(None) => {}
Err(err) => writeln!(e, "Failed to parse build ID: {}", err)?,
}
match file.gnu_debuglink() {
Ok(Some((filename, crc))) => writeln!(
w,
"GNU debug link: {} CRC: {:08x}",
String::from_utf8_lossy(filename),
crc,
)?,
Ok(None) => {}
Err(err) => writeln!(e, "Failed to parse GNU debug link: {}", err)?,
}
match file.gnu_debugaltlink() {
Ok(Some((filename, build_id))) => writeln!(
w,
"GNU debug alt link: {}, build ID: {:x?}",
String::from_utf8_lossy(filename),
build_id,
)?,
Ok(None) => {}
Err(err) => writeln!(e, "Failed to parse GNU debug alt link: {}", err)?,
}
match file.pdb_info() {
Ok(Some(info)) => writeln!(
w,
"PDB file: {}, GUID: {:x?}, Age: {}",
String::from_utf8_lossy(info.path()),
info.guid(),
info.age()
)?,
Ok(None) => {}
Err(err) => writeln!(e, "Failed to parse PE CodeView info: {}", err)?,
}
for segment in file.segments() {
writeln!(w, "{:x?}", segment)?;
}
for section in file.sections() {
writeln!(w, "{}: {:x?}", section.index().0, section)?;
}
for comdat in file.comdats() {
write!(w, "{:?} Sections:", comdat)?;
for section in comdat.sections() {
write!(w, " {}", section.0)?;
}
writeln!(w)?;
}
writeln!(w)?;
writeln!(w, "Symbols")?;
for symbol in file.symbols() {
writeln!(w, "{}: {:x?}", symbol.index().0, symbol)?;
}
for section in file.sections() {
if section.relocations().next().is_some() {
writeln!(
w,
"\n{} relocations",
section.name().unwrap_or("<invalid name>")
)?;
for relocation in section.relocations() {
writeln!(w, "{:x?}", relocation)?;
}
}
}
writeln!(w)?;
writeln!(w, "Dynamic symbols")?;
for symbol in file.dynamic_symbols() {
writeln!(w, "{}: {:x?}", symbol.index().0, symbol)?;
}
if let Some(relocations) = file.dynamic_relocations() {
writeln!(w)?;
writeln!(w, "Dynamic relocations")?;
for relocation in relocations {
writeln!(w, "{:x?}", relocation)?;
}
}
match file.imports() {
Ok(imports) => {
if !imports.is_empty() {
writeln!(w)?;
for import in imports {
writeln!(w, "{:x?}", import)?;
}
}
}
Err(err) => writeln!(e, "Failed to parse imports: {}", err)?,
}
match file.exports() {
Ok(exports) => {
if !exports.is_empty() {
writeln!(w)?;
for export in exports {
writeln!(w, "{:x?}", export)?;
}
}
}
Err(err) => writeln!(e, "Failed to parse exports: {}", err)?,
}
Ok(())
}

70
__compress/zstd-demo/Cargo.lock generated Normal file
View File

@@ -0,0 +1,70 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
dependencies = [
"jobserver",
]
[[package]]
name = "jobserver"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "pkg-config"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "zstd"
version = "0.12.3+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-demo"
version = "0.1.0"
dependencies = [
"zstd",
]
[[package]]
name = "zstd-safe"
version = "6.0.4+zstd.1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543"
dependencies = [
"libc",
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.0.7+zstd.1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5"
dependencies = [
"cc",
"libc",
"pkg-config",
]

View File

@@ -0,0 +1,9 @@
[package]
name = "zstd-demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
zstd = "0.12.3"

View File

@@ -0,0 +1,29 @@
use std::collections::VecDeque;
use std::io;
use zstd::Encoder;
fn main() {
let inputs = "hello world".repeat(100);
let outputs = compress_manually(1, inputs.as_bytes().to_vec().into());
println!("Inputs len: {}", inputs.len());
println!("Outputs len: {}", outputs.len());
println!("{:x?}", outputs);
}
// fn compress(level: i32) {
// zstd::stream::copy_encode(io::stdin(), io::stdout(), level).unwrap();
// }
// fn decompress() {
// zstd::stream::copy_decode(io::stdin(), io::stdout()).unwrap();
// }
// This function does the same thing, directly using an `Encoder`:
fn compress_manually(level: i32, mut input: VecDeque<u8>) -> Vec<u8> {
let mut output: Vec<u8> = vec![];
let mut encoder = Encoder::new(&mut output, level).unwrap();
io::copy(&mut input, &mut encoder).unwrap();
encoder.finish().unwrap();
output
}

21
__concurrent/arc-swap/Cargo.lock generated Normal file
View File

@@ -0,0 +1,21 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "arc-swap"
version = "0.1.0"
dependencies = [
"arc-swap 0.4.7",
"once_cell",
]
[[package]]
name = "arc-swap"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034"
[[package]]
name = "once_cell"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad"

View File

@@ -0,0 +1,13 @@
[package]
name = "arc-swap"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
arc-swap = "0.4"
once_cell = "1.4"

View File

@@ -0,0 +1,11 @@
use once_cell::sync::Lazy;
use arc_swap::ArcSwap;
static TEST_STRING: Lazy<ArcSwap<String>> = Lazy::new(|| {
ArcSwap::from_pointee("Hello World!".to_owned())
});
fn main() {
let s = TEST_STRING.load();
println!("{}", s);
}

View File

@@ -0,0 +1,421 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "async-fn-resumed-after-completion"
version = "0.1.0"
dependencies = [
"tokio",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bytes"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
[[package]]
name = "cc"
version = "1.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "gimli"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "hermit-abi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "libc"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "lock_api"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "memchr"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "miniz_oxide"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
dependencies = [
"libc",
"wasi",
"windows-sys 0.48.0",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "object"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"memchr",
]
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets 0.48.5",
]
[[package]]
name = "pin-project-lite"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "proc-macro2"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags",
]
[[package]]
name = "rustc-demangle"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "smallvec"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
[[package]]
name = "socket2"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871"
dependencies = [
"libc",
"windows-sys 0.52.0",
]
[[package]]
name = "syn"
version = "2.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tokio"
version = "1.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-macros"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets 0.52.4",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
name = "windows-targets"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b"
dependencies = [
"windows_aarch64_gnullvm 0.52.4",
"windows_aarch64_msvc 0.52.4",
"windows_i686_gnu 0.52.4",
"windows_i686_msvc 0.52.4",
"windows_x86_64_gnu 0.52.4",
"windows_x86_64_gnullvm 0.52.4",
"windows_x86_64_msvc 0.52.4",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8"

View File

@@ -0,0 +1,9 @@
[package]
name = "async-fn-resumed-after-completion"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.36.0", features = ["full"] }

View File

@@ -0,0 +1,48 @@
async fn action(input: Option<i32>) -> Option<String> {
// 若 input输入是None则返回 None
// 事实上也可以这么写: `let i = input?;`
let _i = match input {
Some(input) => input,
None => return None,
};
// 这里定义一些逻辑
Some("test".into())
}
#[tokio::main]
async fn main() {
let (tx, mut rx) = tokio::sync::mpsc::channel(128);
let mut done = false;
let operation = action(None);
tokio::pin!(operation);
tokio::spawn(async move {
let _ = tx.send(1).await;
let _ = tx.send(3).await;
let _ = tx.send(2).await;
});
loop {
tokio::select! {
res = &mut operation, if !done => {
println!("res = &mut operation, done={}", done);
done = true;
if let Some(v) = res {
println!("GOT = {}", v);
return;
}
}
Some(v) = rx.recv() => {
println!("Some(v={}) = rx.recv()", v);
if v % 2 == 0 {
// `.set` 是 `Pin` 上定义的方法
operation.set(action(Some(v)));
done = false;
}
}
}
}
}

438
__concurrent/async_study/Cargo.lock generated Normal file
View File

@@ -0,0 +1,438 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "async_study"
version = "0.1.0"
dependencies = [
"bytes",
"futures",
"futures-core",
"futures-util",
"tokio",
"tokio-stream",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bytes"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "futures"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3"
[[package]]
name = "futures-executor"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b"
[[package]]
name = "futures-macro"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868"
[[package]]
name = "futures-task"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a"
[[package]]
name = "futures-util"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.121"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
[[package]]
name = "lock_api"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
dependencies = [
"cfg-if",
]
[[package]]
name = "memchr"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "mio"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52da4364ffb0e4fe33a9841a98a3f3014fb964045ce4f7a45a398243c8d6b0c9"
dependencies = [
"libc",
"log",
"miow",
"ntapi",
"wasi",
"winapi",
]
[[package]]
name = "miow"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21"
dependencies = [
"winapi",
]
[[package]]
name = "ntapi"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f"
dependencies = [
"winapi",
]
[[package]]
name = "num_cpus"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "once_cell"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]]
name = "parking_lot"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-sys",
]
[[package]]
name = "pin-project-lite"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "proc-macro2"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4af2ec4714533fcdf07e886f17025ace8b997b9ce51204ee69b6da831c3da57"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c"
dependencies = [
"bitflags",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "signal-hook-registry"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
dependencies = [
"libc",
]
[[package]]
name = "slab"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5"
[[package]]
name = "smallvec"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
[[package]]
name = "socket2"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "syn"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea297be220d52398dcc07ce15a209fce436d361735ac1db700cab3b6cdfb9f54"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "tokio"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee"
dependencies = [
"bytes",
"libc",
"memchr",
"mio",
"num_cpus",
"once_cell",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"winapi",
]
[[package]]
name = "tokio-macros"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tokio-stream"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3"
dependencies = [
"futures-core",
"pin-project-lite",
"tokio",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6"
dependencies = [
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5"
[[package]]
name = "windows_i686_gnu"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615"
[[package]]
name = "windows_i686_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172"
[[package]]
name = "windows_x86_64_gnu"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"

View File

@@ -0,0 +1,14 @@
[package]
name = "async_study"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.0", features = ["full"] }
futures-core = "0.3"
futures-util = { version = "0.3", default-features = false }
bytes = "1.1"
futures = "0.3"
tokio-stream = "0.1"

View File

@@ -0,0 +1,22 @@
Import `tokio`:
```
tokio = { version = "1.0", features = ["full"] }
```
Usage:
```rust
#[tokio::main]
async fn main() {
// TODO ...
}
```
`tokio` 提供以下几种 channels 类型:
* mpsc: 多生产者,单消费者 - https://docs.rs/tokio/1/tokio/sync/mpsc/index.html
* oneshot: 单生产者,单消费者 - https://docs.rs/tokio/1/tokio/sync/oneshot/index.html
* broadcast: 多生产者,多消费者 - https://docs.rs/tokio/1/tokio/sync/broadcast/index.html
* watch: 单生产者,多消费者 - https://docs.rs/tokio/1/tokio/sync/watch/index.html

View File

@@ -0,0 +1,8 @@
#[tokio::main]
async fn main() {
invoke().await
}
async fn invoke() {
println!("Hello World!");
}

View File

@@ -0,0 +1,23 @@
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
#[tokio::main]
async fn main() {
invoke().await
}
struct FutureImpl {}
impl Future for FutureImpl {
type Output = ();
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
println!("Hello World!");
Poll::Ready(())
}
}
fn invoke() -> impl Future<Output=()> {
FutureImpl {}
}

View File

@@ -0,0 +1,35 @@
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
#[tokio::main]
async fn main() {
invoke().await
}
struct FutureImpl {
i: i32,
}
impl Future for FutureImpl {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
if self.i == 0 {
let s = &mut *self;
s.i += 1;
println!("Hello World, pending");
cx.waker().wake_by_ref();
Poll::Pending
} else {
println!("Hello World, ready");
Poll::Ready(())
}
}
}
fn invoke() -> impl Future<Output=()> {
FutureImpl {
i: 0,
}
}

View File

@@ -0,0 +1,10 @@
fn main() {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
invoke().await
});
}
async fn invoke() {
println!("Hello World!");
}

View File

@@ -0,0 +1,72 @@
use std::collections::VecDeque;
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::{Duration, Instant};
use futures::task;
// from: https://tokio.rs/tokio/tutorial/async
fn main() {
let mut mini_tokio = MiniTokio::new();
mini_tokio.spawn(async {
let when = Instant::now() + Duration::from_millis(10);
let future = Delay { when };
let out = future.await;
assert_eq!(out, "done");
});
mini_tokio.run();
}
struct MiniTokio {
tasks: VecDeque<Task>,
}
type Task = Pin<Box<dyn Future<Output=()> + Send>>;
impl MiniTokio {
fn new() -> MiniTokio {
MiniTokio {
tasks: VecDeque::new(),
}
}
/// Spawn a future onto the mini-tokio instance.
fn spawn<F>(&mut self, future: F) where F: Future<Output=()> + Send + 'static, {
self.tasks.push_back(Box::pin(future));
}
fn run(&mut self) {
let waker = task::noop_waker();
let mut cx = Context::from_waker(&waker);
while let Some(mut task) = self.tasks.pop_front() {
if task.as_mut().poll(&mut cx).is_pending() {
self.tasks.push_back(task);
}
}
}
}
struct Delay {
when: Instant,
}
impl Future for Delay {
type Output = &'static str;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<&'static str> {
if Instant::now() >= self.when {
println!("Hello world");
Poll::Ready("done")
} else {
// Ignore this line for now.
cx.waker().wake_by_ref();
Poll::Pending
}
}
}

View File

@@ -0,0 +1,24 @@
use std::time::Duration;
use tokio::sync::oneshot::channel;
#[tokio::main]
async fn main() {
let (tx1, rx1) = channel::<i32>();
let (_tx2, rx2) = channel::<i32>();
tokio::spawn(async move {
tokio::time::sleep(Duration::from_millis(200)).await;
tx1.send(1);
});
println!("start select");
tokio::select! {
val = rx1 => {
println!("rx1 completed first with {:?}", val);
}
val = rx2 => {
println!("rx2 completed first with {:?}", val);
}
}
println!("end select");
}

View File

@@ -0,0 +1,44 @@
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;
use tokio::sync::oneshot::{channel, Receiver};
#[tokio::main]
async fn main() {
let (tx1, rx1) = channel::<i32>();
let (_tx2, rx2) = channel::<i32>();
tokio::spawn(async move {
tokio::time::sleep(Duration::from_millis(200)).await;
let _ = tx1.send(1);
});
println!("start select");
MySelect { rx1, rx2 }.await;
println!("end select");
}
struct MySelect {
rx1: Receiver<i32>,
rx2: Receiver<i32>,
}
impl Future for MySelect {
type Output = ();
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
if let Poll::Ready(val) = Pin::new(&mut self.rx1).poll(cx) {
println!("rx1 completed first with {:?}", val);
return Poll::Ready(());
}
if let Poll::Ready(val) = Pin::new(&mut self.rx2).poll(cx) {
println!("rx2 completed first with {:?}", val);
return Poll::Ready(());
}
Poll::Pending
}
}

View File

@@ -0,0 +1,40 @@
use std::time::Duration;
use tokio::{join, select};
use tokio::sync::oneshot::channel;
#[tokio::main]
async fn main() {
let (tx1, rx1) = channel::<i32>();
let a = tokio::spawn(async move {
tokio::time::sleep(Duration::from_millis(2000)).await;
let _ = tx1.send(1);
println!(">>> send tx1");
});
select! {
a = rx1 => {
println!("tx: {:?}", a);
}
b = run() => {
println!("run: {:?}", b);
}
c = tokio::time::sleep(Duration::from_millis(1500)) => {
println!("timeout: {:?}", c);
}
}
println!("join: {:?}", join!(a));
println!(">> pre end");
tokio::time::sleep(Duration::from_millis(2000)).await;
println!(">> end");
}
async fn run() {
for i in 0.. {
tokio::time::sleep(Duration::from_millis(300)).await;
println!("# {}", i);
}
}

View File

@@ -0,0 +1,98 @@
use std::future::Future;
use std::io::{self, ErrorKind};
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf};
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let (sender, receiver) = channel::<StreamMessage>(512);
let stream = Stream { sender, receiver };
let (mut s, mut w) = tokio::io::split(stream);
let t = tokio::spawn(async move {
let mut buf = Vec::<u8>::with_capacity(1024);
loop {
match s.read_buf(&mut buf).await {
Ok(len) => println!("Len: {}, Buf: {:?}", len, &buf[..len]),
Err(e) => {
println!("Err: {:?}", e);
if e.to_string().contains("broken pipe") {
break;
}
}
}
}
});
sleep(Duration::from_secs(1)).await;
let _ = w.write_all(b"hello world").await;
sleep(Duration::from_secs(1)).await;
let _ = w.write_all(b"hello world").await;
sleep(Duration::from_secs(1)).await;
let _ = w.write_all(b"hello world").await;
let a = tokio::join!(w.shutdown());
let b = tokio::join!(t);
println!("{:?}, {:?}", a, b)
}
#[derive(Debug)]
enum StreamMessage {
Data(Vec<u8>),
Flush,
Close,
}
struct Stream {
sender: Sender<StreamMessage>,
receiver: Receiver<StreamMessage>,
}
impl AsyncRead for Stream {
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<io::Result<()>> {
let m = self.receiver.poll_recv(cx);
match m {
Poll::Pending => Poll::Pending,
Poll::Ready(m_opt) => match m_opt {
None => Poll::Ready(Err(io::Error::new(ErrorKind::BrokenPipe, "broken pipe"))),
Some(StreamMessage::Close) => {
self.receiver.close();
Poll::Ready(Ok(()))
}
Some(StreamMessage::Flush) => Poll::Ready(Ok(())),
Some(StreamMessage::Data(mm)) => {
buf.put_slice(mm.as_slice());
Poll::Ready(Ok(()))
}
}
}
}
}
impl AsyncWrite for Stream {
fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<io::Result<usize>> {
pool_send(self, cx, StreamMessage::Data(Vec::from(buf)), buf.len())
}
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
pool_send(self, cx, StreamMessage::Flush, ())
}
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
pool_send(self, cx, StreamMessage::Close, ())
}
}
fn pool_send<R>(s: Pin<&mut Stream>, cx: &mut Context<'_>, stream_message: StreamMessage, r: R) -> Poll<io::Result<R>> {
let fut = s.sender.send(stream_message);
tokio::pin!( fut);
match fut.poll(cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(Ok(_)) => Poll::Ready(Ok(r)),
Poll::Ready(Err(e)) => Poll::Ready(Err(io::Error::new(ErrorKind::BrokenPipe, e.to_string()))),
}
}

View File

@@ -0,0 +1,10 @@
use tokio_stream::{self as stream, StreamExt};
#[tokio::main]
async fn main() {
let mut stream = stream::iter(vec![0, 1, 2]);
while let Some(value) = stream.next().await {
println!("Got {}", value);
}
}

View File

@@ -0,0 +1,29 @@
use std::pin::Pin;
use std::task::{Context, Poll};
use futures_core::Stream;
use tokio_stream::StreamExt;
#[tokio::main]
async fn main() {
let mut stream = MyStream(0);
while let Some(value) = stream.next().await {
println!("Got {}", value);
}
}
struct MyStream(i32);
impl Stream for MyStream {
type Item = i32;
fn poll_next(mut self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
if self.0 < 10 {
self.0 += 1;
Poll::Ready(Some(self.0))
} else {
Poll::Ready(None)
}
}
}

View File

@@ -0,0 +1,190 @@
use std::collections::HashMap;
use std::future::Future;
use std::io::{self, ErrorKind};
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicU64, Ordering};
use std::task::{Context, Poll};
use std::time::Duration;
use bytes::BytesMut;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, ReadBuf, ReadHalf, WriteHalf};
use tokio::sync::mpsc::{channel, Receiver, Sender};
use tokio::task::JoinHandle;
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let channel_id = AtomicU64::new(1);
let (left_to_right_sender, left_to_right_receiver) = channel::<StreamPackage>(512);
let (right_to_left_sender, right_to_left_receiver) = channel::<StreamPackage>(512);
let right_consumer_stream_map = Arc::new(Mutex::new(HashMap::<u64, Sender<StreamPackage>>::new()));
let left_consumer_stream_map = Arc::new(Mutex::new(HashMap::<u64, Sender<StreamPackage>>::new()));
loop_consume(left_to_right_receiver, right_consumer_stream_map.clone());
loop_consume(right_to_left_receiver, left_consumer_stream_map.clone());
let mut handles = vec![];
for _ in 0..3 {
let new_channel_id = channel_id.fetch_add(1, Ordering::SeqCst);
let right_stream = create_stream(new_channel_id, right_to_left_sender.clone(), right_consumer_stream_map.clone());
let left_stream = create_stream(new_channel_id, left_to_right_sender.clone(), left_consumer_stream_map.clone());
let (right_stream_reader, right_stream_writer) = tokio::io::split(right_stream);
let (left_stream_reader, left_stream_writer) = tokio::io::split(left_stream);
let a = loop_read(right_stream_reader, format!("#{} right reader", new_channel_id));
let b = loop_read(left_stream_reader, format!("#{} left reader", new_channel_id));
let c = loop_send(new_channel_id, right_stream_writer, format!("right sender"));
let d = loop_send(new_channel_id, left_stream_writer, format!("left sender"));
handles.extend([a, b, c, d]);
}
for h in handles {
let _ = tokio::join!(h);
}
}
fn create_stream(channel_id: u64, sender: Sender<StreamPackage>, consumer_stream_map: Arc<Mutex<HashMap<u64, Sender<StreamPackage>>>>) -> Stream {
let (new_sender, receiver) = channel::<StreamPackage>(16);
{
let stream_map_left_locked = &mut consumer_stream_map.lock().unwrap();
stream_map_left_locked.insert(channel_id, new_sender);
}
Stream {
channel_id,
sender,
receiver,
}
}
fn loop_send(channel_id: u64, mut writer: WriteHalf<Stream>, tag: String) -> JoinHandle<()> {
tokio::spawn(async move {
for i in 0..3 {
sleep(Duration::from_millis(100)).await;
let _ = writer.write_all(format!("Send message: [{}] {} - {}", &tag, channel_id, i).as_bytes()).await;
}
let _ = writer.shutdown().await;
})
}
fn loop_read(mut reader: ReadHalf<Stream>, tag: String) -> JoinHandle<()> {
tokio::spawn(async move {
let mut buf = BytesMut::with_capacity(4096);
// let mut buf = Vec::with_capacity(4096);
loop {
buf.clear();
match reader.read_buf(&mut buf).await {
Ok(len) => println!("Tag: {}, Len: {}, Buf: [[ {} ]]", &tag, len, String::from_utf8_lossy(&buf[..len])),
Err(e) => {
println!("Tag: {}, Err: {:?}", &tag, e);
if e.to_string().contains("broken pipe") {
break;
}
}
}
}
})
}
fn loop_consume(mut receiver: Receiver<StreamPackage>, stream_map: Arc<Mutex<HashMap<u64, Sender<StreamPackage>>>>) {
tokio::spawn(async move {
loop {
match receiver.recv().await {
None => {
println!("Receiver none");
break;
}
Some(package) => {
let channel_id = package.channel_id;
let sender = {
let stream_map_locked = &stream_map.lock().unwrap();
stream_map_locked.get(&channel_id).map(|s| s.clone())
};
match sender {
None => println!("Channel id not found: {}", channel_id),
Some(sender) => {
// TODO process result
let _ = sender.send(package).await;
}
}
}
}
}
});
}
#[derive(Debug)]
struct StreamPackage {
channel_id: u64,
message: StreamPackageMessage,
}
#[derive(Debug)]
enum StreamPackageMessage {
Data(Vec<u8>),
Flush,
Close,
}
struct Stream {
channel_id: u64,
sender: Sender<StreamPackage>,
receiver: Receiver<StreamPackage>,
}
impl AsyncRead for Stream {
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<io::Result<()>> {
let m = self.receiver.poll_recv(cx);
match m {
Poll::Pending => Poll::Pending,
Poll::Ready(m_opt) => match m_opt {
None => Poll::Ready(Err(io::Error::new(ErrorKind::BrokenPipe, "broken pipe"))),
Some(package) => match package.message {
StreamPackageMessage::Close => {
self.receiver.close();
// Poll::Ready(Ok(()))
Poll::Ready(Err(io::Error::new(ErrorKind::BrokenPipe, "broken pipe")))
}
StreamPackageMessage::Flush => Poll::Ready(Ok(())),
StreamPackageMessage::Data(mm) => {
buf.put_slice(mm.as_slice());
Poll::Ready(Ok(()))
}
}
}
}
}
}
impl AsyncWrite for Stream {
fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<io::Result<usize>> {
let stream_package = StreamPackage { channel_id: self.channel_id, message: StreamPackageMessage::Data(Vec::from(buf)) };
pool_send(self, cx, stream_package, buf.len())
}
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
let stream_package = StreamPackage { channel_id: self.channel_id, message: StreamPackageMessage::Flush };
pool_send(self, cx, stream_package, ())
}
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
let stream_package = StreamPackage { channel_id: self.channel_id, message: StreamPackageMessage::Close };
pool_send(self, cx, stream_package, ())
}
}
fn pool_send<R>(s: Pin<&mut Stream>, cx: &mut Context<'_>, stream_package: StreamPackage, r: R) -> Poll<io::Result<R>> {
let fut = s.sender.send(stream_package);
tokio::pin!( fut);
match fut.poll(cx) {
Poll::Pending => Poll::Pending,
Poll::Ready(Ok(_)) => Poll::Ready(Ok(r)),
Poll::Ready(Err(e)) => Poll::Ready(Err(io::Error::new(ErrorKind::BrokenPipe, e.to_string()))),
}
}

View File

@@ -0,0 +1,203 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "const_fn"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826"
[[package]]
name = "crossbeam"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd01a6eb3daaafa260f6fc94c3a6c36390abc2080e38e3e34ced87393fb77d80"
dependencies = [
"cfg-if",
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-epoch",
"crossbeam-queue",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d"
dependencies = [
"cfg-if",
"const_fn",
"crossbeam-utils",
"lazy_static",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-queue"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f6cb3c7f5b8e51bc3ebb73a2327ad4abdbd119dc13223f14f961d2f38486756"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d"
dependencies = [
"autocfg",
"cfg-if",
"lazy_static",
]
[[package]]
name = "crossbeam_n_parking_lot"
version = "0.1.0"
dependencies = [
"crossbeam",
"crossbeam-channel",
"lock_api",
"parking_lot",
]
[[package]]
name = "instant"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
dependencies = [
"cfg-if",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
[[package]]
name = "lock_api"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd96ffd135b2fd7b973ac026d28085defbe8983df057ced3eb4f2130b0831312"
dependencies = [
"scopeguard",
]
[[package]]
name = "memoffset"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87"
dependencies = [
"autocfg",
]
[[package]]
name = "parking_lot"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ccb628cad4f84851442432c60ad8e1f607e29752d0bf072cbd0baf28aa34272"
dependencies = [
"cfg-if",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi",
]
[[package]]
name = "redox_syscall"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "smallvec"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@@ -0,0 +1,13 @@
[package]
name = "crossbeam_n_parking_lot"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
crossbeam = "0.8.0"
crossbeam-channel = "0.5.0"
parking_lot = "0.11.1"
lock_api = "0.4.2"

View File

@@ -0,0 +1,37 @@
use std::thread;
use crossbeam_channel::bounded;
fn main() {
let (s, r) = bounded(100);
let mut ts = vec![];
for ti in 0..4 {
let copied_sender = s.clone();
let t = thread::spawn(move|| {
println!("Start: {}", ti);
for i in 0..100000_u64 {
copied_sender.send(Some(i)).unwrap();
}
println!("End: {}", ti);
});
ts.push(t);
}
let tt = thread::spawn(move || {
println!("Start collect");
let mut sum = 0_u64;
loop {
let x = r.recv().unwrap();
match x {
None => break,
Some(x) => sum+=x,
}
}
println!("Enc collect");
println!("Sum: {}", sum);
});
for t in ts {
t.join().unwrap();
}
s.send(None).unwrap();
tt.join().unwrap();
}

View File

@@ -0,0 +1,8 @@
_:
@just --list
ex-multi-chan:
cargo r --example multi_chan

View File

@@ -0,0 +1,38 @@
// use crossbeam::atomic::AtomicCell;
use crossbeam_channel::unbounded;
use parking_lot::FairMutex;
use parking_lot::RwLock;
use std::sync::Arc;
use std::thread;
use std::time::Duration;
fn main() {
let mutex = Arc::new(FairMutex::new(0_i32));
let rw_lock = Arc::new(RwLock::new(0_i32));
// let cell = AtomicCell::new(0_i32);
let (s, r) = unbounded::<i32>();
let thead_mutex = mutex.clone();
let thread_rw_lock = rw_lock.clone();
thread::spawn(move || {
for i in 1..=10 {
thread::sleep(Duration::from_millis(500));
s.send(i).unwrap();
let mut m = thead_mutex.lock();
*m += 1;
let mut rw = thread_rw_lock.write();
*rw += 1;
}
s.send(-1).unwrap();
});
loop {
let x = r.recv().unwrap();
if x < 0 {
break;
}
println!("Received: {}, mutext: {}, rw_lock: {}", x, *mutex.lock(), *rw_lock.read());
}
}

296
__concurrent/glommio/Cargo.lock generated Normal file
View File

@@ -0,0 +1,296 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aligned_alloc"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dcebfb002ccde769c15bc841d0d5548a90e80fcd2ffed5131339e8074746f0a"
dependencies = [
"kernel32-sys",
"libc",
"winapi 0.2.8",
]
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "bitmaps"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2"
dependencies = [
"typenum",
]
[[package]]
name = "cache-padded"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba"
[[package]]
name = "cc"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "concurrent-queue"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3"
dependencies = [
"cache-padded",
]
[[package]]
name = "enclose"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1056f553da426e9c025a662efa48b52e62e0a3a7648aa2d15aeaaf7f0d329357"
[[package]]
name = "fastrand"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3"
dependencies = [
"instant",
]
[[package]]
name = "futures-core"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748"
[[package]]
name = "futures-io"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb"
[[package]]
name = "futures-lite"
version = "1.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb"
dependencies = [
"fastrand",
"futures-core",
"futures-io",
"memchr",
"parking",
"pin-project-lite 0.2.0",
"waker-fn",
]
[[package]]
name = "glommio"
version = "0.1.0"
dependencies = [
"glommio 0.2.0-alpha",
]
[[package]]
name = "glommio"
version = "0.2.0-alpha"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7c1a8b6b7726d600964e723d5b27127b871685d09359981a6b1e9e8739fec5d"
dependencies = [
"aligned_alloc",
"bitflags",
"bitmaps",
"cc",
"concurrent-queue",
"enclose",
"futures-lite",
"lazy_static",
"libc",
"log",
"nix",
"pin-project-lite 0.1.11",
"rlimit",
"scoped-tls",
"scopeguard",
"socket2",
"typenum",
]
[[package]]
name = "instant"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec"
dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
[[package]]
name = "log"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if 0.1.10",
]
[[package]]
name = "memchr"
version = "2.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]]
name = "nix"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0eaf8df8bab402257e0a5c17a254e4cc1f72a93588a1ddfb5d356c801aa7cb"
dependencies = [
"bitflags",
"cc",
"cfg-if 0.1.10",
"libc",
"void",
]
[[package]]
name = "parking"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
[[package]]
name = "pin-project-lite"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b"
[[package]]
name = "pin-project-lite"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c"
[[package]]
name = "rlimit"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6d26e65e82a1e2628c5f209ec12f4508fa50e644bd2f264138e60129d61eae8"
dependencies = [
"cfg-if 0.1.10",
"libc",
]
[[package]]
name = "scoped-tls"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "socket2"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e"
dependencies = [
"cfg-if 1.0.0",
"libc",
"winapi 0.3.9",
]
[[package]]
name = "typenum"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "waker-fn"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca"
[[package]]
name = "winapi"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@@ -0,0 +1,10 @@
[package]
name = "glommio"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
glommio = "0.2.0-alpha"

View File

@@ -0,0 +1,7 @@
build failed!
url
https://crates.io/crates/glommio

View File

@@ -0,0 +1,7 @@
use glommio::prelude::*;
fn main() {
LocalExecutorBuilder::new().spawn(|| async move {
/// your code here
}).unwrap();
}

5
__concurrent/green-threads/Cargo.lock generated Normal file
View File

@@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "green-threads"
version = "0.1.0"

View File

@@ -0,0 +1,9 @@
[package]
name = "green-threads"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@@ -0,0 +1,8 @@
https://zhuanlan.zhihu.com/p/101061389
https://cfsamson.gitbook.io/green-threads-explained-in-200-lines-of-rust/final-200-lines-of-code
https://github.com/cfsamson/example-greenthreads

View File

@@ -0,0 +1 @@
nightly

View File

@@ -0,0 +1,200 @@
#![feature(llvm_asm, naked_functions)]
const DEFAULT_STACK_SIZE: usize = 1024 * 1024 * 2;
const MAX_THREADS: usize = 4;
static mut RUNTIME: usize = 0;
pub struct Runtime {
threads: Vec<Thread>,
current: usize,
}
#[derive(PartialEq, Eq, Debug)]
enum State {
Available,
Running,
Ready,
}
struct Thread {
id: usize,
stack: Vec<u8>,
ctx: ThreadContext,
state: State,
}
#[derive(Debug, Default)]
#[repr(C)]
struct ThreadContext {
rsp: u64,
r15: u64,
r14: u64,
r13: u64,
r12: u64,
rbx: u64,
rbp: u64,
}
impl Thread {
fn new(id: usize) -> Self {
Thread {
id,
stack: vec![0_u8; DEFAULT_STACK_SIZE],
ctx: ThreadContext::default(),
state: State::Available,
}
}
}
impl Runtime {
pub fn new() -> Self {
let base_thread = Thread {
id: 0,
stack: vec![0_u8; DEFAULT_STACK_SIZE],
ctx: ThreadContext::default(),
state: State::Running,
};
let mut threads = vec![base_thread];
let mut available_threads: Vec<Thread> = (1..MAX_THREADS).map(|i| Thread::new(i)).collect();
threads.append(&mut available_threads);
Runtime {
threads,
current: 0,
}
}
pub fn init(&self) {
unsafe {
let r_ptr: *const Runtime = self;
RUNTIME = r_ptr as usize;
}
}
pub fn run(&mut self) -> ! {
while self.t_yield() {}
std::process::exit(0);
}
fn t_return(&mut self) {
if self.current != 0 {
self.threads[self.current].state = State::Available;
self.t_yield();
}
}
fn t_yield(&mut self) -> bool {
let mut pos = self.current;
while self.threads[pos].state != State::Ready {
pos += 1;
if pos == self.threads.len() {
pos = 0;
}
if pos == self.current {
return false;
}
}
if self.threads[self.current].state != State::Available {
self.threads[self.current].state = State::Ready;
}
self.threads[pos].state = State::Running;
let old_pos = self.current;
self.current = pos;
unsafe {
switch(&mut self.threads[old_pos].ctx, &self.threads[pos].ctx);
}
self.threads.len() > 0
}
pub fn spawn(&mut self, f: fn()) {
let available = self
.threads
.iter_mut()
.find(|t| t.state == State::Available)
.expect("no available thread.");
let size = available.stack.len();
unsafe {
let s_ptr = available.stack.as_mut_ptr().offset(size as isize);
let s_ptr = (s_ptr as usize & !15) as *mut u8;
std::ptr::write(s_ptr.offset(-16) as *mut u64, guard as u64);
std::ptr::write(s_ptr.offset(-24) as *mut u64, skip as u64);
std::ptr::write(s_ptr.offset(-32) as *mut u64, f as u64);
available.ctx.rsp = s_ptr.offset(-32) as u64;
}
available.state = State::Ready;
}
}
#[naked]
fn skip() { }
fn guard() {
unsafe {
let rt_ptr = RUNTIME as *mut Runtime;
(*rt_ptr).t_return();
};
}
pub fn yield_thread() {
unsafe {
let rt_ptr = RUNTIME as *mut Runtime;
(*rt_ptr).t_yield();
};
}
#[naked]
#[inline(never)]
unsafe fn switch(old: *mut ThreadContext, new: *const ThreadContext) {
llvm_asm!("
mov %rsp, 0x00($0)
mov %r15, 0x08($0)
mov %r14, 0x10($0)
mov %r13, 0x18($0)
mov %r12, 0x20($0)
mov %rbx, 0x28($0)
mov %rbp, 0x30($0)
mov 0x00($1), %rsp
mov 0x08($1), %r15
mov 0x10($1), %r14
mov 0x18($1), %r13
mov 0x20($1), %r12
mov 0x28($1), %rbx
mov 0x30($1), %rbp
ret
"
:
:"r"(old), "r"(new)
:
: "volatile", "alignstack"
);
}
fn main() {
let mut runtime = Runtime::new();
runtime.init();
runtime.spawn(|| {
println!("THREAD 1 STARTING");
let id = 1;
for i in 0..10 {
println!("thread: {} counter: {}", id, i);
yield_thread();
}
println!("THREAD 1 FINISHED");
});
runtime.spawn(|| {
println!("THREAD 2 STARTING");
let id = 2;
for i in 0..15 {
println!("thread: {} counter: {}", id, i);
yield_thread();
}
println!("THREAD 2 FINISHED");
});
runtime.run();
}

25
__concurrent/qcell/Cargo.lock generated Normal file
View File

@@ -0,0 +1,25 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "once_cell"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]]
name = "qcell"
version = "0.1.0"
dependencies = [
"qcell 0.5.0",
]
[[package]]
name = "qcell"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5023f06b72bfa9fbb5ebdbe891f02db9406ba026990e0778f80094bc84f3ac8"
dependencies = [
"once_cell",
]

View File

@@ -0,0 +1,10 @@
[package]
name = "qcell"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
qcell = "0.5.0"

View File

@@ -0,0 +1,16 @@
use std::rc::Rc;
use qcell::{QCell, QCellOwner};
// https://docs.rs/qcell/latest/qcell/
fn main() {
let mut owner = QCellOwner::new();
let item = Rc::new(QCell::new(&owner, Vec::<u8>::new()));
let iref = owner.rw(&item);
// test(&mut owner, &item); // Compile error
iref.push(1);
fn test(owner: &mut QCellOwner, item: &Rc<QCell<Vec<u8>>>) {
owner.rw(&item).push(2);
}
}

149
__concurrent/rayon/Cargo.lock generated Normal file
View File

@@ -0,0 +1,149 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "const_fn"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826"
[[package]]
name = "crossbeam-channel"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d"
dependencies = [
"cfg-if",
"const_fn",
"crossbeam-utils",
"lazy_static",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d"
dependencies = [
"autocfg",
"cfg-if",
"lazy_static",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "hermit-abi"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
dependencies = [
"libc",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
[[package]]
name = "memoffset"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "rayon"
version = "0.1.0"
dependencies = [
"rayon 1.5.0",
]
[[package]]
name = "rayon"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b0d8e0819fadc20c74ea8373106ead0600e3a67ef1fe8da56e39b9ae7275674"
dependencies = [
"autocfg",
"crossbeam-deque",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ab346ac5921dc62ffa9f89b7a773907511cdfa5490c572ae9be1be33e8afa4a"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"lazy_static",
"num_cpus",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"

View File

@@ -0,0 +1,11 @@
[package]
name = "rayon"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rayon = "1.5.0"

View File

@@ -0,0 +1,32 @@
use rayon::prelude::*;
fn main() {
println!("{}", sum_of_squares(&vec![11, 22, 3, 4, 5, 6, 7]));
println!("{}", fib_iterative(40));
println!("{}", fib_recursive(40));
}
fn sum_of_squares(input: &[i32]) -> i32 {
input.par_iter() // <-- just change that!
.map(|&i| i * i)
.sum()
}
fn fib_iterative(n: u128) -> u128 {
let mut a = 0;
let mut b = 1;
for _ in 0..n {
let c = a + b;
a = b;
b = c;
}
a
}
fn fib_recursive(n: u128) -> u128 {
if n < 2 {
return n;
}
fib_recursive(n - 1) + fib_recursive(n - 2)
}

444
__concurrent/waitgroup-demo/Cargo.lock generated Normal file
View File

@@ -0,0 +1,444 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "atomic-waker"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "autocfg"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
[[package]]
name = "backtrace"
version = "0.3.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "bitflags"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
[[package]]
name = "bytes"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
[[package]]
name = "cc"
version = "1.0.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "065a29261d53ba54260972629f9ca6bffa69bac13cd1fed61420f7fa68b9f8bd"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "gimli"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "hermit-abi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "libc"
version = "0.2.154"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346"
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "memchr"
version = "2.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
[[package]]
name = "miniz_oxide"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7"
dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
dependencies = [
"libc",
"wasi",
"windows-sys 0.48.0",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "object"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"memchr",
]
[[package]]
name = "parking_lot"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets 0.52.5",
]
[[package]]
name = "pin-project-lite"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
[[package]]
name = "proc-macro2"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
dependencies = [
"bitflags",
]
[[package]]
name = "rustc-demangle"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [
"libc",
]
[[package]]
name = "smallvec"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "socket2"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c"
dependencies = [
"libc",
"windows-sys 0.52.0",
]
[[package]]
name = "syn"
version = "2.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tokio"
version = "1.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-macros"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "waitgroup"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1f50000a783467e6c0200f9d10642f4bc424e39efc1b770203e88b488f79292"
dependencies = [
"atomic-waker",
]
[[package]]
name = "waitgroup-demo"
version = "0.1.0"
dependencies = [
"tokio",
"waitgroup",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets 0.52.5",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
name = "windows-targets"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm 0.52.5",
"windows_aarch64_msvc 0.52.5",
"windows_i686_gnu 0.52.5",
"windows_i686_gnullvm",
"windows_i686_msvc 0.52.5",
"windows_x86_64_gnu 0.52.5",
"windows_x86_64_gnullvm 0.52.5",
"windows_x86_64_msvc 0.52.5",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"

View File

@@ -0,0 +1,10 @@
[package]
name = "waitgroup-demo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.37.0", features = ["full"] }
waitgroup = "0.1.2"

View File

@@ -0,0 +1,26 @@
use std::time::Duration;
use tokio::task::yield_now;
use tokio::time;
use tokio::time::Instant;
use waitgroup::WaitGroup;
#[tokio::main]
async fn main() {
let wg = WaitGroup::new();
for i in 80..100 {
let w = wg.worker();
tokio::spawn(async move {
println!("Start work #{}", i);
time::sleep(Duration::from_millis(i * 100)).await;
println!("Finish work #{}", i);
drop(w);
});
yield_now().await;
}
let instant = Instant::now();
println!("Start waiting...");
wg.wait().await;
println!("Finish wait, elapsed: {}ms", instant.elapsed().as_millis());
}

72
__cpu/x86/Cargo.lock generated Normal file
View File

@@ -0,0 +1,72 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "bit_field"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4"
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "cc"
version = "1.0.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1770ced377336a88a67c473594ccc14eca6f4559217c34f64aac8f83d641b40"
[[package]]
name = "raw-cpuid"
version = "8.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fdf7d9dbd43f3d81d94a49c1c3df73cc2b3827995147e6cf7f89d4ec5483e73"
dependencies = [
"bitflags",
"cc",
"rustc_version",
]
[[package]]
name = "rustc_version"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
dependencies = [
"semver",
]
[[package]]
name = "semver"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
dependencies = [
"semver-parser",
]
[[package]]
name = "semver-parser"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "x86"
version = "0.1.0"
dependencies = [
"x86 0.34.0",
]
[[package]]
name = "x86"
version = "0.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c146cbc47471e076987378c159a7aa8fa434680c6fbddca59fe6f40f1591c819"
dependencies = [
"bit_field",
"bitflags",
"raw-cpuid",
]

11
__cpu/x86/Cargo.toml Normal file
View File

@@ -0,0 +1,11 @@
[package]
name = "x86"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
x86 = "0.34"

4
__cpu/x86/README.md Normal file
View File

@@ -0,0 +1,4 @@
crate:
https://github.com/gz/rust-x86

1
__cpu/x86/rust-toolchain Normal file
View File

@@ -0,0 +1 @@
nightly

20
__cpu/x86/src/main.rs Normal file
View File

@@ -0,0 +1,20 @@
use x86::cpuid::CpuId;
fn main() {
let cpu_id = CpuId::new();
println!("Vendor: {:?}", cpu_id.get_vendor_info().map(|v| v.as_string().to_owned()));
println!("Feature: {:?}", cpu_id.get_feature_info());
println!("Cache: {:?}", cpu_id.get_cache_info());
cpu_id.get_cache_info().map(|c| {
for i in c {
println!("- {}", i.desc());
}
});
println!("Processor: {:?}", cpu_id.get_processor_serial());
println!("Cache parameters: {:?}", cpu_id.get_cache_parameters());
println!("Performace monitoring: {:?}", cpu_id.get_performance_monitoring_info());
println!("Performace monitoring, number of counters: {:?}", cpu_id.get_performance_monitoring_info().unwrap().number_of_counters());
println!("SGX: {:?}", cpu_id.get_sgx_info());
println!("SoC vendor: {:?}", cpu_id.get_soc_vendor_info());
println!("Extended function: {:?}", cpu_id.get_extended_function_info());
}

4
__crypto/README.md Normal file
View File

@@ -0,0 +1,4 @@
Cryptography:
https://cryptography.rs/

454
__crypto/aegis-test/Cargo.lock generated Normal file
View File

@@ -0,0 +1,454 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aead"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
dependencies = [
"crypto-common",
"generic-array",
]
[[package]]
name = "aegis"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f5bfadafb4f9094ee03767a64997e6645cf29243d6d4c04158212b8663f9d6d"
dependencies = [
"cc",
"softaes",
]
[[package]]
name = "aegis-test"
version = "0.1.0"
dependencies = [
"aegis",
"aes-gcm",
"ascon-aead",
"benchmark-simple",
"chacha20poly1305",
"rocca",
]
[[package]]
name = "aes"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac1f845298e95f983ff1944b728ae08b8cebab80d684f0a832ed0fc74dfa27e2"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
]
[[package]]
name = "aes-gcm"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "209b47e8954a928e1d72e86eca7000ebb6655fe1436d33eefc2201cad027e237"
dependencies = [
"aead",
"aes",
"cipher",
"ctr",
"ghash",
"subtle",
]
[[package]]
name = "ascon"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fe9a0cff241855e9166670d259192aacf1e9a81b865dc9905afbbab31a9d2c1"
[[package]]
name = "ascon-aead"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf081c54f55de655350e71e01dd36e093012f11447a3d575b907b84425887fa3"
dependencies = [
"aead",
"ascon",
"subtle",
"zeroize",
]
[[package]]
name = "benchmark-simple"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f87ada40e82bfa2716c35e99c1969299d3a17ce8ec05d58145d4056da16ea2c4"
dependencies = [
"precision",
]
[[package]]
name = "bumpalo"
version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
[[package]]
name = "cc"
version = "1.0.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01"
dependencies = [
"libc",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chacha20"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
]
[[package]]
name = "chacha20poly1305"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35"
dependencies = [
"aead",
"chacha20",
"cipher",
"poly1305",
"zeroize",
]
[[package]]
name = "cipher"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"crypto-common",
"inout",
"zeroize",
]
[[package]]
name = "cpufeatures"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"rand_core",
"typenum",
]
[[package]]
name = "ctr"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835"
dependencies = [
"cipher",
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "getrandom"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "ghash"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d930750de5717d2dd0b8c0d42c076c0e884c81a73e6cab859bbd2339c71e3e40"
dependencies = [
"opaque-debug",
"polyval",
]
[[package]]
name = "inout"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
dependencies = [
"generic-array",
]
[[package]]
name = "libc"
version = "0.2.147"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
[[package]]
name = "log"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "once_cell"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "opaque-debug"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "poly1305"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf"
dependencies = [
"cpufeatures",
"opaque-debug",
"universal-hash",
]
[[package]]
name = "polyval"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52cff9d1d4dee5fe6d03729099f4a310a41179e0a10dbf542039873f2e826fb"
dependencies = [
"cfg-if",
"cpufeatures",
"opaque-debug",
"universal-hash",
]
[[package]]
name = "precision"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ae7cc38dee6656eeb0eee56a8aef8aa40d5128acd9c4b8bdfb80ae08ee1993"
dependencies = [
"cc",
"libc",
"rustc_version",
"wasi",
"wasm-bindgen",
]
[[package]]
name = "proc-macro2"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rocca"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b52de49d9fde07d1241f2156a8958b65c71ce615f2ff8256ae5106513eb1713e"
dependencies = [
"aes",
]
[[package]]
name = "rustc_version"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
dependencies = [
"semver",
]
[[package]]
name = "semver"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
[[package]]
name = "softaes"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff744c5d37b8ff11721ef14e92d1ec8743b5419d81513b3df22346cbee3d9d3e"
[[package]]
name = "subtle"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
[[package]]
name = "syn"
version = "2.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "typenum"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "unicode-ident"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
[[package]]
name = "universal-hash"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
dependencies = [
"crypto-common",
"subtle",
]
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "zeroize"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9"
dependencies = [
"zeroize_derive",
]
[[package]]
name = "zeroize_derive"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [
"proc-macro2",
"quote",
"syn",
]

View File

@@ -0,0 +1,14 @@
[package]
name = "aegis-test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
aegis = "0.4.4"
aes-gcm = "0.10.2"
ascon-aead = "0.4.2"
benchmark-simple = "0.1.8"
chacha20poly1305 = "0.10.1"
rocca = "0.3.0"

View File

@@ -0,0 +1,62 @@
Benchmark:
```shell
$ cargo r --release
aegis128l : 10.63 G/s
aes256-gcm : 546.31 M/s
aes128-gcm : 597.56 M/s
chacha20-poly1305 : 1.03 G/s
ascon128a : 330.85 M/s
rocca : 307.84 M/s
```
```shell
$ RUSTFLAGS="-C target-cpu=native" cargo r --release
aegis128l : 10.66 G/s
aes256-gcm : 701.21 M/s
aes128-gcm : 794.85 M/s
chacha20-poly1305 : 1.18 G/s
ascon128a : 347.18 M/s
rocca : 4.35 G/s
```
```shell
$ RUSTFLAGS="-Ctarget-feature=+aes,+sse4.1" cargo r --release
aegis128l : 10.68 G/s
aes256-gcm : 554.68 M/s
aes128-gcm : 608.58 M/s
chacha20-poly1305 : 1.04 G/s
ascon128a : 337.74 M/s
rocca : 2.75 G/s
```
```shell
$ RUSTFLAGS="-Ctarget-feature=+aes,+sse4.2" cargo r --release
aegis128l : 10.74 G/s
aes256-gcm : 706.54 M/s
aes128-gcm : 797.11 M/s
chacha20-poly1305 : 1.04 G/s
ascon128a : 338.19 M/s
rocca : 6.05 G/s
```
```shell
$ RUSTFLAGS="-C target-cpu=native -Ctarget-feature=+aes,+pclmulqdq,+sse4.1" cargo r --release
aegis128l : 10.62 G/s
aes256-gcm : 695.29 M/s
aes128-gcm : 778.97 M/s
chacha20-poly1305 : 1.17 G/s
ascon128a : 345.49 M/s
rocca : 4.28 G/s
```
```shell
$ RUSTFLAGS="-C target-cpu=native -Ctarget-feature=+aes,+pclmulqdq,+sse4.2" cargo r --release
aegis128l : 10.60 G/s
aes256-gcm : 692.76 M/s
aes128-gcm : 760.85 M/s
chacha20-poly1305 : 1.18 G/s
ascon128a : 344.81 M/s
rocca : 4.28 G/s
```

View File

@@ -0,0 +1,84 @@
use aegis::aegis128l::Aegis128L;
use aes_gcm::{
aead::{AeadInPlace as _, KeyInit as _},
Aes128Gcm, Aes256Gcm,
};
use benchmark_simple::*;
use chacha20poly1305::ChaCha20Poly1305;
use rocca::Rocca;
fn test_aes256gcm(m: &mut [u8]) {
let key = aes_gcm::Key::<Aes256Gcm>::from_slice(&[0u8; 32]);
let nonce = aes_gcm::Nonce::from_slice(&[0u8; 12]);
let state = Aes256Gcm::new(key);
state.encrypt_in_place_detached(nonce, &[], m).unwrap();
}
fn test_aes128gcm(m: &mut [u8]) {
let key = aes_gcm::Key::<Aes128Gcm>::from_slice(&[0u8; 16]);
let nonce = aes_gcm::Nonce::from_slice(&[0u8; 12]);
let state = Aes128Gcm::new(key);
state.encrypt_in_place_detached(nonce, &[], m).unwrap();
}
fn test_chacha20poly1305(m: &mut [u8]) {
let key = chacha20poly1305::Key::from_slice(&[0u8; 32]);
let nonce = chacha20poly1305::Nonce::from_slice(&[0u8; 12]);
let state = ChaCha20Poly1305::new(key);
state.encrypt_in_place_detached(nonce, &[], m).unwrap();
}
fn test_ascon128a(m: &mut [u8]) {
let key = [0u8; 16];
let nonce = [0u8; 16];
let state = ascon_aead::Ascon128a::new(key.as_slice().into());
state
.encrypt_in_place_detached(nonce.as_slice().into(), &[], m)
.unwrap();
}
fn test_aegis128l(m: &mut [u8]) {
let key = [0u8; 16];
let nonce = [0u8; 16];
let state = Aegis128L::<16>::new(&nonce, &key);
state.encrypt_in_place(m, &[]);
}
fn test_rocca(m: &mut [u8]) {
let key = [0u8; 32];
let nonce = [0u8; 16];
let state = Rocca::new(&nonce, &key);
state.encrypt_in_place(m, &[]);
}
fn main() {
let bench = Bench::new();
let mut m = vec![0xd0u8; 16384];
let options = &Options {
iterations: 10_000, // 100_000 -> 10_000 -> 1_000
warmup_iterations: 1_000,
min_samples: 5,
max_samples: 10,
max_rsd: 1.0,
..Default::default()
};
let res = bench.run(options, || test_aegis128l(&mut m));
println!("aegis128l : {}", res.throughput(m.len() as _));
let res = bench.run(options, || test_aes256gcm(&mut m));
println!("aes256-gcm : {}", res.throughput(m.len() as _));
let res = bench.run(options, || test_aes128gcm(&mut m));
println!("aes128-gcm : {}", res.throughput(m.len() as _));
let res = bench.run(options, || test_chacha20poly1305(&mut m));
println!("chacha20-poly1305 : {}", res.throughput(m.len() as _));
let res = bench.run(options, || test_ascon128a(&mut m));
println!("ascon128a : {}", res.throughput(m.len() as _));
let res = bench.run(options, || test_rocca(&mut m));
println!("rocca : {}", res.throughput(m.len() as _));
}

100
__crypto/aes_ctr_test/Cargo.lock generated Normal file
View File

@@ -0,0 +1,100 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aes"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
]
[[package]]
name = "aes_ctr_test"
version = "0.1.0"
dependencies = [
"aes",
"hex",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cipher"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"crypto-common",
"inout",
]
[[package]]
name = "cpufeatures"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "inout"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
dependencies = [
"generic-array",
]
[[package]]
name = "libc"
version = "0.2.158"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"

View File

@@ -0,0 +1,8 @@
[package]
name = "aes_ctr_test"
version = "0.1.0"
edition = "2021"
[dependencies]
aes = "0.8.4"
hex = "0.4.3"

View File

@@ -0,0 +1,42 @@
Test Java codes:
```java
public class AesCtrTest {
public static void main(String[] args) throws Exception {
final byte[] key = new byte[]{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
};
final byte[] iv = new byte[]{
1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0
};
final SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
final Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(iv));
System.out.println(Bytes.from(cipher.doFinal("hello world".getBytes())).asHex());
System.out.println(Bytes.from(cipher.doFinal(
"hello world.hello world.hello world.hello world.hello world.hello world.".getBytes())).asHex());
}
}
```
Outputs:
```
84ad8d80732490c061177a
84ad8d80732490c061177a58bd26d032d6fcff2e66f9afe3cf95717485d3a4485d4a2a7bd835df3d0756b8192e3bf5a287ad8dd81942c43bc812c82d666ebbb34df4e2a5069467d9
```
<br>
Java `nonce` counter:
`com.sun.crypto.provider.CounterMode`
```java
private static void increment(byte[] nonce) {
for(int index = nonce.length - 1; index >= 0 && ++nonce[index] == 0; --index) {
}
}
```

View File

@@ -0,0 +1,109 @@
use aes::cipher::generic_array::GenericArray;
use aes::cipher::{Block, BlockEncryptMut, KeyInit};
use aes::Aes128;
fn main() {
let key = [0_u8; 16];
let iv = [0_u8; 16];
let plaintext = b"hello world";
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
assert_eq!("0e8c27b880aa5b54fa209e", hex::encode(&ciphertext));
let plaintext = b"hello world.hello world.hello world.hello world.hello world.hello world.";
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
assert_eq!("0e8c27b880aa5b54fa209e77a251474237c28ba18812544f5e1a713bcbc7323571e4bee008d3cf\
fe9c08b5d603de9a569ff0c6c7266b2e4c8591edd1fceead8c4f22664e3c1ff0f4", hex::encode(&ciphertext));
let key = [1_u8; 16];
let mut iv = [0_u8; 16];
for i in 0..8 {
iv[i] = i as u8 + 1;
}
let plaintext = b"hello world.hello world.hello world.hello world.hello world.hello world.";
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
assert_eq!("84ad8d80732490c061177a58bd26d032d6fcff2e66f9afe3cf95717485d3a4485d4a2a7bd835df\
3d0756b8192e3bf5a287ad8dd81942c43bc812c82d666ebbb34df4e2a5069467d9", hex::encode(&ciphertext));
let key = [1_u8; 16];
let iv = [1, 2, 3, 4, 5, 6, 7, 0, 1, 1, 2, 2, 3, 3, 4, 4];
let plaintext = b"hello world.hello world.hello world.hello world.hello world.hello world.";
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
assert_eq!("d373d6b3491c7b8940996f9efefc98d0f564d066a557cf0aa29935a638f99d077a85338e574ee6\
7f69da41b8a87569c324b4d421f1350e11d6be30721605b9dd6401bc3780da3452", hex::encode(&ciphertext));
let key = [1_u8; 16];
let iv = [1, 2, 3, 4, 5, 6, 7, 0, 1, 1, 2, 2, 3, 3, 4, 4];
let plaintext = b"hello world.hello world.hello world.hello world.hello world.h\
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
ello world.hello world.hello world.hello world.hello world.hello world.hello world.hello w\
orld.hello world.hello world.hello world.hello world.hello world.hello world.hello world.h\
ello world.hello world.hello world.hello world.";
let ciphertext = encrypt_ctr(&key, &iv, plaintext);
assert_eq!("d373d6b3491c7b8940996f9efefc98d0f564d066a557cf0aa29935a638f99d077a85338e574ee6\
7f69da41b8a87569c324b4d421f1350e11d6be30721605b9dd6401bc3780da3452033164403472b0ea84a7894b\
500100959ccc2cfbe2b6792691f1a1b047755c1961a730c7bcd941ab50b4ece7501d624d5af457875370dbc7e6\
0e73fd6ab10b5033fb3b3e2caed7489cc02bf174a3e7f04bd1e5c81c811314689b2bb7f6f0f0333d9b3bf637ff\
7ac34b32bc4905638204dbd97d4cefd1a823b5d49364c72d987807991eb703e47d56631f9f1a62c9f691bd3641\
509884144fc6e1b63e8177c8e1247ccc0769cb59cd973869f2ac3dd6cb90534ee42f69995e4af48de870936d21\
cf1b4ccd52e4bd0eafaff46dd6f34c91072ffd61f73050580b790deba9dc30d9557c4142a0dfa52b70e050a563\
abd69e87150da9325751a58bb3e162ea3a69347684e50710ea2bd25f6c285903d7b200a56a7eb042639410da17\
471c93e2b26b13091cc22ec81c3912a7121a1337a560d9733d904b6c6752993b2943861d3b770693281d3519fb\
69158df2353913aebe1e6c16787b8d2ff363c1c31bb8b491cec0214bd3ef61357569c8ecf9487087e22eca48b2\
d1c2c718ad7d3984eb7d0ca27b96653d90847ed138b581f8a01c0bea33c435e7f124f4009de059c46c006431fa\
5cf41ad9f16e6457389f928216ebd4efd048840a4dbc80da170c666a5293209866e9371f47005a12d6dc76f7fd\
57fc5b265cc38f4aef6e5496836d1c4c6d96b2c807997b3f61fd45f0acf505f3512ea04a0ad89cc35b344bdc3f\
2126b24bee40406ff00a733555316b8ccb57d661326d6b2d48a7a7fe33fbec23d69890b9368f6321d60b231cf2\
5680bcf7e8f43e443c19150b72394b5a9617fb8cc9666d43968fecdb56c22db6421ffbe3351fe479d9e7841288\
15fbeb7f1b5f9dc1f8b3d772741f7ef9884b5ca81d972d8537ea4c12cbf29c7e362ccd14ed83781db312da5d83\
8e11b20b050b6be472d8133f8f6525649dc9b967d40f430feb4cb3408a623a12658959f8cd8a115d8f63dd6e8b\
b8449937620b1cf783a0761fcbd4f48dcb572c1463a7c756bf9dd77d45f92cfe9a04dfb4d007a448d9b1a8c936\
9bcd35db598e7cdec566d075ff4c8d445e94ef49c0d0a78bb45921bf4c6e6b750a4d0f3310fc9a767a368ced10\
293987bf88026c69dcd805aea561d9b207c2710e6e90658ec5e0f8560449889ba8af852ea36b272aebb73ef59e\
74d1c0fe963ecbf1049743263681f5733cdf3b0b89b52667f63f65e4e7327ca45a2c1bd385f7c5fbf74b82e4f8\
0425c237813f2d39c4d7a06b49eec49b26dd234323747cf41eb4c2a7647b8548dcd72d59a4f0da2b1120759cfc\
dae5df80c55a9015fc48f985bda3d416f7301d72a4348953", hex::encode(&ciphertext));
}
fn encrypt_ctr(key: &[u8; 16], iv: &[u8; 16], plaintext: &[u8]) -> Vec<u8> {
let mut aes128 = Aes128::new_from_slice(key).unwrap();
let plaintext_len = plaintext.len();
let blocks_count = (plaintext_len / 16) + if plaintext_len % 16 == 0 { 0 } else { 1 };
let iv_u128 = u128::from_be_bytes(iv.clone());
let mut cipher_text = vec![0_u8; plaintext_len];
for i in 0..blocks_count {
let enc_iv_u128 = iv_u128 + i as u128;
let mut block: Block<Aes128> = GenericArray::from(enc_iv_u128.to_be_bytes()).clone();
aes128.encrypt_block_mut(&mut block);
let block_slice = block.as_slice();
for j in 0..block_slice.len() {
let oi = i * 16 + j;
if oi < plaintext_len {
cipher_text[oi] = block_slice[j] ^ plaintext[oi];
}
}
}
cipher_text
}
#[test]
fn test_aes() {
let mut aes128 = Aes128::new_from_slice(
&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
).unwrap();
let mut a: Block<Aes128> = GenericArray::from_slice(&[0_u8; 16]).clone();
aes128.encrypt_block_mut(&mut a);
println!("{}", hex::encode(a.as_slice()));
assert_eq!("66e94bd4ef8a2c3b884cfa59ca342b2e", hex::encode(a.as_slice()));
}

107
__crypto/aes_gcm_crypto/Cargo.lock generated Normal file
View File

@@ -0,0 +1,107 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aes"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "433cfd6710c9986c576a25ca913c39d66a6474107b406f34f91d4a8923395241"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
]
[[package]]
name = "aes_gcm_crypto"
version = "0.1.0"
dependencies = [
"aes",
"hex",
"hex-literal",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cipher"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e"
dependencies = [
"crypto-common",
"inout",
]
[[package]]
name = "cpufeatures"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "generic-array"
version = "0.14.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hex-literal"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0"
[[package]]
name = "inout"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
dependencies = [
"generic-array",
]
[[package]]
name = "libc"
version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "typenum"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"

View File

@@ -0,0 +1,11 @@
[package]
name = "aes_gcm_crypto"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
aes = "0.8.2"
hex = "0.4.3"
hex-literal = "0.3.4"

View File

@@ -0,0 +1,162 @@
use aes::Aes256;
use aes::cipher::{BlockEncrypt, Key, KeyInit};
use aes::cipher::generic_array::GenericArray;
use hex_literal::hex;
pub struct GCM {
aes: Aes256,
}
// R = 11100001 || 0(120)
const R: u128 = 0b11100001 << 120;
fn gmul_128(x: u128, y: u128) -> u128 {
let mut z = 0u128;
let mut v = y;
for i in (0..128).rev() {
let xi = (x >> i) & 1;
if xi != 0 {
z ^= v;
}
v = match v & 1 == 0 {
true => { v >> 1 }
false => { (v >> 1) ^ R }
};
}
z
}
fn u8to128(bytes: &[u8]) -> u128 {
let result = bytes.iter().rev().enumerate().fold(0, |acc, (i, &byte)| {
acc | (byte as u128) << (i * 8)
});
result
}
fn msb_s(s: usize, bytes: &[u8]) -> Vec<u8> {
let mut result = vec![];
let n = s / 8;
let remain = s % 8;
for i in 0..n {
result.push(bytes[i]);
}
if remain > 0 {
result.push(bytes[n] >> (8 - remain));
}
result
}
// incs(X)=MSBlen(X)-s(X) || [int(LSBs(X))+1 mod 2^s]s
fn inc_32(bits: u128) -> u128 {
let msb = bits >> 32;
let mut lsb = (bits & 0xffffffff) as u32;
lsb = lsb.wrapping_add(1);
msb << 32 | lsb as u128
}
fn ghash(key: u128, messages: &[u128]) -> u128 {
let mut y = 0u128;
for i in 0..messages.len() {
let yi = gmul_128(y ^ messages[i], key);
y = yi;
}
y
}
impl GCM {
pub fn new(key: [u8; 32]) -> Self {
let key = Key::<Aes256>::from_slice(&key);
let aes = Aes256::new(&key);
Self {
aes,
}
}
fn encrypt_block(&mut self, block: &[u8; 16]) -> Vec<u8> {
let mut block = GenericArray::from(block.clone());
self.aes.encrypt_block(&mut block);
block.to_vec()
}
fn ghash_key(&mut self) -> u128 {
u8to128(&self.encrypt_block(&[0u8; 16]))
}
pub fn gctr(&mut self, iv: u128, message: &[u8]) -> Vec<u8> {
// 如果X是空串, 则直接返回
if message.len() == 0 {
return vec![];
}
let mut output = vec![];
let mut cb = iv;
for chunk in message.chunks(16) {
if chunk.len() < 16 {
let msb = msb_s(chunk.len() * 8, &self.encrypt_block(&cb.to_be_bytes()));
let y = u8to128(chunk) ^ u8to128(&msb);
output.extend_from_slice(&y.to_be_bytes()[16 - chunk.len()..16]);
} else {
let y = u8to128(chunk) ^ u8to128(&self.encrypt_block(&cb.to_be_bytes()));
output.extend_from_slice(&y.to_be_bytes());
}
// counter + 1
cb = inc_32(cb);
}
output
}
pub fn ae(&mut self, iv_bytes: &[u8], adata: &[u8], message: &[u8]) -> (Vec<u8>, Vec<u8>) {
let ghash_key = self.ghash_key();
let mut iv_padding = vec![];
let iv = u8to128(iv_bytes);
let j0 = match iv_bytes.len() == 12 {
true => {
iv << 32 | 0x00000001
}
false => {
// s = 128[len(iv) / 128] - len(iv)
let s = 128 * (((iv_bytes.len() * 8) + 128 - 1) / 128) - (iv_bytes.len() * 8);
iv_padding.push(iv << s);
iv_padding.push((iv_bytes.len() * 8) as u128);
ghash(ghash_key, &iv_padding)
}
};
let message_len = message.len() * 8;
let adata_len = adata.len() * 8;
let u = 128 * ((message_len + 128 - 1) / 128) - message_len;
let v = 128 * ((adata_len + 128 - 1) / 128) - adata_len;
// println!("u, v: {}, {}", u, v);
// println!("j0 = {:02x?}", j0);
let enc = self.gctr(inc_32(j0), &message);
let mut bit_string = Vec::<u8>::new();
bit_string.extend_from_slice(adata);
bit_string.extend_from_slice(&vec![0x00; v / 8]);
// 这里认证的是密文
bit_string.extend_from_slice(&enc);
bit_string.extend_from_slice(&vec![0x00; u / 8]);
bit_string.extend_from_slice(&(adata_len as u64).to_be_bytes());
bit_string.extend_from_slice(&(message_len as u64).to_be_bytes());
// println!("len = {}, bit_string[u8] = {:02x?}", bit_string.len(), bit_string);
let bit_string: Vec<u128> = bit_string.chunks(16).map(|it| u8to128(it)).collect();
// println!("bit_string[u128] = {:02x?}", bit_string);
let s = ghash(ghash_key, &bit_string).to_be_bytes();
// println!("{:02x?}", s);
let tag = self.gctr(j0, &s);
// println!("tag = {:02x?}", tag);
// println!("enc = {:02x?}", enc);
(tag, enc)
}
}
// https://developer.aliyun.com/article/952809
fn main() {
let key: [u8; 32] = hex!("0001020304050607080910111213141516171819202122232425262728293031");
let p: Vec<u8> = "Hello world!".as_bytes().to_vec();
let iv = hex!("000102030405060708091011");
let mut gcm = GCM::new(key);
// let h = gcm.ghash_key();
// assert_eq!(h, u8to128(&hex!("66e94bd4ef8a2c3b884cfa59ca342b2e")));
let (tag, enc) = gcm.ae(&iv, &[], &p);
println!("{}{}", hex::encode(&enc), hex::encode(tag));
println!("dce9511866417cff5123fa08c9e92cf156c5fc8bf6108ff28816fb58");
}

185
__crypto/asn1-der-test/Cargo.lock generated Normal file
View File

@@ -0,0 +1,185 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "asn1-der-test"
version = "0.1.0"
dependencies = [
"asn1-rs",
"base64",
"hex",
]
[[package]]
name = "asn1-rs"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ad1373757efa0f70ec53939aabc7152e1591cb485208052993070ac8d2429d"
dependencies = [
"asn1-rs-derive",
"asn1-rs-impl",
"displaydoc",
"nom",
"num-traits",
"rusticata-macros",
"thiserror",
]
[[package]]
name = "asn1-rs-derive"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7378575ff571966e99a744addeff0bff98b8ada0dedf1956d59e634db95eaac1"
dependencies = [
"proc-macro2",
"quote",
"syn",
"synstructure",
]
[[package]]
name = "asn1-rs-impl"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "autocfg"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80"
[[package]]
name = "base64"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51"
[[package]]
name = "displaydoc"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "memchr"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "num-traits"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
dependencies = [
"autocfg",
]
[[package]]
name = "proc-macro2"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rusticata-macros"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632"
dependencies = [
"nom",
]
[[package]]
name = "syn"
version = "2.0.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "synstructure"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "thiserror"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"

View File

@@ -0,0 +1,11 @@
[package]
name = "asn1-der-test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
asn1-rs = "0.6.1"
base64 = "0.22.0"
hex = "0.4.3"

View File

@@ -0,0 +1,91 @@
use std::str::FromStr;
use asn1_rs::{
BitString, Class, Error, Explicit, Integer,
OctetString, Oid, Sequence, TaggedValue, ToDer,
};
use base64::{Engine, engine::GeneralPurpose};
const BASE64: GeneralPurpose = base64::engine::general_purpose::STANDARD;
// -----BEGIN PRIVATE KEY-----
// MIG2AgEAMBAGByqGSM49AgEGBSuBBAAiBIGeMIGbAgEBBDB0n4af3g3zaB67WD+/
// Xe+FNOkwvuoDd/YUPh0y5ZfoBlkqG1WGNkZN2/d4EYqrNrahZANiAAR2vgKLjiAd
// I6l4EAyxGKwGBJ6pAdYZvNlBi8X9kKlCj6aYi5kSKqUfAMaQAX9+0WPoQ6Cy/gzi
// bPPmlPRMa4SdTKgZvvw5nuyNXZQU/wN69Opz/hCqxZHKYx5zSznj4/g=
// -----END PRIVATE KEY-----
// 0 182: SEQUENCE {
// 3 1: INTEGER 0
// 6 16: SEQUENCE {
// 8 7: OBJECT IDENTIFIER ecPublicKey (1 2 840 10045 2 1)
// 17 5: OBJECT IDENTIFIER secp384r1 (1 3 132 0 34)
// : }
// 24 158: OCTET STRING, encapsulates {
// 27 155: SEQUENCE {
// 30 1: INTEGER 1
// 33 48: OCTET STRING
// : 74 9F 86 9F DE 0D F3 68 1E BB 58 3F BF 5D EF 85
// : 34 E9 30 BE EA 03 77 F6 14 3E 1D 32 E5 97 E8 06
// : 59 2A 1B 55 86 36 46 4D DB F7 78 11 8A AB 36 B6
// 83 100: [1] {
// 85 98: BIT STRING
// : 04 76 BE 02 8B 8E 20 1D 23 A9 78 10 0C B1 18 AC
// : 06 04 9E A9 01 D6 19 BC D9 41 8B C5 FD 90 A9 42
// : 8F A6 98 8B 99 12 2A A5 1F 00 C6 90 01 7F 7E D1
// : 63 E8 43 A0 B2 FE 0C E2 6C F3 E6 94 F4 4C 6B 84
// : 9D 4C A8 19 BE FC 39 9E EC 8D 5D 94 14 FF 03 7A
// : F4 EA 73 FE 10 AA C5 91 CA 63 1E 73 4B 39 E3 E3
// : F8
// : }
// : }
// : }
// : }
const PRIVATE_KEY: &str = "749F869FDE0DF3681EBB583FBF5DEF8534E930BEEA0377F6143E1D32E597E806592A1B558636464DDBF778118AAB36B6";
const PUBLIC_KEY: &str = "0476BE028B8E201D23A978100CB118AC06049EA901D619BCD9418BC5FD90A9428FA6988B99122AA51F00C690017F7ED16\
3E843A0B2FE0CE26CF3E694F44C6B849D4CA819BEFC399EEC8D5D9414FF037AF4EA73FE10AAC591CA631E734B39E3E3F8";
fn main() {
let ec_public_key = Oid::from_str("1.2.840.10045.2.1").unwrap();
let secp_384_r1 = Oid::from_str("1.3.132.0.34").unwrap();
let private_key_oid_seq = {
let mut private_key_oid = Vec::new();
ec_public_key.write_der(&mut private_key_oid).unwrap();
secp_384_r1.write_der(&mut private_key_oid).unwrap();
Sequence::new(private_key_oid.into())
};
let private_body_seq = {
let private_key = hex::decode(PRIVATE_KEY).unwrap();
let public_key = hex::decode(PUBLIC_KEY).unwrap();
let integer_1 = Integer::from_i8(1);
let private_key_oct = OctetString::new(&private_key);
let mut private_body = Vec::new();
integer_1.write_der(&mut private_body).unwrap();
private_key_oct.write_der(&mut private_body).unwrap();
type TaggedValueContextSpecific<'a> = TaggedValue<BitString<'a>, Error, Explicit, { Class::CONTEXT_SPECIFIC }, 1>;
let public_key_bit = BitString::new(0, &public_key);
let public_key_tag = TaggedValueContextSpecific::explicit(public_key_bit);
public_key_tag.write_der(&mut private_body).unwrap();
Sequence::new(private_body.into())
};
let private_body = private_body_seq.to_der_vec().unwrap();
let private_body_oct = OctetString::new(&private_body);
let private_key_info_seq = {
let mut private_key_info = Vec::new();
let integer_0 = Integer::from_i8(0);
integer_0.write_der(&mut private_key_info).unwrap();
private_key_oid_seq.write_der(&mut private_key_info).unwrap();
private_body_oct.write_der(&mut private_key_info).unwrap();
Sequence::new(private_key_info.into())
};
println!("BASED64:\n{}", BASE64.encode(private_key_info_seq.to_der_vec().unwrap()));
println!("HEX:\n{}", hex::encode(private_key_info_seq.to_der_vec().unwrap()));
}

View File

@@ -0,0 +1,52 @@
use asn1_rs::{BitString, Class, Error, Explicit, Integer, OctetString, Oid, ParseResult, Sequence, TaggedValue};
use asn1_rs::FromDer;
use base64::Engine;
use base64::engine::GeneralPurpose;
const BASE64: GeneralPurpose = base64::engine::general_purpose::STANDARD;
fn main() {
let private_key = "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgakRmuDPA8pr1kqmY\
PxjoMJSJzMeWllw0qbKWzrbEfzehRANCAAQs2XCluo7NF7Y0tL6Pp2GWz2fw5llF\
dRvIpq0j8kVQjNOIYZqlBG6OOMQql3U95HsJJY0YzkoXEcdcJmoIV0zn";
let private_key_der = BASE64.decode(private_key).unwrap();
let r: ParseResult<()> = Sequence::from_der_and_then(&private_key_der, |i| {
let (i, i0) = Integer::from_der(i)?;
println!("INTEGER0: {}", i0.as_i8().unwrap());
let r: ParseResult<()> = Sequence::from_der_and_then(i, |i| {
let (i, oid1) = Oid::from_der(i)?;
let (i, oid2) = Oid::from_der(i)?;
println!("OID1: {}", oid1);
println!("OID2: {}", oid2);
Ok((i, ()))
});
let (i, _) = r.unwrap();
let (i, octet) = OctetString::from_der(i).unwrap();
let octet = octet.as_ref();
let r: ParseResult<()> = Sequence::from_der_and_then(octet, |i| {
let (i, i1) = Integer::from_der(i).unwrap();
println!("INTEGER1: {}", i1.as_i8().unwrap());
let (i, oct) = OctetString::from_der(i)?;
println!("PRIVATE KEY: {}", hex::encode(oct.as_ref()));
type TaggedValueContextSpecific<'a> = TaggedValue<BitString<'a>, Error, Explicit, { Class::CONTEXT_SPECIFIC }, 1>;
let tagged_value = TaggedValueContextSpecific::from_der(i);
let _ = tagged_value.map(|(_i, tagged_value)| {
println!("Tagged value [{}]", tagged_value.tag().0);
let tagged_value_inner = tagged_value.into_inner();
println!("Tagged value: {}, unused: {}", hex::encode(tagged_value_inner.as_ref()), tagged_value_inner.unused_bits);
});
Ok((i, ()))
});
r.unwrap();
Ok((i, ()))
});
r.unwrap();
}

284
__crypto/bc1-btc-address/Cargo.lock generated Normal file
View File

@@ -0,0 +1,284 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "arrayvec"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
[[package]]
name = "base58ck"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f"
dependencies = [
"bitcoin-internals",
"bitcoin_hashes",
]
[[package]]
name = "bc1-btc-address"
version = "0.1.0"
dependencies = [
"bitcoin",
"hex",
"rand",
]
[[package]]
name = "bech32"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"
[[package]]
name = "bitcoin"
version = "0.32.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad8929a18b8e33ea6b3c09297b687baaa71fb1b97353243a3f1029fad5c59c5b"
dependencies = [
"base58ck",
"bech32",
"bitcoin-internals",
"bitcoin-io",
"bitcoin-units",
"bitcoin_hashes",
"hex-conservative",
"hex_lit",
"secp256k1",
]
[[package]]
name = "bitcoin-internals"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2"
[[package]]
name = "bitcoin-io"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b47c4ab7a93edb0c7198c5535ed9b52b63095f4e9b45279c6736cec4b856baf"
[[package]]
name = "bitcoin-units"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2"
dependencies = [
"bitcoin-internals",
]
[[package]]
name = "bitcoin_hashes"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16"
dependencies = [
"bitcoin-io",
"hex-conservative",
]
[[package]]
name = "bitflags"
version = "2.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
[[package]]
name = "cc"
version = "1.2.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d487aa071b5f64da6f19a3e848e3578944b726ee5a4854b82172f02aa876bfdc"
dependencies = [
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
[[package]]
name = "getrandom"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasi",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hex-conservative"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd"
dependencies = [
"arrayvec",
]
[[package]]
name = "hex_lit"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd"
[[package]]
name = "libc"
version = "0.2.174"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "rand"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
dependencies = [
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
]
[[package]]
name = "secp256k1"
version = "0.29.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113"
dependencies = [
"bitcoin_hashes",
"secp256k1-sys",
]
[[package]]
name = "secp256k1-sys"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9"
dependencies = [
"cc",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "syn"
version = "2.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "wasi"
version = "0.14.2+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
dependencies = [
"wit-bindgen-rt",
]
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags",
]
[[package]]
name = "zerocopy"
version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
dependencies = [
"proc-macro2",
"quote",
"syn",
]

View File

@@ -0,0 +1,9 @@
[package]
name = "bc1-btc-address"
version = "0.1.0"
edition = "2024"
[dependencies]
bitcoin = "0.32.6"
hex = "0.4.3"
rand = "0.9.1"

View File

@@ -0,0 +1,29 @@
use bitcoin::key::Secp256k1;
use bitcoin::{Address, CompressedPublicKey, Network, PrivateKey};
use rand::RngCore;
// generate btc address:
// https://coinb.in/#newSegWit
fn main() {
let secp = Secp256k1::new();
let mut sk_bytes = [0u8; 32];
rand::rng().fill_bytes(&mut sk_bytes);
let secret_key = PrivateKey::from_slice(&sk_bytes, Network::Bitcoin).unwrap();
// let secret_key = PrivateKey::from_wif("L2HajtedHgDT16o3Er8L8tyRrPNbXkeBK69vhGi7K9eK4Yg3dJuj").unwrap();
let public_key = secret_key.public_key(&secp);
let compress_public_key = CompressedPublicKey::try_from(public_key).unwrap();
// 构造 P2WPKH 地址 (bc1 开头)
let address = Address::p2wpkh(&compress_public_key, Network::Bitcoin);
let address = address.to_string();
println!("Private Key (WIF): {}", secret_key.to_wif());
println!("Public Key: {}", public_key);
println!(
"Public Key: {}",
hex::encode(&public_key.inner.serialize_uncompressed())
);
println!("SegWit Address (bc1): {}", address);
}

333
__crypto/btc-address/Cargo.lock generated Normal file
View File

@@ -0,0 +1,333 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "autocfg"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "block-buffer"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
dependencies = [
"block-padding",
"byte-tools",
"byteorder",
"generic-array",
]
[[package]]
name = "block-padding"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
dependencies = [
"byte-tools",
]
[[package]]
name = "bs58"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb"
[[package]]
name = "btc-address"
version = "0.1.0"
dependencies = [
"bs58",
"digest",
"hex",
"num_cpus",
"rand",
"ripemd160",
"secp256k1",
"sha2",
]
[[package]]
name = "byte-tools"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cc"
version = "1.0.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dae9c4b8fedcae85592ba623c4fd08cfdab3e3b72d6df780c6ead964a69bfff"
[[package]]
name = "cloudabi"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
dependencies = [
"bitflags",
]
[[package]]
name = "digest"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
dependencies = [
"generic-array",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]]
name = "generic-array"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
dependencies = [
"typenum",
]
[[package]]
name = "hermit-abi"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9"
dependencies = [
"libc",
]
[[package]]
name = "hex"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
[[package]]
name = "libc"
version = "0.2.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f96b10ec2560088a8e76961b00d47107b3a625fecb76dedb29ee7ccbf98235"
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "opaque-debug"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "rand"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
dependencies = [
"autocfg",
"libc",
"rand_chacha",
"rand_core 0.4.2",
"rand_hc",
"rand_isaac",
"rand_jitter",
"rand_os",
"rand_pcg",
"rand_xorshift",
"winapi",
]
[[package]]
name = "rand_chacha"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
dependencies = [
"autocfg",
"rand_core 0.3.1",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rand_hc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "rand_isaac"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "rand_jitter"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b"
dependencies = [
"libc",
"rand_core 0.4.2",
"winapi",
]
[[package]]
name = "rand_os"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071"
dependencies = [
"cloudabi",
"fuchsia-cprng",
"libc",
"rand_core 0.4.2",
"rdrand",
"winapi",
]
[[package]]
name = "rand_pcg"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44"
dependencies = [
"autocfg",
"rand_core 0.4.2",
]
[[package]]
name = "rand_xorshift"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]]
name = "ripemd160"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad5112e0dbbb87577bfbc56c42450235e3012ce336e29c5befd7807bd626da4a"
dependencies = [
"block-buffer",
"digest",
"opaque-debug",
]
[[package]]
name = "secp256k1"
version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2932dc07acd2066ff2e3921a4419606b220ba6cd03a9935123856cc534877056"
dependencies = [
"rand",
"secp256k1-sys",
]
[[package]]
name = "secp256k1-sys"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ab2c26f0d3552a0f12e639ae8a64afc2e3db9c52fe32f5fc6c289d38519f220"
dependencies = [
"cc",
]
[[package]]
name = "sha2"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69"
dependencies = [
"block-buffer",
"digest",
"fake-simd",
"opaque-debug",
]
[[package]]
name = "typenum"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View File

@@ -0,0 +1,20 @@
[package]
name = "btc-address"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
hex = "0.4"
bs58 = "0.3.0"
secp256k1 = { version = "0.17.2", features = ["rand"] }
rand = "0.6"
# elliptic-curve = "0.3.0"
# k256 = "0.1.0"
digest = "0.8.1"
ripemd160 = "0.8.0"
sha2 = "0.8.1"
num_cpus = "1.13.0"

View File

@@ -0,0 +1,116 @@
use std::{sync::{Arc, Mutex}, thread};
use digest::{FixedOutput, Input};
use rand::rngs::OsRng;
use ripemd160::Ripemd160;
use secp256k1::{key::PublicKey, Secp256k1};
use sha2::Sha256;
fn main() {
let args = std::env::args();
if args.len() <= 1 {
println!("[ERROR] Need at least one argument, e.g. 1Hatter 1UTF8 ...");
return;
}
let continue_on_found = std::env::var("CONTINUE_ON_FOUND")
.map(|c| c.to_lowercase())
.map(|c| c == "1" || c == "true" || c == "yes" || c == "on")
.unwrap_or_else(|_| false);
let prefixes: Vec<String> = args.skip(1).collect();
println!("Prefixes: {:?}", prefixes);
if continue_on_found {
println!("CONTINUE_ON_FOUND is ON");
} else {
println!("CONTINUE_ON_FOUND is OFF");
}
let loop_count = std::env::var("LOOP_COUNT")
.map(|c| c.parse::<u64>())
.unwrap_or_else(|_| Ok(10_000_000_u64))
.unwrap_or_else(|_| 10_000_000_u64);
println!("LOOP_COUNT={}", loop_count);
let num_of_vcpus = num_cpus::get();
let num_of_phycpus = num_cpus::get_physical();
println!("You have {} vCPUs, from {} phyCPUs", num_of_vcpus, num_of_phycpus);
let concurrent_count = std::env::var("CONCURRENT_COUNT")
.map(|c| c.parse::<u64>())
.unwrap_or_else(|_| Ok(num_of_phycpus as u64))
.unwrap_or_else(|_| 1_u64);
println!("CONCURRENT_COUNT={}", concurrent_count);
let stop_flag = Arc::new(Mutex::new(false));
let mut handles = vec![];
for ind in 0..concurrent_count {
println!("- Running task {} of {}", ind, concurrent_count);
let the_stop_flag = Arc::clone(&stop_flag);
let prefixes = prefixes.clone();
let child = thread::spawn(move || {
run_one_task(prefixes, continue_on_found, loop_count, ind, the_stop_flag);
});
handles.push(child);
}
while let Some(h) = handles.pop() {
h.join().unwrap();
}
println!("Finished!");
}
fn run_one_task(prefixes: Vec<String>, continue_on_found: bool, loop_count: u64, ind: u64, the_stop_flag: Arc<Mutex<bool>>) {
let secp = Secp256k1::new();
let mut rng = OsRng::new().expect("OsRng");
for i in 0..loop_count {
let (secret_key, public_key) = secp.generate_keypair(&mut rng);
let s = make_btc_address(&public_key);
if i % 1_000 == 0 {
if *the_stop_flag.lock().unwrap() {
return;
}
if i > 0 && i % 100_000 == 0 {
println!("> {} - {}", ind, i);
}
}
if prefixes.iter().any(|p| s.starts_with(p)) {
println!(">> {}\n{}", s, secret_key);
if !continue_on_found {
*the_stop_flag.lock().unwrap() = true;
break;
}
}
}
}
fn make_btc_address(public_key: &PublicKey) -> String {
let public_key_bytes = public_key.serialize_uncompressed().to_vec();
let riphemd160_sha256_pub_key = calc_ripemd160(&calc_sha256(&public_key_bytes));
let mut btc_addr = Vec::<u8>::with_capacity(25);
btc_addr.push(0x00 as u8);
btc_addr.extend_from_slice(&riphemd160_sha256_pub_key);
let checksum = &calc_sha256(&calc_sha256(&btc_addr))[0..4];
btc_addr.extend_from_slice(checksum);
bs58::encode(&btc_addr).into_string()
}
#[inline]
fn calc_sha256(i: &[u8]) -> Vec<u8> {
calc_hash(Sha256::default(), i)
}
#[inline]
fn calc_ripemd160(i: &[u8]) -> Vec<u8> {
calc_hash(Ripemd160::default(), i)
}
#[inline]
fn calc_hash<T>(mut hasher: T, i: &[u8]) -> Vec<u8> where T: Input + FixedOutput {
hasher.input(&i);
hasher.fixed_result().to_vec()
}

215
__crypto/crypto/Cargo.lock generated Normal file
View File

@@ -0,0 +1,215 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "block-buffer"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
dependencies = [
"block-padding",
"byte-tools",
"byteorder",
"generic-array",
]
[[package]]
name = "block-padding"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
dependencies = [
"byte-tools",
]
[[package]]
name = "byte-tools"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "crypto"
version = "0.1.0"
dependencies = [
"digest",
"ecdsa",
"ed25519",
"elliptic-curve",
"k256",
"p256",
"p384",
"p521",
"sha2",
]
[[package]]
name = "digest"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
dependencies = [
"generic-array",
]
[[package]]
name = "ecdsa"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a7aaf89875554fab12c9d0855d694803a8820b73bfb89cdc96546b6bcab69e4"
dependencies = [
"elliptic-curve",
"generic-array",
"sha2",
"signature",
]
[[package]]
name = "ed25519"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf038a7b6fd7ef78ad3348b63f3a17550877b0e28f8d68bcc94894d1412158bc"
dependencies = [
"signature",
]
[[package]]
name = "elliptic-curve"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01f69be7d1feb7a7a04f158aaf32c7deaa7604e9bd58145525e536438c4e5096"
dependencies = [
"generic-array",
"getrandom",
"subtle",
"zeroize",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "generic-array"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
dependencies = [
"typenum",
]
[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "k256"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8a010224d825405c12a840fc269094683abe1282222f46c368318a02fa8876b"
dependencies = [
"elliptic-curve",
"subtle",
]
[[package]]
name = "libc"
version = "0.2.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
[[package]]
name = "opaque-debug"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "p256"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86640e33ca638ec215c74de317696bbca5daa7d52cf55b905bd20a6bd2cfd133"
dependencies = [
"elliptic-curve",
"subtle",
]
[[package]]
name = "p384"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3aee0d9bdeedaea6cdd47f9281a9f8e1037d3037088b70e2af13c64ce65608ec"
dependencies = [
"elliptic-curve",
]
[[package]]
name = "p521"
version = "0.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be25ade38ee14ce95ca4cc94ae139eef99c819419e05296f62d5ef09f67c668b"
[[package]]
name = "sha2"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0"
dependencies = [
"block-buffer",
"digest",
"fake-simd",
"opaque-debug",
]
[[package]]
name = "signature"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "685e1c5b65c6cc6fd0eb9ba63c6cfb8431f7f9c7e078c626f23f50e13fa378d7"
dependencies = [
"digest",
]
[[package]]
name = "subtle"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c65d530b10ccaeac294f349038a597e435b18fb456aadd0840a623f83b9e941"
[[package]]
name = "typenum"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "zeroize"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8"

View File

@@ -0,0 +1,19 @@
[package]
name = "crypto"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ecdsa = "0.5.0"
ed25519 = "1.0.1"
digest = "0.8.1"
elliptic-curve = "0.3.0"
k256 = "0.2.0"
p256 = "0.2.0"
p384 = "0.1.0"
p521 = "0.0.0"
sha2 = "0.8.1"

View File

@@ -0,0 +1,31 @@
use sha2::{Sha256, Sha512, Digest};
fn main() {
println!("{}", to_hex(&sha256(b"hello world")));
println!("{}", to_hex(&sha512(b"hello world")));
}
fn sha256(data: &[u8]) -> Vec<u8> {
let mut hasher = Sha256::new();
hasher.input(data);
let result = hasher.result();
result[..].to_vec()
}
fn sha512(data: &[u8]) -> Vec<u8> {
let mut hasher = Sha512::new();
hasher.input(data);
let result = hasher.result();
result[..].to_vec()
}
fn to_hex(bs: &[u8]) -> String {
bs.iter().map(|u| {
let x = format!("{:x}", u);
if x.len() == 1 {
"0".to_owned() + &x
} else {
x
}
}).collect()
}

31
__crypto/crypto2-demo/Cargo.lock generated Normal file
View File

@@ -0,0 +1,31 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "crypto2"
version = "0.2.0"
source = "git+https://github.com/shadowsocks/crypto2#dbfd3bb4751abd9945370dee25350765039d050a"
dependencies = [
"cfg-if",
]
[[package]]
name = "crypto2-demo"
version = "0.1.0"
dependencies = [
"crypto2",
"hex",
]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"

Some files were not shown because too many files have changed in this diff Show More