Skip to content

Commit d1cbc91

Browse files
committed
Drop all support for anyhow, migrate to thiserror 2
1 parent 1430f5c commit d1cbc91

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ crc32fast = "^1.3.2"
2222
chacha20poly1305 = "^0.10.1"
2323
secp256k1 = "^0.30.0"
2424
x25519-dalek = { version = "2.0.0-rc.2", features = ["static_secrets"] }
25-
thiserror = "^1.0.48"
26-
anyhow = "^1.0.0"
25+
thiserror = "^2.0"
2726
hex = "^0.4.3"
2827
ed25519-dalek = { version = "2.1.1", features = ["rand_core"] }
2928
scrypt = { version = "0.11.0", default-features = false }

src/error.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use chacha20poly1305::aead::Error as AeadError;
2+
use thiserror::Error;
3+
4+
#[derive(Debug, Error)]
5+
pub enum Error {
6+
#[error("AEAD error")]
7+
Aead(AeadError),
8+
}
9+
10+
impl From<AeadError> for Error {
11+
fn from(error: AeadError) -> Self {
12+
Error::Aead(error)
13+
}
14+
}
15+
16+
pub type Result<T> = std::result::Result<T, Error>;

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
//! bc-crypto = "0.9.0"
2828
//! ```
2929
30+
pub mod error;
31+
pub use error::{Error, Result};
32+
3033
/// The `hash` module contains functions for hashing data.
3134
pub mod hash;
3235
pub use hash::{

src/symmetric_encryption.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use anyhow::{anyhow, Result};
21
use chacha20poly1305::{ChaCha20Poly1305, KeyInit, AeadInPlace};
2+
use crate::Result;
33

44
pub const SYMMETRIC_KEY_SIZE: usize = 32;
55
pub const SYMMETRIC_NONCE_SIZE: usize = 12;
@@ -49,7 +49,7 @@ pub fn aead_chacha20_poly1305_decrypt_with_aad<D1, D2>(
4949
{
5050
let cipher = ChaCha20Poly1305::new(key.into());
5151
let mut buffer = ciphertext.as_ref().to_vec();
52-
cipher.decrypt_in_place_detached(nonce.into(), aad.as_ref(), &mut buffer, auth.into()).map_err(|_| anyhow!("Decrypt failed"))?;
52+
cipher.decrypt_in_place_detached(nonce.into(), aad.as_ref(), &mut buffer, auth.into())?;
5353
Ok(buffer)
5454
}
5555

0 commit comments

Comments
 (0)