Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
refactor!: remove Error::UntrustedMessage
Browse files Browse the repository at this point in the history
Replaced with `InvalidMessage` which is more appropriate.

`UntrustedMessage` was supposed to mean that the message is otherwise valid but we don't trust the key it was signed with. However, we often used this error even in cases where the message was actually invalid, for example when the proof chain was broken. Also, untrusted messages are bounced back to the sender, so receiving them is not treated as an error anyway.

BREAKING CHANGE: this affects the `Error` type which is a part of the public API.
  • Loading branch information
madadam committed Jan 13, 2021
1 parent 5520c18 commit dbcf0db
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ pub enum Error {
InvalidDestination,
#[error("Content of a received message is inconsistent.")]
InvalidMessage,
#[error("A signed message could not be trusted.")]
UntrustedMessage,
#[error("A signature share is invalid.")]
InvalidSignatureShare,
#[error("The secret key share is missing.")]
Expand Down
2 changes: 1 addition & 1 deletion src/routing/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl<'a> State<'a> {
.verify(trusted_key.map(|key| (&prefix, key)))
.and_then(|status| match (status, trusted_key) {
(VerifyStatus::Full, _) | (VerifyStatus::Unknown, None) => Ok(()),
(VerifyStatus::Unknown, Some(_)) => Err(Error::UntrustedMessage),
(VerifyStatus::Unknown, Some(_)) => Err(Error::InvalidMessage),
});

match result {
Expand Down
7 changes: 5 additions & 2 deletions src/section/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ impl Section {
/// (`elders_info`).
pub fn new(chain: SectionProofChain, elders_info: Proven<EldersInfo>) -> Result<Self, Error> {
if !chain.has_key(&elders_info.proof.public_key) {
return Err(Error::UntrustedMessage);
// TODO: consider more specific error here.
return Err(Error::InvalidMessage);
}

Ok(Self {
Expand Down Expand Up @@ -86,6 +87,8 @@ impl Section {
Ok((section, section_key_share))
}

/// Try to merge this `Section` with `other`. Returns `InvalidMessage` if `other` is invalid or
/// its chain is not compatible with the chain of `self`.
pub fn merge(&mut self, other: Self) -> Result<()> {
if !other.chain.self_verify() || !other.elders_info.verify(&other.chain) {
return Err(Error::InvalidMessage);
Expand All @@ -94,7 +97,7 @@ impl Section {
// TODO: handle forks
self.chain
.merge(other.chain)
.map_err(|_| Error::UntrustedMessage)?;
.map_err(|_| Error::InvalidMessage)?;

match cmp_section_chain_position(
&self.elders_info.proof,
Expand Down

0 comments on commit dbcf0db

Please sign in to comment.