Skip to content

Commit 9b564ac

Browse files
Merge branch 'impls-patch' into external-prover
2 parents 413bea8 + 34ede78 commit 9b564ac

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ dag_cbor = ["serde_cbor", "serde_cbor/tags"]
1616
multibase = { version = "1.0", git = "https://github.com/cryptidtech/rust-multibase.git" }
1717
multicodec = { version = "1.0", git = "https://github.com/cryptidtech/rust-multicodec.git" }
1818
multihash = { version = "1.0", git = "https://github.com/cryptidtech/multihash.git" }
19-
multikey = { version = "1.0", git = "https://github.com/DougAnderson444/multikey.git" }
20-
multisig = { version = "1.0", git = "https://github.com/DougAnderson444/multisig.git" }
19+
multikey = { version = "1.0", git = "https://github.com/cryptidtech/multikey.git" }
20+
multisig = { version = "1.0", git = "https://github.com/cryptidtech/multisig.git" }
2121
multitrait = { version = "1.0", git = "https://github.com/cryptidtech/multitrait.git" }
2222
multiutil = { version = "1.0", git = "https://github.com/cryptidtech/multiutil.git" }
2323
rand = "0.8"

src/cid.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ impl fmt::Debug for Cid {
156156
}
157157
}
158158

159+
impl fmt::Display for Cid {
160+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
161+
let encoded = EncodedCid::new(self.encoding(), self.clone());
162+
write!(f, "{}", encoded)
163+
}
164+
}
165+
159166
/// Hash builder that takes the codec and the data and produces a Multihash
160167
#[derive(Clone, Debug, Default)]
161168
pub struct Builder {
@@ -210,8 +217,7 @@ impl Builder {
210217
return Err(CidError::LegacyCid.into());
211218
}
212219
Ok(EncodedCid::new(
213-
self.base_encoding
214-
.unwrap_or_else(Cid::preferred_encoding),
220+
self.base_encoding.unwrap_or_else(Cid::preferred_encoding),
215221
self.try_build()?,
216222
))
217223
}
@@ -275,17 +281,23 @@ mod tests {
275281
assert_eq!(Codec::Sha2256, v0_1.hash.codec());
276282

277283
// this does not assume a multibase encoded CID
278-
let v0_2 = EncodedCid::try_from("bafybeihcrr5owouhnms63areolshu2lp4jjbjqlhf4exegk7tnso5ja6py").unwrap();
284+
let v0_2 =
285+
EncodedCid::try_from("bafybeihcrr5owouhnms63areolshu2lp4jjbjqlhf4exegk7tnso5ja6py")
286+
.unwrap();
279287
assert_eq!(Codec::Cidv1, v0_2.codec());
280288
assert_eq!(Codec::DagPb, v0_2.target_codec);
281289
assert_eq!(Codec::Sha2256, v0_2.hash.codec());
282290

283-
let v0_3 = EncodedCid::try_from("f01701220e28c7aeb3a876b25ed822472e47a696fe25214c1672f0972195f9b64eea41e7e").unwrap();
291+
let v0_3 = EncodedCid::try_from(
292+
"f01701220e28c7aeb3a876b25ed822472e47a696fe25214c1672f0972195f9b64eea41e7e",
293+
)
294+
.unwrap();
284295
assert_eq!(Codec::Cidv1, v0_3.codec());
285296
assert_eq!(Codec::DagPb, v0_3.target_codec);
286297
assert_eq!(Codec::Sha2256, v0_3.hash.codec());
287298

288-
let v0_4 = EncodedCid::try_from("uAXASIOKMeus6h2sl7YIkcuR6aW_iUhTBZy8Jchlfm2TupB5-").unwrap();
299+
let v0_4 =
300+
EncodedCid::try_from("uAXASIOKMeus6h2sl7YIkcuR6aW_iUhTBZy8Jchlfm2TupB5-").unwrap();
289301
assert_eq!(Codec::Cidv1, v0_4.codec());
290302
assert_eq!(Codec::DagPb, v0_4.target_codec);
291303
assert_eq!(Codec::Sha2256, v0_4.hash.codec());
@@ -392,4 +404,20 @@ mod tests {
392404
assert!(cid1 != cid2);
393405
assert!(!cid2.is_null());
394406
}
407+
408+
#[test]
409+
fn test_string_roundtrip() {
410+
let v1 = Builder::new(Codec::Cidv1)
411+
.with_target_codec(Codec::DagCbor)
412+
.with_hash(
413+
&mh::Builder::new_from_bytes(Codec::Sha3512, b"for great justice, move every zig!")
414+
.unwrap()
415+
.try_build()
416+
.unwrap(),
417+
)
418+
.try_build()
419+
.unwrap();
420+
let s = v1.to_string();
421+
assert_eq!(s, EncodedCid::try_from(s.as_str()).unwrap().to_string());
422+
}
395423
}

src/vlad.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ impl Vlad {
5252
vv.verify(&ms, Some(&cidv))?;
5353
Ok(())
5454
}
55+
56+
/// Return the Vlad's [Cid].
57+
/// This is the content address of the verification function.
58+
/// It should match the `vlad/cid` field in a Provenance Log's first Entry.
59+
pub fn cid(&self) -> &Cid {
60+
&self.cid
61+
}
5562
}
5663

5764
impl CodecInfo for Vlad {

0 commit comments

Comments
 (0)