From 44f3984159e630b3b6be1cc159c7a00b099086a6 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Mon, 6 Mar 2023 10:42:26 +0100 Subject: [PATCH] Sign COB refs after modification --- radicle-cli/src/commands/issue.rs | 2 +- radicle/src/cob/issue.rs | 4 +-- radicle/src/cob/store.rs | 41 +++++++++++++++++++------------ radicle/src/storage/git.rs | 3 ++- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/radicle-cli/src/commands/issue.rs b/radicle-cli/src/commands/issue.rs index a394ac44..57329a7c 100644 --- a/radicle-cli/src/commands/issue.rs +++ b/radicle-cli/src/commands/issue.rs @@ -302,7 +302,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { t.render(); } Operation::Delete { id } => { - issues.remove(&id)?; + issues.remove(&id, &signer)?; } } diff --git a/radicle/src/cob/issue.rs b/radicle/src/cob/issue.rs index e64be649..5df7afc4 100644 --- a/radicle/src/cob/issue.rs +++ b/radicle/src/cob/issue.rs @@ -491,8 +491,8 @@ impl<'a> Issues<'a> { } /// Remove an issue. - pub fn remove(&self, id: &ObjectId) -> Result<(), store::Error> { - self.raw.remove(id) + pub fn remove(&self, id: &ObjectId, signer: &G) -> Result<(), store::Error> { + self.raw.remove(id, signer) } } diff --git a/radicle/src/cob/store.rs b/radicle/src/cob/store.rs index 07fb2ef8..1b841483 100644 --- a/radicle/src/cob/store.rs +++ b/radicle/src/cob/store.rs @@ -84,33 +84,35 @@ pub enum Error { HistoryType(String), #[error("object `{1}` of type `{0}` was not found")] NotFound(TypeName, ObjectId), + #[error("signed refs: {0}")] + SignRefs(#[from] storage::Error), } /// Storage for collaborative objects of a specific type `T` in a single repository. pub struct Store<'a, T> { whoami: PublicKey, parent: git::Oid, - raw: &'a storage::Repository, + repo: &'a storage::Repository, witness: PhantomData, rng: StdRng, } impl<'a, T> AsRef for Store<'a, T> { fn as_ref(&self) -> &storage::Repository { - self.raw + self.repo } } impl<'a, T> Store<'a, T> { /// Open a new generic store. - pub fn open(whoami: PublicKey, store: &'a storage::Repository) -> Result { + pub fn open(whoami: PublicKey, repo: &'a storage::Repository) -> Result { let rng = rng::std(); - let identity = store.identity()?; + let identity = repo.identity()?; Ok(Self { parent: identity.current, whoami, - raw: store, + repo, witness: PhantomData, rng, }) @@ -145,9 +147,8 @@ where signer: &G, ) -> Result { let changes = actions.into(); - - cob::update( - self.raw, + let obj = cob::update( + self.repo, signer, self.parent, signer.public_key(), @@ -158,8 +159,11 @@ where message: message.to_owned(), changes, }, - ) - .map_err(Error::from) + )?; + + self.repo.sign_refs(signer).map_err(Error::SignRefs)?; + + Ok(obj) } /// Create an object. @@ -171,7 +175,7 @@ where ) -> Result<(ObjectId, T, Lamport), Error> { let contents = actions.into(); let cob = cob::create( - self.raw, + self.repo, signer, self.parent, signer.public_key(), @@ -184,12 +188,14 @@ where )?; let (object, clock) = T::from_history(cob.history())?; + self.repo.sign_refs(signer).map_err(Error::SignRefs)?; + Ok((*cob.id(), object, clock)) } /// Get an object. pub fn get(&self, id: &ObjectId) -> Result, Error> { - let cob = cob::get(self.raw, T::type_name(), id)?; + let cob = cob::get(self.repo, T::type_name(), id)?; if let Some(cob) = cob { if cob.manifest().history_type != HISTORY_TYPE { @@ -207,7 +213,7 @@ where pub fn all( &self, ) -> Result>, Error> { - let raw = cob::list(self.raw, T::type_name())?; + let raw = cob::list(self.repo, T::type_name())?; Ok(raw.into_iter().map(|o| { let (obj, clock) = T::from_history(o.history())?; @@ -217,14 +223,17 @@ where /// Return objects count. pub fn count(&self) -> Result { - let raw = cob::list(self.raw, T::type_name())?; + let raw = cob::list(self.repo, T::type_name())?; Ok(raw.len()) } /// Remove an object. - pub fn remove(&self, id: &ObjectId) -> Result<(), Error> { - cob::remove(self.raw, &self.whoami, T::type_name(), id).map_err(Error::from) + pub fn remove(&self, id: &ObjectId, signer: &G) -> Result<(), Error> { + cob::remove(self.repo, &self.whoami, T::type_name(), id)?; + self.repo.sign_refs(signer).map_err(Error::SignRefs)?; + + Ok(()) } } diff --git a/radicle/src/storage/git.rs b/radicle/src/storage/git.rs index 63274140..f5eb36f1 100644 --- a/radicle/src/storage/git.rs +++ b/radicle/src/storage/git.rs @@ -16,10 +16,11 @@ use crate::identity::{Identity, IdentityError, Project}; use crate::storage::refs; use crate::storage::refs::{Refs, SignedRefs}; use crate::storage::{ - Error, Inventory, ReadRepository, ReadStorage, Remote, Remotes, WriteRepository, WriteStorage, + Inventory, ReadRepository, ReadStorage, Remote, Remotes, WriteRepository, WriteStorage, }; pub use crate::git::*; +pub use crate::storage::Error; use super::RemoteId;