diff --git a/Cargo.lock b/Cargo.lock index 6c30892d7..75d2dbaff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -972,12 +972,6 @@ dependencies = [ "rand 0.8.6", ] -[[package]] -name = "arrayref" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" - [[package]] name = "arrayvec" version = "0.7.6" @@ -1895,42 +1889,6 @@ dependencies = [ "wyz", ] -[[package]] -name = "blake2b_simd" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b79834656f71332577234b50bfc009996f7449e0c056884e6a02492ded0ca2f3" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - -[[package]] -name = "blake2s_simd" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee29928bad1e3f94c9d1528da29e07a1d3d04817ae8332de1e8b846c8439f4b3" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - -[[package]] -name = "blake3" -version = "1.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2468ef7d57b3fb7e16b576e8377cdbde2320c60e1491e961d11da40fc4f02a2d" -dependencies = [ - "arrayref", - "arrayvec", - "cc", - "cfg-if", - "constant_time_eq", - "cpufeatures 0.2.17", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -2120,11 +2078,10 @@ dependencies = [ [[package]] name = "cid" -version = "0.11.1" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3147d8272e8fa0ccd29ce51194dd98f79ddfb8191ba9e3409884e751798acf3a" +checksum = "21a304f95f84d169a6f31c4d0a30d784643aaa0bbc9c1e449a2c23e963ec4971" dependencies = [ - "core2", "multibase", "multihash", "unsigned-varint", @@ -2297,12 +2254,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "constant_time_eq" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" - [[package]] name = "convert_case" version = "0.10.0" @@ -2338,15 +2289,6 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "core2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" -dependencies = [ - "memchr", -] - [[package]] name = "cpufeatures" version = "0.2.17" @@ -2701,7 +2643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ab67060fc6b8ef687992d439ca0fa36e7ed17e9a0b16b25b601e8757df720de" dependencies = [ "data-encoding", - "syn 2.0.117", + "syn 1.0.109", ] [[package]] @@ -4860,49 +4802,6 @@ dependencies = [ "unsigned-varint", ] -[[package]] -name = "multihash-codetable" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67996849749d25f1da9f238e8ace2ece8f9d6bdf3f9750aaf2ae7de3a5cad8ea" -dependencies = [ - "blake2b_simd", - "blake2s_simd", - "blake3", - "core2", - "digest 0.10.7", - "multihash-derive", - "ripemd", - "sha1 0.10.6", - "sha2 0.10.9", - "sha3", - "strobe-rs", -] - -[[package]] -name = "multihash-derive" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f1b7edab35d920890b88643a765fc9bd295cf0201f4154dda231bef9b8404eb" -dependencies = [ - "core2", - "multihash", - "multihash-derive-impl", -] - -[[package]] -name = "multihash-derive-impl" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3dc7141bd06405929948754f0628d247f5ca1865be745099205e5086da957cb" -dependencies = [ - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 2.0.117", - "synstructure", -] - [[package]] name = "multistream-select" version = "0.14.0" @@ -5961,15 +5860,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "ripemd" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "rlp" version = "0.5.2" @@ -6871,19 +6761,6 @@ dependencies = [ "unicode-properties", ] -[[package]] -name = "strobe-rs" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98fe17535ea31344936cc58d29fec9b500b0452ddc4cc24c429c8a921a0e84e5" -dependencies = [ - "bitflags 1.3.2", - "byteorder", - "keccak", - "subtle", - "zeroize", -] - [[package]] name = "strsim" version = "0.11.1" @@ -7469,7 +7346,6 @@ dependencies = [ "hex", "multibase", "multihash", - "multihash-codetable", "pkcs8", "rand 0.8.6", "serde", diff --git a/Cargo.toml b/Cargo.toml index e77884863..dd914d266 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,7 +42,6 @@ hex = "0.4.3" base64 = "0.22" multibase = "0.9" multihash = { version = "0.19", features = ["std"] } -multihash-codetable = { version = "0.1", features = ["sha2"] } cid = "0.11" # logging tracing = "0.1" diff --git a/ci/twigpine-core-allowed-deps.txt b/ci/twigpine-core-allowed-deps.txt index dc0c199f4..b338fea04 100644 --- a/ci/twigpine-core-allowed-deps.txt +++ b/ci/twigpine-core-allowed-deps.txt @@ -41,7 +41,6 @@ cid cipher const-oid const-str -core2 cpufeatures crypto-common crypto_box @@ -55,14 +54,11 @@ der digest ed25519 ed25519-dalek -equivalent fastcdc generic-array getrandom -hashbrown hex iana-time-zone -indexmap inout itoa libc @@ -70,16 +66,12 @@ match-lookup memchr multibase multihash -multihash-codetable -multihash-derive -multihash-derive-impl num-traits opaque-debug pem-rfc7468 pkcs8 poly1305 ppv-lite86 -proc-macro-crate proc-macro2 quote rand @@ -95,18 +87,13 @@ signature spki subtle syn -synstructure thiserror thiserror-impl -toml_datetime -toml_edit -toml_parser typenum unicode-ident universal-hash unsigned-varint uuid -winnow zerocopy zeroize zeroize_derive diff --git a/crates/twigpine-core/Cargo.toml b/crates/twigpine-core/Cargo.toml index aebd3f53a..0e17850f9 100644 --- a/crates/twigpine-core/Cargo.toml +++ b/crates/twigpine-core/Cargo.toml @@ -18,7 +18,6 @@ hex = { workspace = true } base64 = { workspace = true } multibase = { workspace = true } multihash = { workspace = true } -multihash-codetable = { workspace = true } cid = { workspace = true } chrono = { workspace = true } uuid = { workspace = true } diff --git a/crates/twigpine-core/src/cid.rs b/crates/twigpine-core/src/cid.rs index daf58bcf0..10b5beaa0 100644 --- a/crates/twigpine-core/src/cid.rs +++ b/crates/twigpine-core/src/cid.rs @@ -9,7 +9,6 @@ //! from the raw git object bytes, not the SHA-256 hash string. use cid::CidGeneric; -use multihash_codetable::{Code, MultihashDigest}; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::fmt; @@ -30,10 +29,7 @@ impl Cid { /// This is the canonical mapping: git objects pushed to IPFS always /// produce this CID, so the content is self-verifying. pub fn from_git_object_bytes(bytes: &[u8]) -> Self { - let mh = Code::Sha2_256.digest(bytes); - // CIDv1 with raw codec - let c = CidGeneric::<64>::new_v1(RAW, mh); - Self(c.to_string()) + Self::from_sha256_bytes(&sha256_bytes(bytes)) } /// Compute a CID from an existing SHA-256 hex hash (e.g. from `git rev-parse`). @@ -127,6 +123,14 @@ mod tests { assert_eq!(c1, c2); } + #[test] + fn git_object_cid_matches_known_vector() { + assert_eq!( + Cid::from_git_object_bytes(b"blob 5\0hello").as_str(), + "bafkreiek5rheq5xykt3iruhl7shtowmphds722idztgikdfdmwirowxlma" + ); + } + #[test] fn cid_starts_with_b() { // CIDv1 base32 strings start with 'b'