Compare commits
472 Commits
8e5596472d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
b73fd9e64e
|
|||
|
5ef3b4d3e6
|
|||
|
3dda4e8e5b
|
|||
|
a1024943ff
|
|||
|
9eba818de9
|
|||
|
814b5e9442
|
|||
|
6d7273c6a3
|
|||
|
bd9ea78e53
|
|||
|
73d58350c2
|
|||
|
e45d14498c
|
|||
|
f2fd57c342
|
|||
|
ed54a7e6ef
|
|||
|
7c0865fafd
|
|||
|
|
6e681f0ba1
|
||
|
|
0dcbb75879 | ||
|
|
ad25ed2453 | ||
|
|
0491407e58 | ||
|
564977aad7
|
|||
|
c966ad621d
|
|||
|
|
9982409535 | ||
|
|
9e8cbf557d | ||
|
ada9691adc
|
|||
|
48ad5122f2
|
|||
|
10672a86b1
|
|||
|
744b16af6c
|
|||
|
2ff99a832d
|
|||
|
4f048b3981
|
|||
|
49d91c0dc1
|
|||
|
9d9575843c
|
|||
|
1eb7aeab42
|
|||
|
cc4c793835
|
|||
|
1b59475ab9
|
|||
|
0f85300a74
|
|||
|
e4f4e70951
|
|||
|
ae8747de70
|
|||
|
2a9d6dfaac
|
|||
|
9b2c40d662
|
|||
|
04a58e9f66
|
|||
|
1ae6bb6737
|
|||
|
8717ca7594
|
|||
|
09129b38a1
|
|||
|
7f0e18bbe4
|
|||
|
22344b6d96
|
|||
|
f107f82b7c
|
|||
|
50fa9b5179
|
|||
|
46bbd4859e
|
|||
|
e5a56888ad
|
|||
|
6b752c4a77
|
|||
|
18e7545bcf
|
|||
|
37f94aad3f
|
|||
|
f5a41fdb02
|
|||
|
8adc5a58bc
|
|||
|
31ba44c45e
|
|||
|
a3c45895e1
|
|||
|
051eb5fecc
|
|||
|
930c35abff
|
|||
|
e5748b1e41
|
|||
|
bb36536347
|
|||
|
0d1e08fcd1
|
|||
|
47830618e4
|
|||
|
fe5c16450c
|
|||
|
97baed2e2a
|
|||
|
7ec4c4a526
|
|||
|
526dd4172b
|
|||
|
11278926bf
|
|||
|
d41b499913
|
|||
|
55e5b732f6
|
|||
|
05afe67de7
|
|||
|
a32ef922c7
|
|||
|
11aaa45456
|
|||
|
e8b5167490
|
|||
|
607b78b6b8
|
|||
|
49c352e84c
|
|||
|
a26e3e1ffe
|
|||
|
27ee89dd8a
|
|||
|
45eb023741
|
|||
|
a321aae4d2
|
|||
|
12a91e6103
|
|||
|
8904df2753
|
|||
|
49fefb745c
|
|||
|
38b8fbe37f
|
|||
|
8aba71a72b
|
|||
|
c259d6c102
|
|||
|
2b71b456a3
|
|||
|
04914f33ab
|
|||
|
4fb7c049b5
|
|||
|
00bedd5ce1
|
|||
|
1defe5958f
|
|||
|
e7f03687dc
|
|||
|
f7b23d0943
|
|||
|
12e24652b7
|
|||
|
591154f331
|
|||
|
390a142561
|
|||
|
0f94dae70a
|
|||
|
8e03973dda
|
|||
|
9e06880a81
|
|||
|
9ec922f965
|
|||
|
651c96d658
|
|||
|
88c931bc5c
|
|||
|
c95a566c58
|
|||
|
8803a8500a
|
|||
|
d1b1132cc3
|
|||
|
2e256c32f8
|
|||
|
f73e6ce7f8
|
|||
|
ead7eddf1f
|
|||
|
e44aa7f60c
|
|||
|
137e04eda0
|
|||
|
6e4277a53b
|
|||
|
c173ce8dba
|
|||
|
33cd9b007c
|
|||
|
e6b985a695
|
|||
|
3eefa3cba1
|
|||
|
d514f80f64
|
|||
|
8862192778
|
|||
|
1bc45c72b1
|
|||
|
14d22ef4ef
|
|||
|
3a98d7da3f
|
|||
|
570b578596
|
|||
|
8f6805f3e3
|
|||
|
c8837b21f6
|
|||
|
93a8832b36
|
|||
|
aa50d63aec
|
|||
|
01e8f5a959
|
|||
|
ea815f1c0d
|
|||
|
34c04da05d
|
|||
|
a0359637e2
|
|||
|
2a3d63d1e8
|
|||
|
448f7e42ac
|
|||
|
060c6b2263
|
|||
|
b98542fff3
|
|||
|
1098220058
|
|||
|
78561aec5b
|
|||
|
78db54db6c
|
|||
|
4efe9d4a12
|
|||
|
820417832b
|
|||
|
8979029e29
|
|||
|
3a4d6b2d62
|
|||
|
acb1878e8d
|
|||
|
c18b025ac4
|
|||
|
cb12afd2da
|
|||
|
6873d68129
|
|||
|
a49d639b18
|
|||
|
9ab7685f2d
|
|||
|
e972998e09
|
|||
|
2f4df9395d
|
|||
|
2bb467898e
|
|||
|
fe3f2af4e9
|
|||
|
5337f7f61d
|
|||
|
20cd2d6877
|
|||
|
50a4d71ad8
|
|||
|
dc213c4055
|
|||
|
36e1609002
|
|||
|
338d2720ac
|
|||
|
bce6338c2b
|
|||
|
4c5d44d553
|
|||
|
0b0d4f2f9c
|
|||
|
5d1372905f
|
|||
|
60eb54ca49
|
|||
|
8e29384cb2
|
|||
|
6833f7b86a
|
|||
|
acf61e1520
|
|||
|
3e755b465c
|
|||
|
1eb9b95070
|
|||
|
4b32063d93
|
|||
|
e4af4e6e25
|
|||
|
debc750e2f
|
|||
|
842c5b4579
|
|||
|
b908736c1c
|
|||
|
46b730e235
|
|||
|
c40ac23cf5
|
|||
|
1c9669a4a7
|
|||
|
f0c3aa9df5
|
|||
|
4b4eacf3f4
|
|||
|
7d769d3a0f
|
|||
|
a116b1c2e6
|
|||
|
0415152500
|
|||
|
d90b1e69ea
|
|||
|
ca32d8701c
|
|||
|
b80d8b1859
|
|||
|
05ebf862fd
|
|||
|
1de8f9499a
|
|||
|
9f61cc748a
|
|||
|
30ac42001b
|
|||
|
0741768d29
|
|||
|
15bd8076b1
|
|||
|
cbc05226e0
|
|||
|
4e88c90fd4
|
|||
|
2d6b1e3a1b
|
|||
|
6890520435
|
|||
|
74a202f1ed
|
|||
|
4ba63b4c2e
|
|||
|
b0e1a89020
|
|||
|
dd45671b35
|
|||
|
51685c6284
|
|||
|
4d45c2dbcf
|
|||
|
fdee5bef03
|
|||
|
2a6b904c2a
|
|||
|
6160185ace
|
|||
|
a8a284163d
|
|||
|
d17c718ee8
|
|||
|
e2d6b9c54f
|
|||
|
09c20602e9
|
|||
|
206470cdb3
|
|||
|
89ce27b02f
|
|||
|
46783e8398
|
|||
|
e0b2b59858
|
|||
|
4359817513
|
|||
|
713e1424f9
|
|||
|
f90941f497
|
|||
|
22e77db82c
|
|||
|
af706d9abb
|
|||
|
9ceaf9a789
|
|||
|
fc23a5959b
|
|||
|
8ae8a57671
|
|||
|
d74850d236
|
|||
|
d181d970de
|
|||
|
fbfe58c0e7
|
|||
|
cf46e8f119
|
|||
|
44759d1a67
|
|||
|
0488154e6f
|
|||
|
2330a646b7
|
|||
|
6a8d8ca043
|
|||
|
fe46aef388
|
|||
|
7034c0b86c
|
|||
|
92bfe1819a
|
|||
|
6517457d0d
|
|||
|
fc2a5217b3
|
|||
|
5538db42d9
|
|||
|
791c18ea77
|
|||
|
fe2f615943
|
|||
|
72a8969453
|
|||
|
46d24a8e24
|
|||
|
2b3e2a7c87
|
|||
|
f104c9dec9
|
|||
|
8fa4284e6c
|
|||
|
3f38ba99f7
|
|||
|
18b7b4707a
|
|||
|
3684ae79da
|
|||
|
779ecc08f2
|
|||
|
0b0c1e4f11
|
|||
|
cbb8f43ad3
|
|||
|
7007a77334
|
|||
|
effb8587b1
|
|||
|
87f21a0b93
|
|||
|
e0b7a148ba
|
|||
|
db42a77035
|
|||
|
43bd89f477
|
|||
|
f1fcb8d6f4
|
|||
|
03c3e1dab5
|
|||
|
0534c43968
|
|||
|
3486a5aae2
|
|||
|
aca23fa6fd
|
|||
|
315ccf100e
|
|||
|
8339336888
|
|||
|
4a873ab1f6
|
|||
|
c20df9c739
|
|||
|
f967a24351
|
|||
|
259115dea4
|
|||
| f97124884b | |||
| 7331163c2b | |||
| 85714fd86d | |||
| 0328bc17d6 | |||
| 084166e0bd | |||
| 355fcc1b9d | |||
| 134c0dc166 | |||
| 1addcd26ea | |||
| ba796dd652 | |||
| 813a7d5b2f | |||
| 2b82801053 | |||
| 19a03e85d5 | |||
| 4bbb7b9578 | |||
| 5f880886ba | |||
| 1c58c1cfd2 | |||
| d09b72468e | |||
| 87327c8b11 | |||
| 1d02fda724 | |||
| ca1fe72030 | |||
| f8c96be6a9 | |||
| 8b2c84b8bc | |||
| 521fc4f369 | |||
| 6bc61da148 | |||
| 2dd0c00c03 | |||
| a2afc118e2 | |||
| 29618a99ec | |||
| dceda46ae8 | |||
| 67f62ee869 | |||
| b4f8d33e64 | |||
| dd05e11b30 | |||
| e55f773860 | |||
| d7967ce520 | |||
| 38439e4204 | |||
| ed41681faf | |||
| 4c5ee6f908 | |||
| fb84b0f85e | |||
| d383b36f00 | |||
| bf7b9275c1 | |||
| 03c5919538 | |||
| 6f36859a4e | |||
| b131013b3e | |||
| 452b41d51a | |||
| 6769322905 | |||
| a8c9c92f75 | |||
| 980d52ad07 | |||
| c6e36fb414 | |||
| db388a6e37 | |||
| db6bcfa7b9 | |||
| 6a2001a0db | |||
| a52e5192f0 | |||
| 9c33fca074 | |||
| e73575f62e | |||
| 58ea520a63 | |||
| 9dc7182b86 | |||
| 505f44df42 | |||
| bbc0adf1fa | |||
| 316ba7b338 | |||
| dee3033007 | |||
| 394e76ba29 | |||
| 740d5baf65 | |||
| 8b70dfa145 | |||
| 42a261af55 | |||
| 257906518e | |||
| d7488c82d7 | |||
| 695561da70 | |||
| eb1be1caf2 | |||
| 0094ce2e5c | |||
| 2a2d33be2c | |||
| bfe461a2b7 | |||
| 0941f9e340 | |||
| de0184e253 | |||
| ba35489cdf | |||
| 602e14071b | |||
| 24150ca0f1 | |||
| 601f11efe6 | |||
| 6fef958a70 | |||
| 54856504a2 | |||
| 6386371a69 | |||
| c49f432208 | |||
| 95917efa2d | |||
| ffaba9fe48 | |||
| f0958ac291 | |||
| 784be79abf | |||
| cc10c8effd | |||
| 8d34b85a9c | |||
| cd4a02f513 | |||
| ec29c2368c | |||
| 9a0434868b | |||
| 895385a2b5 | |||
| 88c4ba5c94 | |||
| e3ac142ead | |||
| 6843d69daf | |||
| 64ea4ba82e | |||
| 6a6cfae137 | |||
| 14a473103a | |||
| 8b5e9e54c1 | |||
| 0e9b83fad1 | |||
| 9884ea62f3 | |||
| 907c894dbc | |||
| 5157903b3a | |||
| 4948dc547e | |||
| d1db369f44 | |||
| a5571a138b | |||
| 41447e002e | |||
| 1f47486d52 | |||
| 6220da35a0 | |||
| 113911b6ac | |||
| 9eecc77ac0 | |||
| d510963203 | |||
| 456a036b23 | |||
| 9688a0ccef | |||
| 30dc4a1416 | |||
| 6488b111d7 | |||
| 220a582122 | |||
| f017ee9dc1 | |||
| 86557359a5 | |||
| 895b7e03c8 | |||
| 22ee698955 | |||
| afb948c48c | |||
| c03b7d75a3 | |||
| 6f8c83fe26 | |||
| 1b3cb499b4 | |||
| b02111ecd5 | |||
| dd53462cfb | |||
| 7650b3c939 | |||
| 228e006fb5 | |||
| cad9dfe606 | |||
| 8bc89e80bb | |||
| 939861e987 | |||
| 6f7b3ecce8 | |||
| 297dca28f3 | |||
| 76beb992a3 | |||
| 3321c4720d | |||
| c51d2bb576 | |||
| 56b44d1a8f | |||
| 5110732561 | |||
| 7e8d1e7884 | |||
| b09f526c10 | |||
| 79efa59a34 | |||
| e6917877cc | |||
| 1bd0f3e5c9 | |||
| 24c7f80367 | |||
| afcbb3a8a2 | |||
| 73eddfbd5b | |||
| 82bb330b3c | |||
| e126c953a0 | |||
| 47eb944308 | |||
| 743c38725f | |||
| 47f94a6544 | |||
| 691f77cf47 | |||
| 0c312ef7f7 | |||
| 9c8c467fea | |||
| 5c9a439fe1 | |||
| dfcdd02d27 | |||
| 990f2dac41 | |||
| e447b4e96d | |||
| 93ff5a519e | |||
| 6e8bb9e33f | |||
| a9df08bc6d | |||
| 754ff1ed60 | |||
| 084a74f9c7 | |||
| 1eb86656bf | |||
| 269d087daa | |||
| 9430fd5b1a | |||
| f1d3ca5969 | |||
| 07c2855586 | |||
| 004599c8e4 | |||
| bf1a0343cc | |||
| 0e7cc78585 | |||
| 974545fc7c | |||
| 5e48a69aa0 | |||
| 347ea202e1 | |||
| af97622c79 | |||
| 899428370b | |||
| d88ab2580a | |||
| 9b6fb8b292 | |||
| bb6762ab81 | |||
| a034988643 | |||
| 9d4d830115 | |||
| fc670d54b1 | |||
| dbb00a88b0 | |||
| 6d3713f35e | |||
| b685938431 | |||
| 3ab0c24cf6 | |||
| d169e5a9fc | |||
| 1f6df84c2a | |||
| d5414661fc | |||
| e987a9de3b | |||
| 072dd9f9a4 | |||
| 70459e0c90 | |||
| ce1b7dd4fb | |||
| 9f605830d2 | |||
| 8f8bc6eca9 | |||
| 820a5707fa | |||
| 443ab2c47f | |||
| 37c0a30a99 | |||
| 81a0145be4 | |||
| ccc820145e | |||
| d55b768421 | |||
| 52ef0eaae1 | |||
| 9eaaa185ca | |||
| e8dc9a49fb | |||
| cebee53c4b | |||
| 3a9904d555 | |||
| 42cab3e274 | |||
| 5ece072af9 | |||
| 6e7909f04d | |||
| b92afd290f | |||
| 2a40ee13ac | |||
| b8cfa97481 | |||
| a4ec0c9d53 | |||
| 399ba16771 | |||
| 7cdb6c25e5 | |||
| be2b083c02 |
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,10 +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
|
99.htm
|
||||||
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
|
||||||
|
|||||||
318
README.md
318
README.md
@@ -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
9
README_2.md
Normal 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
9
README_template.md
Normal 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
16
__alloc/zeroizing-alloc-demo/Cargo.lock
generated
Normal 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",
|
||||||
|
]
|
||||||
7
__alloc/zeroizing-alloc-demo/Cargo.toml
Normal file
7
__alloc/zeroizing-alloc-demo/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "zeroizing-alloc-demo"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
zeroizing-alloc = "0.1.0"
|
||||||
8
__alloc/zeroizing-alloc-demo/src/main.rs
Normal file
8
__alloc/zeroizing-alloc-demo/src/main.rs
Normal 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
103
__args/argh-test/Cargo.lock
generated
Normal 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"
|
||||||
7
__args/argh-test/Cargo.toml
Normal file
7
__args/argh-test/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "argh-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
argh = "0.1.13"
|
||||||
22
__args/argh-test/src/main.rs
Normal file
22
__args/argh-test/src/main.rs
Normal 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
261
__args/clap-test-2/Cargo.lock
generated
Normal 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"
|
||||||
8
__args/clap-test-2/Cargo.toml
Normal file
8
__args/clap-test-2/Cargo.toml
Normal 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"
|
||||||
158
__args/clap-test-2/src/main.rs
Normal file
158
__args/clap-test-2/src/main.rs
Normal 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
237
__args/clap-test/Cargo.lock
generated
Normal 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"
|
||||||
7
__args/clap-test/Cargo.toml
Normal file
7
__args/clap-test/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "clap-test"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { version = "4.5.23", features = ["derive"] }
|
||||||
165
__args/clap-test/src/main.rs
Normal file
165
__args/clap-test/src/main.rs
Normal 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
232
__bin/goblin/Cargo.lock
generated
Normal 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
12
__bin/goblin/Cargo.toml
Normal 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
32
__bin/goblin/src/main.rs
Normal 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
82
__bin/object-demo/Cargo.lock
generated
Normal 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",
|
||||||
|
]
|
||||||
10
__bin/object-demo/Cargo.toml
Normal file
10
__bin/object-demo/Cargo.toml
Normal 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"
|
||||||
323
__bin/object-demo/src/main.rs
Normal file
323
__bin/object-demo/src/main.rs
Normal 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
70
__compress/zstd-demo/Cargo.lock
generated
Normal 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",
|
||||||
|
]
|
||||||
9
__compress/zstd-demo/Cargo.toml
Normal file
9
__compress/zstd-demo/Cargo.toml
Normal 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"
|
||||||
29
__compress/zstd-demo/src/main.rs
Normal file
29
__compress/zstd-demo/src/main.rs
Normal 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
21
__concurrent/arc-swap/Cargo.lock
generated
Normal 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"
|
||||||
13
__concurrent/arc-swap/Cargo.toml
Normal file
13
__concurrent/arc-swap/Cargo.toml
Normal 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"
|
||||||
|
|
||||||
|
|
||||||
11
__concurrent/arc-swap/src/main.rs
Normal file
11
__concurrent/arc-swap/src/main.rs
Normal 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);
|
||||||
|
}
|
||||||
421
__concurrent/async-fn-resumed-after-completion/Cargo.lock
generated
Normal file
421
__concurrent/async-fn-resumed-after-completion/Cargo.lock
generated
Normal 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"
|
||||||
@@ -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"] }
|
||||||
48
__concurrent/async-fn-resumed-after-completion/src/main.rs
Normal file
48
__concurrent/async-fn-resumed-after-completion/src/main.rs
Normal 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
438
__concurrent/async_study/Cargo.lock
generated
Normal 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"
|
||||||
14
__concurrent/async_study/Cargo.toml
Normal file
14
__concurrent/async_study/Cargo.toml
Normal 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"
|
||||||
22
__concurrent/async_study/README.md
Normal file
22
__concurrent/async_study/README.md
Normal 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
|
||||||
|
|
||||||
8
__concurrent/async_study/examples/async.rs
Normal file
8
__concurrent/async_study/examples/async.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
invoke().await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn invoke() {
|
||||||
|
println!("Hello World!");
|
||||||
|
}
|
||||||
23
__concurrent/async_study/examples/async2.rs
Normal file
23
__concurrent/async_study/examples/async2.rs
Normal 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 {}
|
||||||
|
}
|
||||||
35
__concurrent/async_study/examples/async3.rs
Normal file
35
__concurrent/async_study/examples/async3.rs
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
||||||
10
__concurrent/async_study/examples/async4.rs
Normal file
10
__concurrent/async_study/examples/async4.rs
Normal 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!");
|
||||||
|
}
|
||||||
72
__concurrent/async_study/examples/mini_tokio.rs
Normal file
72
__concurrent/async_study/examples/mini_tokio.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
__concurrent/async_study/examples/select.rs
Normal file
24
__concurrent/async_study/examples/select.rs
Normal 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");
|
||||||
|
}
|
||||||
44
__concurrent/async_study/examples/select2.rs
Normal file
44
__concurrent/async_study/examples/select2.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
40
__concurrent/async_study/examples/select3.rs
Normal file
40
__concurrent/async_study/examples/select3.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
98
__concurrent/async_study/examples/stream.rs
Normal file
98
__concurrent/async_study/examples/stream.rs
Normal 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()))),
|
||||||
|
}
|
||||||
|
}
|
||||||
10
__concurrent/async_study/examples/tokio_stream.rs
Normal file
10
__concurrent/async_study/examples/tokio_stream.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
__concurrent/async_study/examples/tokio_stream2.rs
Normal file
29
__concurrent/async_study/examples/tokio_stream2.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
190
__concurrent/async_study/src/main.rs
Normal file
190
__concurrent/async_study/src/main.rs
Normal 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()))),
|
||||||
|
}
|
||||||
|
}
|
||||||
203
__concurrent/crossbeam_n_parking_lot/Cargo.lock
generated
Normal file
203
__concurrent/crossbeam_n_parking_lot/Cargo.lock
generated
Normal 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"
|
||||||
13
__concurrent/crossbeam_n_parking_lot/Cargo.toml
Normal file
13
__concurrent/crossbeam_n_parking_lot/Cargo.toml
Normal 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"
|
||||||
37
__concurrent/crossbeam_n_parking_lot/examples/multi_chan.rs
Normal file
37
__concurrent/crossbeam_n_parking_lot/examples/multi_chan.rs
Normal 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();
|
||||||
|
}
|
||||||
8
__concurrent/crossbeam_n_parking_lot/justfile
Normal file
8
__concurrent/crossbeam_n_parking_lot/justfile
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
_:
|
||||||
|
@just --list
|
||||||
|
|
||||||
|
ex-multi-chan:
|
||||||
|
cargo r --example multi_chan
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
38
__concurrent/crossbeam_n_parking_lot/src/main.rs
Normal file
38
__concurrent/crossbeam_n_parking_lot/src/main.rs
Normal 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
296
__concurrent/glommio/Cargo.lock
generated
Normal 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"
|
||||||
10
__concurrent/glommio/Cargo.toml
Normal file
10
__concurrent/glommio/Cargo.toml
Normal 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"
|
||||||
7
__concurrent/glommio/README.md
Normal file
7
__concurrent/glommio/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
build failed!
|
||||||
|
|
||||||
|
url
|
||||||
|
https://crates.io/crates/glommio
|
||||||
|
|
||||||
|
|
||||||
7
__concurrent/glommio/src/main.rs
Normal file
7
__concurrent/glommio/src/main.rs
Normal 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
5
__concurrent/green-threads/Cargo.lock
generated
Normal 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"
|
||||||
9
__concurrent/green-threads/Cargo.toml
Normal file
9
__concurrent/green-threads/Cargo.toml
Normal 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]
|
||||||
8
__concurrent/green-threads/README.md
Normal file
8
__concurrent/green-threads/README.md
Normal 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
|
||||||
|
|
||||||
|
|
||||||
1
__concurrent/green-threads/rust-toolchain
Normal file
1
__concurrent/green-threads/rust-toolchain
Normal file
@@ -0,0 +1 @@
|
|||||||
|
nightly
|
||||||
200
__concurrent/green-threads/src/main.rs
Normal file
200
__concurrent/green-threads/src/main.rs
Normal 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
25
__concurrent/qcell/Cargo.lock
generated
Normal 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",
|
||||||
|
]
|
||||||
10
__concurrent/qcell/Cargo.toml
Normal file
10
__concurrent/qcell/Cargo.toml
Normal 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"
|
||||||
|
|
||||||
16
__concurrent/qcell/src/main.rs
Normal file
16
__concurrent/qcell/src/main.rs
Normal 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
149
__concurrent/rayon/Cargo.lock
generated
Normal 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"
|
||||||
11
__concurrent/rayon/Cargo.toml
Normal file
11
__concurrent/rayon/Cargo.toml
Normal 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"
|
||||||
|
|
||||||
32
__concurrent/rayon/src/main.rs
Normal file
32
__concurrent/rayon/src/main.rs
Normal 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
444
__concurrent/waitgroup-demo/Cargo.lock
generated
Normal 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"
|
||||||
10
__concurrent/waitgroup-demo/Cargo.toml
Normal file
10
__concurrent/waitgroup-demo/Cargo.toml
Normal 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"
|
||||||
26
__concurrent/waitgroup-demo/src/main.rs
Normal file
26
__concurrent/waitgroup-demo/src/main.rs
Normal 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
72
__cpu/x86/Cargo.lock
generated
Normal 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
11
__cpu/x86/Cargo.toml
Normal 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
4
__cpu/x86/README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
crate:
|
||||||
|
https://github.com/gz/rust-x86
|
||||||
|
|
||||||
|
|
||||||
1
__cpu/x86/rust-toolchain
Normal file
1
__cpu/x86/rust-toolchain
Normal file
@@ -0,0 +1 @@
|
|||||||
|
nightly
|
||||||
20
__cpu/x86/src/main.rs
Normal file
20
__cpu/x86/src/main.rs
Normal 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
4
__crypto/README.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Cryptography:
|
||||||
|
https://cryptography.rs/
|
||||||
|
|
||||||
|
|
||||||
454
__crypto/aegis-test/Cargo.lock
generated
Normal file
454
__crypto/aegis-test/Cargo.lock
generated
Normal 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",
|
||||||
|
]
|
||||||
14
__crypto/aegis-test/Cargo.toml
Normal file
14
__crypto/aegis-test/Cargo.toml
Normal 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"
|
||||||
62
__crypto/aegis-test/README.md
Normal file
62
__crypto/aegis-test/README.md
Normal 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
|
||||||
|
```
|
||||||
84
__crypto/aegis-test/src/main.rs
Normal file
84
__crypto/aegis-test/src/main.rs
Normal 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
100
__crypto/aes_ctr_test/Cargo.lock
generated
Normal 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"
|
||||||
8
__crypto/aes_ctr_test/Cargo.toml
Normal file
8
__crypto/aes_ctr_test/Cargo.toml
Normal 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"
|
||||||
42
__crypto/aes_ctr_test/README.md
Normal file
42
__crypto/aes_ctr_test/README.md
Normal 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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
109
__crypto/aes_ctr_test/src/main.rs
Normal file
109
__crypto/aes_ctr_test/src/main.rs
Normal 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
107
__crypto/aes_gcm_crypto/Cargo.lock
generated
Normal 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"
|
||||||
11
__crypto/aes_gcm_crypto/Cargo.toml
Normal file
11
__crypto/aes_gcm_crypto/Cargo.toml
Normal 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"
|
||||||
162
__crypto/aes_gcm_crypto/src/main.rs
Normal file
162
__crypto/aes_gcm_crypto/src/main.rs
Normal 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
185
__crypto/asn1-der-test/Cargo.lock
generated
Normal 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"
|
||||||
11
__crypto/asn1-der-test/Cargo.toml
Normal file
11
__crypto/asn1-der-test/Cargo.toml
Normal 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"
|
||||||
91
__crypto/asn1-der-test/src/bin/test1.rs
Normal file
91
__crypto/asn1-der-test/src/bin/test1.rs
Normal 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()));
|
||||||
|
}
|
||||||
52
__crypto/asn1-der-test/src/bin/test2.rs
Normal file
52
__crypto/asn1-der-test/src/bin/test2.rs
Normal 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
284
__crypto/bc1-btc-address/Cargo.lock
generated
Normal 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",
|
||||||
|
]
|
||||||
9
__crypto/bc1-btc-address/Cargo.toml
Normal file
9
__crypto/bc1-btc-address/Cargo.toml
Normal 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"
|
||||||
29
__crypto/bc1-btc-address/src/main.rs
Normal file
29
__crypto/bc1-btc-address/src/main.rs
Normal 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
333
__crypto/btc-address/Cargo.lock
generated
Normal 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"
|
||||||
20
__crypto/btc-address/Cargo.toml
Normal file
20
__crypto/btc-address/Cargo.toml
Normal 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"
|
||||||
|
|
||||||
116
__crypto/btc-address/src/main.rs
Normal file
116
__crypto/btc-address/src/main.rs
Normal 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()
|
||||||
|
}
|
||||||
31
__crypto/crypto2-demo/Cargo.lock
generated
Normal file
31
__crypto/crypto2-demo/Cargo.lock
generated
Normal 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
Reference in New Issue
Block a user