From c5165ea982086e3b3e1f1aae645332ce8f43796f Mon Sep 17 00:00:00 2001 From: Imbus Date: Thu, 16 Nov 2023 10:40:49 +0100 Subject: [PATCH] Hashing and version bump for future reference --- Cargo.lock | 281 ++++++++++++++++++++++++++-------------------------- Cargo.toml | 7 +- src/main.rs | 59 +++++------ 3 files changed, 168 insertions(+), 179 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd92ecb..2266b44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,71 +3,56 @@ version = 3 [[package]] -name = "ahash" -version = "0.8.3" +name = "blake2" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "cfg-if", - "once_cell", - "version_check", + "digest", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", ] [[package]] name = "borsch-test" version = "0.1.0" dependencies = [ + "blake2", "borsh", - "hex", "lzma-rs", - "uuid", "xz2", "zstd", ] [[package]] name = "borsh" -version = "0.10.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +checksum = "bf617fabf5cdbdc92f774bfe5062d870f228b80056d41180797abf48bed4056e" dependencies = [ "borsh-derive", - "hashbrown", + "cfg_aliases", ] [[package]] name = "borsh-derive" -version = "0.10.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" +checksum = "f404657a7ea7b5249e36808dff544bc88a28f26e0ac40009f674b7a009d14be3" dependencies = [ - "borsh-derive-internal", - "borsh-schema-derive-internal", + "once_cell", "proc-macro-crate", - "proc-macro2", - "syn 1.0.109", -] - -[[package]] -name = "borsh-derive-internal" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" -dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", -] - -[[package]] -name = "borsh-schema-derive-internal" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", + "syn", + "syn_derive", ] [[package]] @@ -87,10 +72,10 @@ dependencies = [ ] [[package]] -name = "cfg-if" -version = "1.0.0" +name = "cfg_aliases" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "crc" @@ -108,30 +93,57 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cace84e55f07e7301bae1c519df89cdad8cc3cd868413d3fdbdeca9ff3db484" [[package]] -name = "getrandom" -version = "0.2.10" +name = "crypto-common" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "cfg-if", - "libc", - "wasi", + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[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 = "hashbrown" -version = "0.13.2" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" [[package]] -name = "hex" -version = "0.4.3" +name = "indexmap" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown", +] [[package]] name = "jobserver" @@ -169,6 +181,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + [[package]] name = "once_cell" version = "1.18.0" @@ -182,18 +200,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] -name = "ppv-lite86" -version = "0.2.17" +name = "proc-macro-crate" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" +dependencies = [ + "toml_edit", +] [[package]] -name = "proc-macro-crate" -version = "0.1.5" +name = "proc-macro-error" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "toml", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", ] [[package]] @@ -215,65 +250,10 @@ dependencies = [ ] [[package]] -name = "rand" -version = "0.8.5" +name = "subtle" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "serde" -version = "1.0.186" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f5db24220c009de9bd45e69fb2938f4b6d2df856aa9304ce377b3180f83b7c1" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.186" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad697f7e0b65af4983a4ce8f56ed5b357e8d3c36651bf6a7e13639c17b8e670" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.29", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" @@ -287,31 +267,46 @@ dependencies = [ ] [[package]] -name = "toml" -version = "0.5.11" +name = "syn_derive" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" dependencies = [ - "serde", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", ] +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" + +[[package]] +name = "toml_edit" +version = "0.20.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + [[package]] name = "unicode-ident" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" -[[package]] -name = "uuid" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" -dependencies = [ - "borsh", - "getrandom", - "rand", -] - [[package]] name = "version_check" version = "0.9.4" @@ -319,10 +314,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +name = "winnow" +version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +dependencies = [ + "memchr", +] [[package]] name = "xz2" @@ -335,20 +333,19 @@ dependencies = [ [[package]] name = "zstd" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c" +checksum = "bffb3309596d527cfcba7dfc6ed6052f1d39dfbd7c867aa2e865e4a449c10110" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "6.0.6" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581" +checksum = "43747c7422e2924c11144d5229878b98180ef8b06cca4ab5af37afc8a8d8ea3e" dependencies = [ - "libc", "zstd-sys", ] diff --git a/Cargo.toml b/Cargo.toml index 7e9c31e..9e6e2ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,9 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -borsh = "0.10.3" -hex = "0.4.3" +blake2 = "0.10.6" +borsh = { version = "1.2.0", features = ["derive"] } lzma-rs = "0.3.0" -uuid = { version = "1.4.1", features = ["borsh", "fast-rng", "v4"] } xz2 = "0.1.7" -zstd = "0.12.4" +zstd = "0.13.0" diff --git a/src/main.rs b/src/main.rs index 1d5544d..c8d524f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ +use blake2::Digest; use std::io::{BufReader, Read}; -use borsh::{BorshDeserialize, BorshSerialize}; +use blake2::Blake2s256; +use borsh::{to_vec, BorshDeserialize, BorshSerialize}; use xz2::bufread::XzEncoder; #[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)] @@ -13,62 +15,53 @@ struct A { x: u64, y: String, z: Test, - uuids: Vec, } #[test] fn test_simple_struct() { - // let a = A { - // x: 3301, - // y: "liber primus".to_string(), - // z: Test::A("test".to_string()), - // }; - // let encoded_a = a.try_to_vec().unwrap(); - // let decoded_a = A::try_from_slice(&encoded_a).unwrap(); - // assert_eq!(a, decoded_a); + let a = A { + x: 3301, + y: "liber primus".to_string(), + z: Test::A("test".to_string()), + }; + let encoded_a = to_vec(&a).unwrap(); + let decoded_a = A::try_from_slice(&encoded_a).unwrap(); + assert_eq!(a, decoded_a); } fn main() { - let mut uuid_vec: Vec = vec![]; - for i in 0..100 { - uuid_vec.push(uuid::Uuid::new_v4().as_u128()); - } let a = A { x: 3301, - y: "liber paasdafasdaa pastafari league cakffekokare robot The Internet is broken – and we are using it to access and distribute all of human knowledge. Data monopolies hold and enclose upon personal & public datasets, threatening universal access. To tackle this problem, between 2013 and 2015 we performed a series of design & development sprints in collaboration with researchers, librarians".to_string(), - z: Test::A("test67d8c5d9-5237 The Internet is broken – and we are using it to access and distribute all of human knowledge. Data monopolies hold and enclose upon personal & public datasets, threatening universal access. To tackle this problem, between 2013 and 2015 we performed a series of design & development sprints in collaboration with researchers, librariansThe Internet is broken – and we are using it to access and distribute all of human knowledge. Data monopolies hold and enclose upon personal & public datasets, threatening universal access. To tackle this problem, between 2013 and 2015 we performed a series of design & development sprints in collaboration with researchers, librariansiInitially available only in English, versions in other languages were quickly developed. Wikipedia's combined editions comprise more than 61 million articles, attracting around 2 billion unique device visits per month and more than 15 million edits per month (about 5.8 edits per second on average) as of July 2023.[6][7] -Wikipedia".to_string()), - uuids: uuid_vec, + y: "Justo nec ultrices dui sapien eget mi. Vestibulum sed arcu non odio euismod lacinia at. Scelerisque eleifend donec pretium vulputate sapien. Faucibus a pellentesque sit amet. Enim eu turpis egestas pretium aenean pharetra magna. Sollicitudin ac orci phasellus egestas tellus rutrum tellus. Faucibus in ornare quam viverra orci sagittis eu. Suspendisse sed nisi lacus sed viverra tellus in hac habitasse. Mauris augue neque gravida in fermentum. Quam adipiscing vitae proin sagittis nisl rhoncus mattis. Non arcu risus quis varius quam quisque. Id venenatis a condimentum vitae sapien pellentesque habitant morbi. Sapien eget mi proin sed libero. Varius vel pharetra vel turpis nunc. Duis tristique sollicitudin nibh sit amet. Elementum tempus egestas sed sed risus pretium quam.".to_string(), + z: Test::A("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.".to_string()), }; - let encoded_a = a.try_to_vec().unwrap(); + let encoded_a = to_vec(&a).unwrap(); let decoded_a = A::try_from_slice(&encoded_a).unwrap(); + assert!(a == decoded_a); // Double check let mut bufread = BufReader::new(&encoded_a[..]); let mut compressed_lzma_rs = vec![]; lzma_rs::lzma_compress(&mut bufread, &mut compressed_lzma_rs).unwrap(); - // let mut bufread = BufReader::new(&encoded_a[..]); - // let mut compressed_lzma = lzma::compress(&mut bufread, 9).unwrap(); - - let mut bufread = BufReader::new(&encoded_a[..]); + let bufread = BufReader::new(&encoded_a[..]); let mut compressed_xz = vec![]; XzEncoder::new(bufread, 9) .read_to_end(&mut compressed_xz) .unwrap(); - let mut bufread = BufReader::new(&encoded_a[..]); - let compressed_zstd = zstd::encode_all(bufread, 9).unwrap(); - - println!("{}", hex::encode(&encoded_a)); - println!(); - println!("{}", hex::encode(&compressed_lzma_rs)); - println!(); - println!("{}", hex::encode(&compressed_zstd)); - println!(); - println!("{}", hex::encode(&compressed_xz)); + let bufread = BufReader::new(&encoded_a[..]); + let compressed_zstd = zstd::encode_all(bufread, 22).unwrap(); println!("Size of encoded_a: {}", encoded_a.len()); println!("Size of compressed_lzma_rs: {}", compressed_lzma_rs.len()); println!("Size of compressed_zstd: {}", compressed_zstd.len()); println!("Size of compressed_xz: {}", compressed_xz.len()); + + let mut hasher = Blake2s256::new(); + hasher.update(&compressed_zstd); // dd7e168f2993e734772acab1fb8bdcf65b0302094350719885b6be6779e3768f + let hash = hasher.finalize(); + println!("Hash of encoded_a: {:x}", hash); + assert!( + format!("{:x}", hash) == "dd7e168f2993e734772acab1fb8bdcf65b0302094350719885b6be6779e3768f" + ); }