Skip to content

Commit

Permalink
Combine error variants into general decryption
Browse files Browse the repository at this point in the history
  • Loading branch information
nyonson committed Sep 25, 2024
1 parent a61c9a4 commit 24d5c18
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ pub enum Error {
SecretMaterialsGeneration(secp256k1::Error),
/// Deriving the shared secrets was unsuccessful.
SecretExpansion,
/// The authentication data was not correct when decoding a packet.
Cipher(fschacha20poly1305::Error),
/// The internal counters of the ciphers are not in sync.
OutOfSync,
/// General decryption error, channel could be out of sync.
Decryption(fschacha20poly1305::Error),
}

impl fmt::Display for Error {
Expand All @@ -114,8 +112,7 @@ impl fmt::Display for Error {
write!(f, "More than 4095 bytes of garbage in the handshake.")
}
Error::HandshakeOutOfOrder => write!(f, "Handshake flow out of sequence."),
Error::Cipher(e) => write!(f, "Cipher encryption/decrytion error: {}.", e),
Error::OutOfSync => write!(f, "Ciphers are out of sync."),
Error::Decryption(e) => write!(f, "Decrytion error: {}.", e),
Error::SecretExpansion => write!(f, "Unable to expand key."),
}
}
Expand All @@ -129,8 +126,7 @@ impl std::error::Error for Error {
Error::CiphertextTooSmall => None,
Error::MaxGarbageLength => None,
Error::HandshakeOutOfOrder => None,
Error::Cipher(e) => Some(e),
Error::OutOfSync => None,
Error::Decryption(e) => Some(e),
Error::SecretExpansion => None,
Error::BufferTooSmall { required_bytes: _ } => None,
}
Expand All @@ -145,7 +141,7 @@ impl From<secp256k1::Error> for Error {

impl From<fschacha20poly1305::Error> for Error {
fn from(e: fschacha20poly1305::Error) -> Self {
Error::Cipher(e)
Error::Decryption(e)
}
}

Expand Down

0 comments on commit 24d5c18

Please sign in to comment.