Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 3 additions & 127 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 0 additions & 13 deletions ci/twigpine-core-allowed-deps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ cid
cipher
const-oid
const-str
core2
cpufeatures
crypto-common
crypto_box
Expand All @@ -55,31 +54,24 @@ der
digest
ed25519
ed25519-dalek
equivalent
fastcdc
generic-array
getrandom
hashbrown
hex
iana-time-zone
indexmap
inout
itoa
libc
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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion crates/twigpine-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
14 changes: 9 additions & 5 deletions crates/twigpine-core/src/cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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`).
Expand Down Expand Up @@ -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'
Expand Down