Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a91bd3bafc | |||
| 207675f522 | |||
| c4c0ad2e12 | |||
| 54500810a0 | |||
| c93bf8f1d2 | |||
| df0b260c7b | |||
| c7fff59f6c | |||
| 0f645d0689 | |||
| 2bbcca5253 | |||
| e5f238a126 | |||
| ac8b4d6f81 | |||
| 561400ae3c | |||
| 9d9beefe7f |
467
Cargo.lock
generated
467
Cargo.lock
generated
@@ -3,17 +3,79 @@
|
|||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-compression"
|
name = "anstream"
|
||||||
version = "0.4.32"
|
version = "0.6.21"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5a89bce6054c720275ac2432fbba080a66a2106a44a1b804553930ca6909f4e0"
|
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"compression-codecs",
|
"anstyle",
|
||||||
"compression-core",
|
"anstyle-parse",
|
||||||
"futures-core",
|
"anstyle-query",
|
||||||
"pin-project-lite",
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
|
||||||
|
|
||||||
|
[[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.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.60.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"once_cell_polyfill",
|
||||||
|
"windows-sys 0.60.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base16ct"
|
||||||
|
version = "0.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d8b59d472eab27ade8d770dcb11da7201c11234bef9f82ce7aa517be028d462b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64ct"
|
||||||
|
version = "1.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytes"
|
||||||
|
version = "1.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.2.41"
|
version = "1.2.41"
|
||||||
@@ -33,21 +95,130 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "compression-codecs"
|
name = "chacha20"
|
||||||
version = "0.4.31"
|
version = "0.10.0-rc.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ef8a506ec4b81c460798f572caead636d57d3d7e940f998160f52bd254bf2d23"
|
checksum = "9bd162f2b8af3e0639d83f28a637e4e55657b7a74508dba5a9bf4da523d5c9e9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"compression-core",
|
"cfg-if",
|
||||||
"zstd",
|
"cpufeatures",
|
||||||
"zstd-safe",
|
"rand_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "compression-core"
|
name = "clap"
|
||||||
version = "0.4.29"
|
version = "4.5.49"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e47641d3deaf41fb1538ac1f54735925e275eaf3bf4d55c81b137fba797e5cbb"
|
checksum = "f4512b90fa68d3a9932cea5184017c5d200f5921df706d45e853537dea51508f"
|
||||||
|
dependencies = [
|
||||||
|
"clap_builder",
|
||||||
|
"clap_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_builder"
|
||||||
|
version = "4.5.49"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0025e98baa12e766c67ba13ff4695a887a1eba19569aad00a472546795bd6730"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"clap_lex",
|
||||||
|
"strsim",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "4.5.49"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "0.7.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "const-oid"
|
||||||
|
version = "0.10.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0dabb6555f92fb9ee4140454eb5dcd14c7960e1225c6d1a6cc361f032947713e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cpufeatures"
|
||||||
|
version = "0.2.17"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-bigint"
|
||||||
|
version = "0.7.0-rc.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f4b0fda9462026d53a3ef37c5ec283639ee8494a1a5401109c0e2a3fb4d490c"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
"rand_core",
|
||||||
|
"serdect",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-common"
|
||||||
|
version = "0.2.0-rc.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6a8235645834fbc6832939736ce2f2d08192652269e11010a6240f61b908a1c6"
|
||||||
|
dependencies = [
|
||||||
|
"hybrid-array",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crypto-primes"
|
||||||
|
version = "0.7.0-pre.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "25f2523fbb68811c8710829417ad488086720a6349e337c38d12fa81e09e50bf"
|
||||||
|
dependencies = [
|
||||||
|
"crypto-bigint",
|
||||||
|
"libm",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "der"
|
||||||
|
version = "0.8.0-rc.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e9d8dd2f26c86b27a2a8ea2767ec7f9df7a89516e4794e54ac01ee618dda3aa4"
|
||||||
|
dependencies = [
|
||||||
|
"const-oid",
|
||||||
|
"pem-rfc7468",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "digest"
|
||||||
|
version = "0.11.0-rc.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dac89f8a64533a9b0eaa73a68e424db0fb1fd6271c74cc0125336a05f090568d"
|
||||||
|
dependencies = [
|
||||||
|
"const-oid",
|
||||||
|
"crypto-common",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "find-msvc-tools"
|
name = "find-msvc-tools"
|
||||||
@@ -55,12 +226,6 @@ version = "0.1.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-core"
|
|
||||||
version = "0.3.31"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "getrandom"
|
name = "getrandom"
|
||||||
version = "0.3.4"
|
version = "0.3.4"
|
||||||
@@ -73,6 +238,27 @@ dependencies = [
|
|||||||
"wasip2",
|
"wasip2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hybrid-array"
|
||||||
|
version = "0.4.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f471e0a81b2f90ffc0cb2f951ae04da57de8baa46fa99112b062a5173a5088d0"
|
||||||
|
dependencies = [
|
||||||
|
"typenum",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.15"
|
version = "1.0.15"
|
||||||
@@ -95,6 +281,12 @@ version = "0.2.177"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libm"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "md5"
|
name = "md5"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
@@ -107,12 +299,56 @@ version = "2.7.6"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell_polyfill"
|
||||||
|
version = "1.70.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pem-rfc7468"
|
||||||
|
version = "1.0.0-rc.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a8e58fab693c712c0d4e88f8eb3087b6521d060bcaf76aeb20cb192d809115ba"
|
||||||
|
dependencies = [
|
||||||
|
"base64ct",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project-lite"
|
name = "pin-project-lite"
|
||||||
version = "0.2.16"
|
version = "0.2.16"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
|
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkcs1"
|
||||||
|
version = "0.8.0-rc.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "986d2e952779af96ea048f160fd9194e1751b4faea78bcf3ceb456efe008088e"
|
||||||
|
dependencies = [
|
||||||
|
"der",
|
||||||
|
"spki",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pkcs8"
|
||||||
|
version = "0.11.0-rc.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "93eac55f10aceed84769df670ea4a32d2ffad7399400d41ee1c13b1cd8e1b478"
|
||||||
|
dependencies = [
|
||||||
|
"der",
|
||||||
|
"spki",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pkg-config"
|
name = "pkg-config"
|
||||||
version = "0.3.32"
|
version = "0.3.32"
|
||||||
@@ -143,6 +379,44 @@ version = "5.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rand"
|
||||||
|
version = "0.10.0-rc.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5ec474812b9de55111b29da8a1559f1718ef3dc20fa36f031f1b5d9e3836ad6c"
|
||||||
|
dependencies = [
|
||||||
|
"chacha20",
|
||||||
|
"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 = "rsa"
|
||||||
|
version = "0.10.0-rc.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bf8955ab399f6426998fde6b76ae27233cce950705e758a6c17afd2f6d0e5d52"
|
||||||
|
dependencies = [
|
||||||
|
"const-oid",
|
||||||
|
"crypto-bigint",
|
||||||
|
"crypto-primes",
|
||||||
|
"digest",
|
||||||
|
"pkcs1",
|
||||||
|
"pkcs8",
|
||||||
|
"rand_core",
|
||||||
|
"signature",
|
||||||
|
"spki",
|
||||||
|
"subtle",
|
||||||
|
"zeroize",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.20"
|
version = "1.0.20"
|
||||||
@@ -201,6 +475,16 @@ dependencies = [
|
|||||||
"serde_core",
|
"serde_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serdect"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d3ef0e35b322ddfaecbc60f34ab448e157e48531288ee49fafbb053696b8ffe2"
|
||||||
|
dependencies = [
|
||||||
|
"base16ct",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
@@ -208,10 +492,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "signature"
|
||||||
version = "2.0.106"
|
version = "3.0.0-rc.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
|
checksum = "fc280a6ff65c79fbd6622f64d7127f32b85563bca8c53cd2e9141d6744a9056d"
|
||||||
|
dependencies = [
|
||||||
|
"digest",
|
||||||
|
"rand_core",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spki"
|
||||||
|
version = "0.8.0-rc.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8baeff88f34ed0691978ec34440140e1572b68c7dd4a495fd14a3dc1944daa80"
|
||||||
|
dependencies = [
|
||||||
|
"base64ct",
|
||||||
|
"der",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "subtle"
|
||||||
|
version = "2.6.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.107"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2a26dbd934e5451d21ef060c018dae56fc073894c5a7896f882928a76e6d081b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -224,6 +540,7 @@ version = "1.48.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
|
checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"tokio-macros",
|
"tokio-macros",
|
||||||
]
|
]
|
||||||
@@ -239,12 +556,24 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "typenum"
|
||||||
|
version = "1.19.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-ident"
|
name = "unicode-ident"
|
||||||
version = "1.0.19"
|
version = "1.0.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
|
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "walkdir"
|
name = "walkdir"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@@ -270,7 +599,7 @@ version = "0.1.11"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-sys",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -279,6 +608,15 @@ version = "0.2.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.60.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.61.2"
|
version = "0.61.2"
|
||||||
@@ -288,6 +626,71 @@ dependencies = [
|
|||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.53.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
|
||||||
|
dependencies = [
|
||||||
|
"windows-link",
|
||||||
|
"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.53.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.53.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.53.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnullvm"
|
||||||
|
version = "0.53.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.53.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.53.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.53.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.53.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wit-bindgen"
|
name = "wit-bindgen"
|
||||||
version = "0.46.0"
|
version = "0.46.0"
|
||||||
@@ -295,11 +698,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zdiff"
|
name = "zeroize"
|
||||||
|
version = "1.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zsdiff_all"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-compression",
|
"clap",
|
||||||
"md5",
|
"md5",
|
||||||
|
"rand",
|
||||||
|
"rsa",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|||||||
21
Cargo.toml
21
Cargo.toml
@@ -1,13 +1,26 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "zdiff"
|
name = "zsdiff_all"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "zsdiff"
|
||||||
|
path = "src/zsdiff.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "zspatch"
|
||||||
|
path = "src/zspatch.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
zstd = { version = "0.13" }
|
zstd = { version = "0.13" }
|
||||||
async-compression = { version = "0.4", features = ["zstd"] }
|
tokio = { version = "1.48", features = ["rt", "rt-multi-thread", "macros", "fs", "io-util"] }
|
||||||
tokio = { version = "1.48.0", features = ["rt", "rt-multi-thread", "macros"] }
|
|
||||||
md5 = "0.8"
|
md5 = "0.8"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
walkdir = "2.5"
|
walkdir = "2.5"
|
||||||
|
clap = { version = "4.5", features = ["derive"] }
|
||||||
|
rsa = { version = "0.10.0-rc.9", features = ["std"] }
|
||||||
|
rand = { version = "0.10.0-rc.0", features = ["thread_rng", "std"] }
|
||||||
|
|||||||
9
Makefile
Normal file
9
Makefile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
all: build-linux build-win
|
||||||
|
|
||||||
|
build-linux:
|
||||||
|
cargo build --release --target x86_64-unknown-linux-gnu --package zsdiff_all --bin zspatch
|
||||||
|
cargo build --release --target x86_64-unknown-linux-gnu --package zsdiff_all --bin zsdiff
|
||||||
|
|
||||||
|
build-win:
|
||||||
|
cargo build --release --target x86_64-pc-windows-gnu --package zsdiff_all --bin zspatch
|
||||||
|
cargo build --release --target x86_64-pc-windows-gnu --package zsdiff_all --bin zsdiff
|
||||||
45
README.md
Normal file
45
README.md
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
# ZsDiff
|
||||||
|
|
||||||
|
A partial update program. Use [Zstandrard](https://github.com/facebook/zstd).
|
||||||
|
|
||||||
|
`zsdiff` products a [filename].zdiff file and [filename].zdiff.md5. It compares ALL file hashes from old with new.
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: zsdiff [OPTIONS] --filename <FILENAME> --old <OLD> --new <NEW>
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-f, --filename <FILENAME>
|
||||||
|
-c, --compress-level <COMPRESS_LEVEL> [default: 11]
|
||||||
|
-o, --old <OLD>
|
||||||
|
-n, --new <NEW>
|
||||||
|
-h, --help Print help
|
||||||
|
```
|
||||||
|
|
||||||
|
`zspatch` extract files from [filename].zdiff to [dest-dir]. If some file was deleted between old and new, `zspatch`
|
||||||
|
also delete it from [dest-dir].
|
||||||
|
Flag --hash-check compare computed hash of [filename].zdiff and hash from [filename].zdiff.md5
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage: zspatch [OPTIONS] --filename <FILENAME> --dest-dir <DEST_DIR>
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-f, --filename <FILENAME>
|
||||||
|
-d, --dest-dir <DEST_DIR>
|
||||||
|
-h, --hash-check
|
||||||
|
--help Print help
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
metadata version: uint16 (2 bytes)
|
||||||
|
metadata size: uint32 (4 bytes)
|
||||||
|
n = 6
|
||||||
|
metadata content: bytes (n;m bytes)
|
||||||
|
m = n+6
|
||||||
|
(content -> rsa -> zstd (bytes) -> bytes) (m;o)
|
||||||
|
content entry: {
|
||||||
|
size: uint32 (4 bytes)
|
||||||
|
i = 4
|
||||||
|
j = i + size
|
||||||
|
content: (i;j bytes)
|
||||||
|
}
|
||||||
|
```
|
||||||
53
src/main.rs
53
src/main.rs
@@ -1,53 +0,0 @@
|
|||||||
mod utils;
|
|
||||||
mod zdiff;
|
|
||||||
mod zpatch;
|
|
||||||
|
|
||||||
use std::fs;
|
|
||||||
use std::fs::read;
|
|
||||||
use std::io;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
async fn zdiff(filename: &str, old: &str, new: &str) -> Result<(), io::Error> {
|
|
||||||
let output_filename = &format!("{}.zdiff", filename);
|
|
||||||
let old_hashes = zdiff::walk_dir(old.to_string()).await;
|
|
||||||
let new_hashes = zdiff::walk_dir(new.to_string()).await;
|
|
||||||
let compare_hashes = zdiff::compare_hashes(old_hashes, new_hashes).await;
|
|
||||||
let parts = compare_hashes.to_vec().await;
|
|
||||||
utils::compress_parts(parts, fs::File::create(output_filename)?, 11).await;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn zpatch(filename: &str, dest_dir: &str) -> Result<(), io::Error> {
|
|
||||||
let filename = &format!("{}.zdiff", filename);
|
|
||||||
let parts = utils::decompress_parts(read(filename)?).await?;
|
|
||||||
let zdiff = zdiff::Zdiff::from_vec(parts).await?;
|
|
||||||
let tmp_dir_name = zpatch::extract_files(&zdiff, filename).await?;
|
|
||||||
for name in zdiff.content.keys().collect::<Vec<&String>>() {
|
|
||||||
let from_path = Path::new(&tmp_dir_name).join(name);
|
|
||||||
let to_path = Path::new(&dest_dir).join(name);
|
|
||||||
// println!("{:?} {:?}", from_path, to_path);
|
|
||||||
fs::create_dir_all(to_path.parent().unwrap())?;
|
|
||||||
fs::copy(from_path, to_path)?;
|
|
||||||
}
|
|
||||||
for file in zdiff.metadata.remove_files {
|
|
||||||
let path = Path::new(&dest_dir).join(file);
|
|
||||||
fs::remove_file(path)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (k, hash) in zdiff.metadata.hashes {
|
|
||||||
let path = Path::new(&dest_dir).join(k);
|
|
||||||
println!("path: {:?}", path);
|
|
||||||
let content = read(path)?;
|
|
||||||
let fs_hash = zdiff::get_hash(&content).await;
|
|
||||||
println!("{:?} {:?}", hash, fs_hash);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> io::Result<()> {
|
|
||||||
let filename = "test";
|
|
||||||
zdiff(filename, "test/old", "test/new").await?;
|
|
||||||
zpatch(filename, "old").await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
285
src/utils.rs
285
src/utils.rs
@@ -1,33 +1,262 @@
|
|||||||
use std::{fs, io};
|
use crate::utils;
|
||||||
|
use md5;
|
||||||
|
use rsa::pkcs1::{DecodeRsaPrivateKey, EncodeRsaPrivateKey, EncodeRsaPublicKey};
|
||||||
|
use rsa::pkcs8::LineEnding;
|
||||||
|
use rsa::traits::PublicKeyParts;
|
||||||
|
use rsa::{Pkcs1v15Encrypt, RsaPrivateKey, RsaPublicKey};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::io;
|
||||||
|
use tokio::fs;
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
use zstd::{Decoder, Encoder};
|
use zstd::{Decoder, Encoder};
|
||||||
|
|
||||||
pub async fn compress_parts(input: Vec<Vec<u8>>, output: fs::File, level: i32) {
|
const METADATA_VERSION: u16 = 1;
|
||||||
let mut encoder = Encoder::new(output, level).unwrap();
|
const SUPPORTED_VERSION: [u16; 1] = [1];
|
||||||
for part in input.iter() {
|
|
||||||
io::copy(&mut &part[..], &mut encoder).unwrap();
|
pub fn is_metadata_supported(version: u16) -> bool {
|
||||||
}
|
SUPPORTED_VERSION.contains(&version)
|
||||||
encoder.finish().unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn decompress_parts(input: Vec<u8>) -> Result<Vec<Vec<u8>>, io::Error> {
|
pub struct Zsdiff {
|
||||||
let mut decoder = Decoder::new(&input[..])?;
|
pub content: HashMap<String, Vec<u8>>,
|
||||||
let mut buf = Vec::new();
|
pub metadata: Metadata,
|
||||||
|
}
|
||||||
io::copy(&mut decoder, &mut buf)?;
|
|
||||||
let mut index = 0;
|
impl Zsdiff {
|
||||||
let mut parts: Vec<Vec<u8>> = Vec::new();
|
pub async fn from_vec(_data: Vec<u8>) -> Result<Self, io::Error> {
|
||||||
|
let meta_version = u16::from_be_bytes(_data[..2].try_into().unwrap());
|
||||||
while index < buf.len() {
|
println!(">>> Metadata version: {}", meta_version);
|
||||||
let filename_size = u32::from_be_bytes(buf[index..index + 4].try_into().unwrap()) as usize;
|
if !SUPPORTED_VERSION.contains(&meta_version) {
|
||||||
let filename = buf[index..index + filename_size + 4].to_vec();
|
return Err(io::Error::new(
|
||||||
index += 4 + filename_size;
|
io::ErrorKind::Other,
|
||||||
|
"Metadata version mismatch",
|
||||||
let content_size = u32::from_be_bytes(buf[index..index + 4].try_into().unwrap()) as usize;
|
));
|
||||||
let content = buf[index..index + content_size + 4].to_vec();
|
}
|
||||||
index += content_size + 4;
|
let meta_size = u32::from_be_bytes(_data[2..6].try_into().unwrap()) as usize;
|
||||||
|
let mut index = 6;
|
||||||
let part = vec![filename, content].concat();
|
let meta = _data[index..index + meta_size].to_vec();
|
||||||
parts.push(part);
|
let metadata: Metadata = serde_json::from_slice(&meta)?;
|
||||||
}
|
println!(">>> Metadata parsed successfully");
|
||||||
Ok(parts)
|
|
||||||
|
index += meta_size;
|
||||||
|
println!(">>> File count: {}", metadata.file_count);
|
||||||
|
|
||||||
|
let mut data = _data[index..].to_vec();
|
||||||
|
|
||||||
|
if metadata.encrypted {
|
||||||
|
println!(">>> Decrypting file");
|
||||||
|
let key_content = fs::read("./private.pem").await?;
|
||||||
|
let private_key = RsaPrivateKey::from_pkcs1_pem(
|
||||||
|
String::from_utf8(key_content)
|
||||||
|
.expect("Can't load key")
|
||||||
|
.as_str(),
|
||||||
|
)
|
||||||
|
.expect("Can't load private key");
|
||||||
|
let encrypter = Encrypter::from_private_key(private_key);
|
||||||
|
data = encrypter.decrypt(data).await;
|
||||||
|
println!(">>> Decrypting done");
|
||||||
|
}
|
||||||
|
println!(">>> Decompressing file");
|
||||||
|
let compressor = Compressor::new();
|
||||||
|
data = compressor.decompress(data).await?;
|
||||||
|
println!(">>> Decompressing done");
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
let mut content = HashMap::new();
|
||||||
|
while index < data.len() {
|
||||||
|
let filename_size =
|
||||||
|
u32::from_be_bytes(data[index..index + 4].try_into().unwrap()) as usize;
|
||||||
|
index += 4;
|
||||||
|
let filename = String::from_utf8(data[index..filename_size + index].to_vec()).unwrap();
|
||||||
|
index += filename_size;
|
||||||
|
|
||||||
|
let content_size =
|
||||||
|
u32::from_be_bytes(data[index..index + 4].try_into().unwrap()) as usize;
|
||||||
|
index += 4;
|
||||||
|
let cont = data[index..index + content_size].to_vec();
|
||||||
|
index += cont.len();
|
||||||
|
content.insert(filename, cont);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Zsdiff { content, metadata })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn to_vec(&self, compress_level: i32, encrypt: bool) -> Vec<u8> {
|
||||||
|
let mut meta_bytes: Vec<u8> = Vec::new();
|
||||||
|
meta_bytes.extend(METADATA_VERSION.to_be_bytes()); // u16
|
||||||
|
let meta = serde_json::to_vec(&self.metadata).unwrap();
|
||||||
|
meta_bytes.extend((meta.len() as u32).to_be_bytes()); // u32
|
||||||
|
meta_bytes.extend(meta);
|
||||||
|
|
||||||
|
let mut parts: Vec<u8> = Vec::new();
|
||||||
|
for (filename, content) in &self.content {
|
||||||
|
let filename_size: [u8; 4] = (filename.len() as u32).to_be_bytes();
|
||||||
|
let filename_encoded = vec![filename_size.as_slice(), filename.as_bytes()].concat();
|
||||||
|
|
||||||
|
let content_size: [u8; 4] = (content.len() as u32).to_be_bytes();
|
||||||
|
let content_encoded = vec![content_size.as_slice(), content.as_slice()].concat();
|
||||||
|
let part = vec![filename_encoded, content_encoded].concat();
|
||||||
|
parts.extend(part)
|
||||||
|
}
|
||||||
|
|
||||||
|
let size_before = parts.len();
|
||||||
|
parts = self.compress(parts, compress_level).await;
|
||||||
|
if encrypt {
|
||||||
|
parts = self.encrypt(parts).await;
|
||||||
|
}
|
||||||
|
|
||||||
|
let size_after = parts.len();
|
||||||
|
println!(">>> Size before: {:.1?}KB", size_before / 1024);
|
||||||
|
println!(">>> Size after: {:.1?}KB", size_after / 1024);
|
||||||
|
println!(
|
||||||
|
">>> Compress ratio: {:.2?}%",
|
||||||
|
size_after as f64 / size_before as f64 * 100.0
|
||||||
|
);
|
||||||
|
|
||||||
|
let out = vec![meta_bytes, parts].concat();
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn compress(&self, data: Vec<u8>, level: i32) -> Vec<u8> {
|
||||||
|
let compressor = Compressor::new();
|
||||||
|
println!(">>> Compressing");
|
||||||
|
let _data = compressor
|
||||||
|
.compress(data, level)
|
||||||
|
.await
|
||||||
|
.expect("Can't compress data");
|
||||||
|
println!(">>> Compressing done");
|
||||||
|
_data
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn encrypt(&self, data: Vec<u8>) -> Vec<u8> {
|
||||||
|
println!(">>> Encrypting");
|
||||||
|
let encrypter = Encrypter::new_pair();
|
||||||
|
let _data = encrypter.encrypt(data).await.expect("Can't encrypt data");
|
||||||
|
encrypter.export().await.expect("Can't export keys");
|
||||||
|
println!(">>> Encrypting done");
|
||||||
|
_data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct Metadata {
|
||||||
|
pub(crate) diff_files: Vec<String>,
|
||||||
|
pub hashes: HashMap<String, String>,
|
||||||
|
pub remove_files: Vec<String>,
|
||||||
|
pub remove_folders: Vec<String>,
|
||||||
|
pub file_count: u32,
|
||||||
|
pub compress_level: i32,
|
||||||
|
pub encrypted: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_hash(data: Vec<u8>) -> String {
|
||||||
|
let hash = md5::compute(&data[..]);
|
||||||
|
format!("{:x}", hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Compressor {}
|
||||||
|
impl Compressor {
|
||||||
|
pub(crate) fn new() -> Self {
|
||||||
|
Compressor {}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn compress(&self, input: Vec<u8>, level: i32) -> Result<Vec<u8>, io::Error> {
|
||||||
|
let buf = Vec::new();
|
||||||
|
let mut encoder = Encoder::new(buf, level)?;
|
||||||
|
io::copy(&mut &input[..], &mut encoder)?;
|
||||||
|
encoder.finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn decompress(&self, input: Vec<u8>) -> Result<Vec<u8>, io::Error> {
|
||||||
|
let mut decoder = Decoder::new(&input[..])?;
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
io::copy(&mut decoder, &mut buf)?;
|
||||||
|
Ok(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Encrypter {
|
||||||
|
private_key: RsaPrivateKey,
|
||||||
|
public_key: RsaPublicKey,
|
||||||
|
key_size: usize,
|
||||||
|
}
|
||||||
|
impl Encrypter {
|
||||||
|
pub fn new_pair() -> Self {
|
||||||
|
let mut rng = rand::rng();
|
||||||
|
let bits = 2048;
|
||||||
|
let private_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key");
|
||||||
|
let public_key = RsaPublicKey::from(&private_key);
|
||||||
|
Self {
|
||||||
|
private_key,
|
||||||
|
public_key,
|
||||||
|
key_size: bits,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_private_key(private_key: RsaPrivateKey) -> Self {
|
||||||
|
let public_key = RsaPublicKey::from(&private_key);
|
||||||
|
Self {
|
||||||
|
key_size: public_key.size(),
|
||||||
|
public_key,
|
||||||
|
private_key,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(private_key: RsaPrivateKey, public_key: RsaPublicKey) -> Self {
|
||||||
|
Self {
|
||||||
|
key_size: public_key.size(),
|
||||||
|
private_key,
|
||||||
|
public_key,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn encrypt(&self, data: Vec<u8>) -> Result<Vec<u8>, io::Error> {
|
||||||
|
let mut rng = rand::rng();
|
||||||
|
let mut out = Vec::new();
|
||||||
|
let segment_size = self.public_key.size() - 11;
|
||||||
|
|
||||||
|
for seg in data.chunks(segment_size) {
|
||||||
|
let segment = self
|
||||||
|
.public_key
|
||||||
|
.encrypt(&mut rng, Pkcs1v15Encrypt, seg)
|
||||||
|
.unwrap();
|
||||||
|
out.extend(segment)
|
||||||
|
}
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn decrypt(&self, data: Vec<u8>) -> Vec<u8> {
|
||||||
|
let mut out = Vec::new();
|
||||||
|
let segment_size = self.public_key.size();
|
||||||
|
for seg in data.chunks(segment_size) {
|
||||||
|
let segment = self
|
||||||
|
.private_key
|
||||||
|
.decrypt(Pkcs1v15Encrypt, seg)
|
||||||
|
.expect("failed to decrypt");
|
||||||
|
out.extend(segment)
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn export(&self) -> Result<(), io::Error> {
|
||||||
|
let private_bytes = self
|
||||||
|
.private_key
|
||||||
|
.to_pkcs1_pem(LineEnding::CRLF)
|
||||||
|
.expect("failed to pem private key");
|
||||||
|
let public_bytes = self
|
||||||
|
.public_key
|
||||||
|
.to_pkcs1_pem(LineEnding::CRLF)
|
||||||
|
.expect("failed to pem public key");
|
||||||
|
|
||||||
|
fs::File::create("private.pem")
|
||||||
|
.await?
|
||||||
|
.write_all(private_bytes.as_bytes())
|
||||||
|
.await?;
|
||||||
|
fs::File::create("public.pem")
|
||||||
|
.await?
|
||||||
|
.write_all(public_bytes.as_bytes())
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
127
src/zdiff.rs
127
src/zdiff.rs
@@ -1,127 +0,0 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fs;
|
|
||||||
use walkdir::WalkDir;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Zdiff {
|
|
||||||
pub content: HashMap<String, Vec<u8>>,
|
|
||||||
pub metadata: Metadata,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Zdiff {
|
|
||||||
pub async fn from_vec(_data: Vec<Vec<u8>>) -> Result<Self, std::io::Error> {
|
|
||||||
let mut content = HashMap::new();
|
|
||||||
for part in _data {
|
|
||||||
let filename_size = u32::from_be_bytes(part[0..4].try_into().unwrap()) as usize;
|
|
||||||
let filename = String::from_utf8(part[4..filename_size + 4].to_vec()).unwrap();
|
|
||||||
let cont = part[filename_size + 8..].to_vec();
|
|
||||||
content.insert(filename, cont);
|
|
||||||
}
|
|
||||||
let meta = content.get("metadata.json").unwrap();
|
|
||||||
let metadata: Metadata = serde_json::from_slice(meta.as_slice())?;
|
|
||||||
content.remove("metadata.json");
|
|
||||||
|
|
||||||
Ok(Zdiff { content, metadata })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn to_vec(&self) -> Vec<Vec<u8>> {
|
|
||||||
let mut parts: Vec<Vec<u8>> = Vec::new();
|
|
||||||
for (filename, content) in &self.content {
|
|
||||||
let filename_size: [u8; 4] = (filename.len() as u32).to_be_bytes();
|
|
||||||
let filename_encoded = vec![filename_size.as_slice(), filename.as_bytes()].concat();
|
|
||||||
|
|
||||||
let content_size: [u8; 4] = (content.len() as u32).to_be_bytes();
|
|
||||||
let content_encoded = vec![content_size.as_slice(), content.as_slice()].concat();
|
|
||||||
parts.push(vec![filename_encoded, content_encoded].concat())
|
|
||||||
}
|
|
||||||
|
|
||||||
let meta = serde_json::to_vec(&self.metadata).unwrap();
|
|
||||||
let meta_filename = "metadata.json";
|
|
||||||
let meta_filename_size = (meta_filename.len() as u32).to_be_bytes();
|
|
||||||
let meta_filename_encoded =
|
|
||||||
vec![meta_filename_size.as_slice(), meta_filename.as_bytes()].concat();
|
|
||||||
|
|
||||||
let meta_size = (meta.len() as u32).to_be_bytes();
|
|
||||||
let meta_encoded = vec![meta_size.as_slice(), meta.as_slice()].concat();
|
|
||||||
parts.push(vec![meta_filename_encoded, meta_encoded].concat());
|
|
||||||
|
|
||||||
parts
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
|
||||||
pub struct Metadata {
|
|
||||||
diff_files: Vec<String>,
|
|
||||||
pub hashes: HashMap<String, String>,
|
|
||||||
pub remove_files: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct FileInfo {
|
|
||||||
path: String,
|
|
||||||
relative_path: String, // Without dir prefix
|
|
||||||
hash: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_hash(data: &Vec<u8>) -> String {
|
|
||||||
let hash = md5::compute(&data[..]);
|
|
||||||
format!("{:x}", hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn walk_dir(dir: String) -> HashMap<String, FileInfo> {
|
|
||||||
let mut hash_list: HashMap<String, FileInfo> = HashMap::new();
|
|
||||||
for e in WalkDir::new(&dir) {
|
|
||||||
let e = e.unwrap();
|
|
||||||
let path = e.path();
|
|
||||||
if path.is_dir() {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
let content = fs::read(path).unwrap();
|
|
||||||
let hash = get_hash(&content).await;
|
|
||||||
// let filename = path.file_name().unwrap().to_str().unwrap().to_string();
|
|
||||||
let path_str = path.display().to_string();
|
|
||||||
let file_info = FileInfo {
|
|
||||||
relative_path: path_str[dir.len() + 1..].to_string(),
|
|
||||||
path: path_str,
|
|
||||||
hash: hash.clone(),
|
|
||||||
};
|
|
||||||
hash_list.insert(hash, file_info);
|
|
||||||
}
|
|
||||||
hash_list
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn compare_hashes(
|
|
||||||
old: HashMap<String, FileInfo>,
|
|
||||||
new: HashMap<String, FileInfo>,
|
|
||||||
) -> Zdiff {
|
|
||||||
let mut diff_files: HashMap<String, Vec<u8>> = HashMap::new();
|
|
||||||
let mut remove_files: Vec<String> = vec![];
|
|
||||||
let mut hashes: HashMap<String, String> = HashMap::new();
|
|
||||||
for (_, info) in &old {
|
|
||||||
remove_files.push(info.relative_path.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (new_hash, new_fileinfo) in &new {
|
|
||||||
let old_fileinfo = old.get(new_hash);
|
|
||||||
remove_files.retain(|filename| !filename.eq(&new_fileinfo.relative_path));
|
|
||||||
|
|
||||||
if old_fileinfo.is_none() {
|
|
||||||
let path = new_fileinfo.relative_path.clone();
|
|
||||||
diff_files.insert(path.clone(), fs::read(new_fileinfo.path.clone()).unwrap());
|
|
||||||
hashes.insert(
|
|
||||||
new_fileinfo.relative_path.clone(),
|
|
||||||
new_fileinfo.hash.clone(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Zdiff {
|
|
||||||
content: diff_files.clone(),
|
|
||||||
metadata: Metadata {
|
|
||||||
diff_files: diff_files.keys().cloned().collect(),
|
|
||||||
hashes,
|
|
||||||
remove_files,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
use crate::zdiff::Zdiff;
|
|
||||||
use crate::zpatch;
|
|
||||||
use std::fs;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
pub async fn create_tmp_dir(dir_name: String) -> Result<String, std::io::Error> {
|
|
||||||
let name = format!("{}.tmp", dir_name);
|
|
||||||
fs::remove_dir_all(name.clone()).map_err(|_| std::io::ErrorKind::NotFound)?;
|
|
||||||
fs::DirBuilder::new().create(name.clone())?;
|
|
||||||
Ok(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn extract_files(zdiff: &Zdiff, filename: &String) -> Result<String, std::io::Error> {
|
|
||||||
let tmp_dir_name = create_tmp_dir(filename.to_string()).await?;
|
|
||||||
let path = Path::new(&tmp_dir_name);
|
|
||||||
fs::remove_dir_all(path)?;
|
|
||||||
for (f, c) in zdiff.content.iter() {
|
|
||||||
let filepath = path.join(f);
|
|
||||||
fs::create_dir_all(filepath.parent().unwrap())?;
|
|
||||||
fs::File::create(&filepath)?.write_all(c)?;
|
|
||||||
}
|
|
||||||
Ok(tmp_dir_name)
|
|
||||||
}
|
|
||||||
149
src/zsdiff.rs
Normal file
149
src/zsdiff.rs
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
mod utils;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::fmt::format;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::{fs, io, time};
|
||||||
|
use utils::{Metadata, Zsdiff, get_hash};
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct FileInfo {
|
||||||
|
path: String,
|
||||||
|
relative_path: String, // Without dir prefix
|
||||||
|
hash: String,
|
||||||
|
is_dir: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn walk_dir(dir: String) -> HashMap<String, FileInfo> {
|
||||||
|
let mut hash_list: HashMap<String, FileInfo> = HashMap::new();
|
||||||
|
for e in WalkDir::new(&dir) {
|
||||||
|
let e = e.unwrap();
|
||||||
|
let path = e.path();
|
||||||
|
if path.display().to_string().eq(&dir) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let content: Vec<u8>;
|
||||||
|
if path.is_dir() {
|
||||||
|
let path_str = path.display().to_string();
|
||||||
|
content = path_str.into_bytes();
|
||||||
|
} else {
|
||||||
|
content = fs::read(path).unwrap();
|
||||||
|
}
|
||||||
|
let hash = get_hash(content).await;
|
||||||
|
let path_str = path.display().to_string();
|
||||||
|
let file_info = FileInfo {
|
||||||
|
relative_path: path_str[dir.len() + 1..].to_string(),
|
||||||
|
path: path_str,
|
||||||
|
hash: hash.clone(),
|
||||||
|
is_dir: path.is_dir(),
|
||||||
|
};
|
||||||
|
hash_list.entry(hash).or_insert(file_info);
|
||||||
|
}
|
||||||
|
hash_list
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn compare_hashes(
|
||||||
|
old: HashMap<String, FileInfo>,
|
||||||
|
new: HashMap<String, FileInfo>,
|
||||||
|
compress_level: i32,
|
||||||
|
encrypted: bool,
|
||||||
|
) -> Zsdiff {
|
||||||
|
let mut diff_files: HashMap<String, Vec<u8>> = HashMap::new();
|
||||||
|
let mut remove_files: Vec<String> = vec![];
|
||||||
|
let mut remove_folders: Vec<String> = vec![];
|
||||||
|
let mut hashes: HashMap<String, String> = HashMap::new();
|
||||||
|
for (_, info) in &old {
|
||||||
|
if info.is_dir {
|
||||||
|
remove_folders.push(info.relative_path.clone());
|
||||||
|
} else {
|
||||||
|
remove_files.push(info.relative_path.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (new_hash, new_fileinfo) in &new {
|
||||||
|
let old_fileinfo = old.get(new_hash);
|
||||||
|
if new_fileinfo.is_dir {
|
||||||
|
remove_folders.retain(|filename| !filename.eq(&new_fileinfo.relative_path));
|
||||||
|
} else {
|
||||||
|
remove_files.retain(|filename| !filename.eq(&new_fileinfo.relative_path));
|
||||||
|
}
|
||||||
|
|
||||||
|
if new_fileinfo.is_dir {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if old_fileinfo.is_none() {
|
||||||
|
let path = new_fileinfo.relative_path.clone();
|
||||||
|
diff_files.insert(path.clone(), fs::read(new_fileinfo.path.clone()).unwrap());
|
||||||
|
hashes.insert(path.clone(), new_fileinfo.hash.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Zsdiff {
|
||||||
|
content: diff_files.clone(),
|
||||||
|
metadata: Metadata {
|
||||||
|
diff_files: diff_files.keys().cloned().collect(),
|
||||||
|
hashes,
|
||||||
|
remove_files,
|
||||||
|
remove_folders,
|
||||||
|
compress_level,
|
||||||
|
file_count: diff_files.len() as u32,
|
||||||
|
encrypted,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn zsdiff(
|
||||||
|
filename: String,
|
||||||
|
old: String,
|
||||||
|
new: String,
|
||||||
|
level: i32,
|
||||||
|
encrypt: bool,
|
||||||
|
) -> Result<(), io::Error> {
|
||||||
|
let now = time::Instant::now();
|
||||||
|
let output_filename = &format!("{}.zdiff", filename);
|
||||||
|
let old_hashes = walk_dir(old).await;
|
||||||
|
let new_hashes = walk_dir(new).await;
|
||||||
|
let diff = compare_hashes(old_hashes, new_hashes, level, encrypt).await;
|
||||||
|
|
||||||
|
let mut file = fs::File::create(output_filename)?;
|
||||||
|
let data = diff.to_vec(level, encrypt).await;
|
||||||
|
file.write_all(&data[..])?;
|
||||||
|
|
||||||
|
let hash = get_hash(data).await;
|
||||||
|
let output_hash = format!("{} {}", hash.clone(), output_filename);
|
||||||
|
fs::File::create(format!("{}.md5", output_filename))?.write_all(output_hash.as_bytes())?;
|
||||||
|
let elapsed = now.elapsed();
|
||||||
|
println!(">>> Zsdiff hash: {}", hash);
|
||||||
|
println!("Time elapsed: {:.2?}", elapsed);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
struct Args {
|
||||||
|
#[arg(short, long)]
|
||||||
|
filename: String,
|
||||||
|
#[arg(short, long, default_value_t = 11)]
|
||||||
|
compress_level: i32,
|
||||||
|
#[arg(short, long)]
|
||||||
|
old: String,
|
||||||
|
#[arg(short, long)]
|
||||||
|
new: String,
|
||||||
|
#[arg(short, long)]
|
||||||
|
encrypt: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> io::Result<()> {
|
||||||
|
let args = Args::parse();
|
||||||
|
zsdiff(
|
||||||
|
args.filename,
|
||||||
|
args.old,
|
||||||
|
args.new,
|
||||||
|
args.compress_level,
|
||||||
|
args.encrypt,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
275
src/zspatch.rs
Normal file
275
src/zspatch.rs
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
mod utils;
|
||||||
|
|
||||||
|
use crate::utils::Metadata;
|
||||||
|
use clap::{Arg, ArgAction, ArgMatches, Command, Parser};
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::{io, time};
|
||||||
|
use tokio::fs;
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
|
use utils::Zsdiff;
|
||||||
|
|
||||||
|
async fn create_tmp_dir(dir_name: String) -> Result<String, io::Error> {
|
||||||
|
let name = PathBuf::from(format!("{}_tmp", dir_name));
|
||||||
|
if name.exists() {
|
||||||
|
fs::remove_dir_all(&name).await?;
|
||||||
|
}
|
||||||
|
fs::create_dir(&name).await?;
|
||||||
|
name.to_str().map(|s| s.to_string()).ok_or_else(|| {
|
||||||
|
io::Error::new(
|
||||||
|
io::ErrorKind::InvalidData,
|
||||||
|
"Path contains invalid UTF-8 characters",
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn load_metadata(filename: String) -> Result<Metadata, io::Error> {
|
||||||
|
let filepath = format!("{}.zdiff", filename);
|
||||||
|
let data = fs::read(&filepath).await?;
|
||||||
|
|
||||||
|
let meta_version = u16::from_be_bytes(data[..2].try_into().unwrap());
|
||||||
|
if !utils::is_metadata_supported(meta_version) {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::InvalidData,
|
||||||
|
"Metadata version not supported",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let meta_size = u32::from_be_bytes(data[2..6].try_into().unwrap()) as usize;
|
||||||
|
let meta_data = data[6..meta_size + 6].to_vec();
|
||||||
|
let metadata = serde_json::from_slice(&meta_data[..])
|
||||||
|
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?;
|
||||||
|
|
||||||
|
Ok(metadata)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn load_file(filename: String) -> Result<Zsdiff, io::Error> {
|
||||||
|
let full_filename = format!("{}.zdiff", filename);
|
||||||
|
let data = fs::read(&full_filename).await?;
|
||||||
|
let zsdiff = Zsdiff::from_vec(data).await?;
|
||||||
|
println!(
|
||||||
|
">>> Metadata files to remove: {}",
|
||||||
|
zsdiff.metadata.remove_files.len()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
">>> Metadata hashes to check: {}",
|
||||||
|
zsdiff.metadata.hashes.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(zsdiff)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn extract_files(zsdiff: &Zsdiff, filename: String) -> Result<String, io::Error> {
|
||||||
|
let tmp_dir_name = create_tmp_dir(filename.to_string()).await?;
|
||||||
|
let path = Path::new(&tmp_dir_name);
|
||||||
|
|
||||||
|
for (i, (f, c)) in zsdiff.content.iter().enumerate() {
|
||||||
|
println!(
|
||||||
|
">>> Processing file {}/{}: '{}'",
|
||||||
|
i + 1,
|
||||||
|
zsdiff.content.len(),
|
||||||
|
f
|
||||||
|
);
|
||||||
|
let filepath = path.join(f);
|
||||||
|
if let Some(parent) = filepath.parent() {
|
||||||
|
fs::create_dir_all(parent).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut file = fs::File::create(&filepath).await?;
|
||||||
|
file.write_all(c).await?;
|
||||||
|
}
|
||||||
|
Ok(tmp_dir_name)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn check_hash(filename: String) -> Result<(), io::Error> {
|
||||||
|
let file_data = fs::read(format!("{}.zdiff", filename)).await?;
|
||||||
|
let mut hash_file =
|
||||||
|
String::from_utf8(fs::read(format!("{}.zdiff.md5", filename)).await?).unwrap();
|
||||||
|
let hash = utils::get_hash(file_data).await;
|
||||||
|
hash_file = hash_file.split(" ").next().unwrap().parse().unwrap();
|
||||||
|
if !hash_file.eq(&hash) {
|
||||||
|
return Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
format!("Hash mismatch. Expected {}, got {}", hash_file, hash),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
println!(">>> Zsdiff hash: {}", hash);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn zspatch(filename: String, dest_dir: String) -> Result<(), io::Error> {
|
||||||
|
let now = time::Instant::now();
|
||||||
|
let cloned = filename.clone();
|
||||||
|
let diff = load_file(cloned).await.ok().unwrap();
|
||||||
|
let tmp_dir_name = extract_files(&diff, filename).await?;
|
||||||
|
|
||||||
|
let files_to_copy: Vec<String> = diff.content.keys().cloned().collect();
|
||||||
|
for (_, name) in files_to_copy.iter().enumerate() {
|
||||||
|
let from_path = Path::new(&tmp_dir_name).join(name);
|
||||||
|
let to_path = Path::new(&dest_dir).join(name);
|
||||||
|
|
||||||
|
if !from_path.exists() {
|
||||||
|
println!("ERROR: Source file doesn't exist: {:?}", from_path);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(parent) = to_path.parent() {
|
||||||
|
fs::create_dir_all(parent).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::copy(from_path.clone(), to_path.clone()).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
for file in &diff.metadata.remove_files {
|
||||||
|
let path = Path::new(&dest_dir).join(file);
|
||||||
|
println!(">>> Removing file {}", path.display());
|
||||||
|
|
||||||
|
if !path.exists() {
|
||||||
|
println!("File doesn't exist, skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::remove_file(path.clone()).await?
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(">>> Starting folder removal process <<<");
|
||||||
|
println!(
|
||||||
|
">>> Folders to remove: {}",
|
||||||
|
diff.metadata.remove_folders.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
for folder in &diff.metadata.remove_folders {
|
||||||
|
let path = Path::new(&dest_dir).join(folder);
|
||||||
|
|
||||||
|
if !path.exists() {
|
||||||
|
println!("Folder doesn't exist, skipping");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::remove_dir_all(path.clone()).await?
|
||||||
|
}
|
||||||
|
|
||||||
|
println!(">>> Starting hash verification <<<");
|
||||||
|
println!(">>> Files to verify: {}", diff.metadata.hashes.len());
|
||||||
|
|
||||||
|
for (k, hash) in &diff.metadata.hashes {
|
||||||
|
let path = Path::new(&dest_dir).join(k);
|
||||||
|
|
||||||
|
match fs::read(path.clone()).await {
|
||||||
|
Ok(content) => {
|
||||||
|
let fs_hash = utils::get_hash(content).await;
|
||||||
|
if !fs_hash.eq(hash) {
|
||||||
|
println!(
|
||||||
|
"Hash mismatch. Expected {}, got {}. Path: {}",
|
||||||
|
hash,
|
||||||
|
fs_hash,
|
||||||
|
path.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
println!("Can't read file for hash verification: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::remove_dir_all(tmp_dir_name).await?;
|
||||||
|
println!(">>> Patching done! <<<");
|
||||||
|
println!(">>> Elapsed time: {:.2?}", now.elapsed());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
struct Args {
|
||||||
|
#[arg(short, long)]
|
||||||
|
filename: String,
|
||||||
|
#[arg(short, long)]
|
||||||
|
dest_dir: String,
|
||||||
|
#[arg(short, long)]
|
||||||
|
metadata: bool,
|
||||||
|
#[arg(short, long)]
|
||||||
|
check_hash: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> io::Result<()> {
|
||||||
|
let m = Command::new("ZsPatch")
|
||||||
|
.author("ScuroNeko")
|
||||||
|
.version("0.3.0")
|
||||||
|
.about("Explains in brief what the program does")
|
||||||
|
.subcommand_required(true)
|
||||||
|
.arg_required_else_help(true)
|
||||||
|
.after_help("")
|
||||||
|
.subcommand(
|
||||||
|
Command::new("metadata")
|
||||||
|
.short_flag('m')
|
||||||
|
.long_flag("metadata")
|
||||||
|
.arg(
|
||||||
|
Arg::new("filename")
|
||||||
|
.short('f')
|
||||||
|
.long("filename")
|
||||||
|
.required(true)
|
||||||
|
.action(ArgAction::Set),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
Command::new("patch")
|
||||||
|
.short_flag('p')
|
||||||
|
.arg(
|
||||||
|
Arg::new("filename")
|
||||||
|
.short('f')
|
||||||
|
.required(true)
|
||||||
|
.action(ArgAction::Set),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("dest")
|
||||||
|
.short('d')
|
||||||
|
.required(true)
|
||||||
|
.action(ArgAction::Set),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("hash_check")
|
||||||
|
.long("hash_check")
|
||||||
|
.required(false)
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.get_matches();
|
||||||
|
|
||||||
|
match m.subcommand() {
|
||||||
|
Some(("metadata", meta_matches)) => {
|
||||||
|
let filename: &String = meta_matches.get_one("filename").unwrap();
|
||||||
|
let metadata = load_metadata(filename.clone()).await?;
|
||||||
|
println!(">>> Compress level: {}", metadata.compress_level);
|
||||||
|
println!(
|
||||||
|
">>> Encrypted?: {}",
|
||||||
|
if metadata.encrypted { "Yes" } else { "No" }
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
Some(("patch", patch_matches)) => {
|
||||||
|
let filename: &String = patch_matches.get_one("filename").unwrap();
|
||||||
|
let dest_dir: &String = patch_matches.get_one("dest").unwrap();
|
||||||
|
if patch_matches.get_flag("hash_check") {
|
||||||
|
check_hash(filename.clone()).await.ok();
|
||||||
|
}
|
||||||
|
zspatch(filename.clone(), dest_dir.clone()).await?;
|
||||||
|
}
|
||||||
|
_ => unreachable!("Subcommand is required"),
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
|
||||||
|
// let args = Args::parse();
|
||||||
|
//
|
||||||
|
// let filename = args.filename.clone();
|
||||||
|
// let dest_dir = args.dest_dir.clone();
|
||||||
|
//
|
||||||
|
// if args.check_hash {
|
||||||
|
// check_hash(args.filename.clone()).await.ok();
|
||||||
|
// }
|
||||||
|
// if args.metadata {
|
||||||
|
// let diff = load_file(filename).await?;
|
||||||
|
// let metadata = diff.metadata;
|
||||||
|
// println!(">>> Compress level: {}", metadata.compress_level);
|
||||||
|
// return Ok(());
|
||||||
|
// }
|
||||||
|
// zspatch(filename, dest_dir).await
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user