diff --git a/crates/radicle-fetch/src/stage.rs b/crates/radicle-fetch/src/stage.rs index 112bacbc..337d2072 100644 --- a/crates/radicle-fetch/src/stage.rs +++ b/crates/radicle-fetch/src/stage.rs @@ -517,7 +517,7 @@ impl ProtocolStage for DataRefs { for (remote, loaded) in &self.remotes { wants_haves.add( refdb, - loaded.refs.iter().filter_map(|(refname, tip)| { + loaded.refs().iter().filter_map(|(refname, tip)| { let refname = Qualified::from_refstr(refname) .map(|refname| refname.with_namespace(Component::from(remote)))?; Some((refname, *tip)) @@ -537,7 +537,7 @@ impl ProtocolStage for DataRefs { let mut updates = Updates::default(); for (remote, refs) in &self.remotes { - let mut signed = HashSet::with_capacity(refs.refs.len()); + let mut signed = HashSet::with_capacity(refs.refs().len()); for (name, tip) in refs.iter() { let tracking: Namespaced<'_> = Qualified::from_refstr(name) .and_then(|q| refs::ReceivedRefname::remote(*remote, q).to_namespaced()) diff --git a/crates/radicle-fetch/src/state.rs b/crates/radicle-fetch/src/state.rs index 9ca07c70..bc2367e7 100644 --- a/crates/radicle-fetch/src/state.rs +++ b/crates/radicle-fetch/src/state.rs @@ -733,7 +733,7 @@ where let mut has_sigrefs = false; // Check all repository references, making sure they are present in the signed refs map. - for (refname, oid) in self.state.refs.references_of(&remote.id) { + for (refname, oid) in self.state.refs.references_of(&remote.id()) { // Skip validation of the signed refs branch, as it is not part of `Remote`. if refname == storage::refs::SIGREFS_BRANCH.to_ref_string() { has_sigrefs = true; @@ -753,7 +753,7 @@ where } if !has_sigrefs { - validations.push(Validation::MissingRadSigRefs(remote.id)); + validations.push(Validation::MissingRadSigRefs(remote.id())); } // The refs that are left in the map, are ones that were signed, but are not @@ -761,7 +761,7 @@ where for (name, _) in signed.into_iter() { validations.push(Validation::MissingRef { refname: name, - remote: remote.id, + remote: remote.id(), }); } diff --git a/crates/radicle/src/storage.rs b/crates/radicle/src/storage.rs index e1836c83..22e47be1 100644 --- a/crates/radicle/src/storage.rs +++ b/crates/radicle/src/storage.rs @@ -384,7 +384,7 @@ impl Remote { } pub fn to_refspecs(&self) -> Vec> { - let ns = self.id.to_namespace(); + let ns = self.id().to_namespace(); // Nb. the references in Refs are expected to be Qualified self.refs .keys() diff --git a/crates/radicle/src/storage/git.rs b/crates/radicle/src/storage/git.rs index 2b0c5582..7809fb15 100644 --- a/crates/radicle/src/storage/git.rs +++ b/crates/radicle/src/storage/git.rs @@ -639,7 +639,7 @@ impl ValidateRepository for Repository { let mut has_sigrefs = false; // Check all repository references, making sure they are present in the signed refs map. - for (refname, oid) in self.references_of(&remote.id)? { + for (refname, oid) in self.references_of(&remote.id())? { // Skip validation of the signed refs branch, as it is not part of `Remote`. if refname == refs::SIGREFS_BRANCH.to_ref_string() { has_sigrefs = true; @@ -659,7 +659,7 @@ impl ValidateRepository for Repository { } if !has_sigrefs { - failures.push(Validation::MissingRadSigRefs(remote.id)); + failures.push(Validation::MissingRadSigRefs(remote.id())); } // The refs that are left in the map, are ones that were signed, but are not @@ -667,7 +667,7 @@ impl ValidateRepository for Repository { if let Some((name, _)) = signed.into_iter().next() { failures.push(Validation::MissingRef { refname: name, - remote: remote.id, + remote: remote.id(), }); } diff --git a/crates/radicle/src/storage/refs.rs b/crates/radicle/src/storage/refs.rs index f42c2fb2..e60c9e45 100644 --- a/crates/radicle/src/storage/refs.rs +++ b/crates/radicle/src/storage/refs.rs @@ -12,6 +12,7 @@ use std::str::FromStr; use crypto::signature::Signer; use crypto::{PublicKey, Signature, Unverified, Verified}; +use radicle_core::NodeId; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -112,7 +113,7 @@ impl Refs { } /// Create refs from a canonical representation. - pub fn from_canonical(bytes: &[u8]) -> Result { + fn from_canonical(bytes: &[u8]) -> Result { let reader = BufReader::new(bytes); let mut refs = BTreeMap::new(); @@ -133,7 +134,7 @@ impl Refs { Ok(Self(refs)) } - pub fn canonical(&self) -> Vec { + fn canonical(&self) -> Vec { let mut buf = String::new(); for (name, oid) in self.iter() { @@ -196,12 +197,12 @@ impl DerefMut for Refs { #[derive(Debug, Clone, PartialEq, Eq, Serialize)] pub struct SignedRefs { /// The signed refs. - pub refs: Refs, + refs: Refs, /// The signature of the signer over the refs. #[serde(skip)] - pub signature: Signature, + signature: Signature, /// This is the remote under which these refs exist, and the public key of the signer. - pub id: PublicKey, + id: PublicKey, #[serde(skip)] _verified: PhantomData, @@ -263,6 +264,16 @@ impl SignedRefs { } impl SignedRefs { + /// Returns the [`NodeId`] of the [`SignedRefs`]. + pub fn id(&self) -> NodeId { + self.id + } + + /// Returns the [`Refs`] of the [`SignedRefs`]. + pub fn refs(&self) -> &Refs { + &self.refs + } + pub fn load(remote: RemoteId, repo: &S) -> Result where S: ReadRepository, diff --git a/crates/radicle/src/test/storage.rs b/crates/radicle/src/test/storage.rs index 36454800..69d19f51 100644 --- a/crates/radicle/src/test/storage.rs +++ b/crates/radicle/src/test/storage.rs @@ -182,7 +182,7 @@ impl RemoteRepository for MockRepository { .remotes .values() .map(|s| refs::RefsAt { - remote: s.id, + remote: s.id(), at: s.at, }) .collect()) @@ -232,7 +232,7 @@ impl ReadRepository for MockRepository { Ok(self .remotes .values() - .any(|sigrefs| sigrefs.at == oid || sigrefs.refs.values().any(|oid_| *oid_ == oid))) + .any(|sigrefs| sigrefs.at == oid || sigrefs.values().any(|oid_| *oid_ == oid))) } fn is_ancestor_of(&self, _ancestor: Oid, _head: Oid) -> Result {