Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Rename CryptoError to crypto::Error

Manav Rathia455ff7bc701
diff --git a/rust/apps/cli/src/models/error.rs b/rust/apps/cli/src/models/error.rs
index 28d2e0375f..c8a1f5f291 100644
--- a/rust/apps/cli/src/models/error.rs
+++ b/rust/apps/cli/src/models/error.rs
@@ -1,5 +1,5 @@
use ente_accounts::Error as AccountsError;
-use ente_core::{auth::AuthError, crypto::CryptoError};
+use ente_core::{auth::AuthError, crypto};
use thiserror::Error;
#[derive(Error, Debug)]
@@ -51,11 +51,11 @@ pub enum Error {
Generic(String),
}
-impl From<CryptoError> for Error {
- fn from(err: CryptoError) -> Self {
+impl From<crypto::Error> for Error {
+ fn from(err: crypto::Error) -> Self {
match err {
- CryptoError::Base64Decode(source) => Error::Base64Decode(source),
- CryptoError::Io(source) => Error::Io(source),
+ crypto::Error::Base64Decode(source) => Error::Base64Decode(source),
+ crypto::Error::Io(source) => Error::Io(source),
other => Error::Crypto(other.to_string()),
}
}
diff --git a/rust/apps/ensu/src-tauri/src/commands/crypto.rs b/rust/apps/ensu/src-tauri/src/commands/crypto.rs
index 2bf7c1c83a..0c992bb18b 100644
--- a/rust/apps/ensu/src-tauri/src/commands/crypto.rs
+++ b/rust/apps/ensu/src-tauri/src/commands/crypto.rs
@@ -3,9 +3,9 @@ use serde::{Deserialize, Serialize};
use crate::commands::common::ApiError;
-impl From<crypto::CryptoError> for ApiError {
- fn from(e: crypto::CryptoError) -> Self {
- use crypto::CryptoError as E;
+impl From<crypto::Error> for ApiError {
+ fn from(e: crypto::Error) -> Self {
+ use crypto::Error as E;
let code = match &e {
E::Base64Decode(_) => "base64_decode",
diff --git a/rust/bindings/uniffi/cast/src/lib.rs b/rust/bindings/uniffi/cast/src/lib.rs
index 726ab90821..294c0e7a19 100644
--- a/rust/bindings/uniffi/cast/src/lib.rs
+++ b/rust/bindings/uniffi/cast/src/lib.rs
@@ -9,8 +9,8 @@ pub enum CastCryptoError {
Message(String),
}
-impl From<crypto::CryptoError> for CastCryptoError {
- fn from(err: crypto::CryptoError) -> Self {
+impl From<crypto::Error> for CastCryptoError {
+ fn from(err: crypto::Error) -> Self {
CastCryptoError::Message(err.to_string())
}
}
diff --git a/rust/bindings/wasm/ente-wasm/src/crypto.rs b/rust/bindings/wasm/ente-wasm/src/crypto.rs
index 11ca3463e7..a21ddd2fc9 100644
--- a/rust/bindings/wasm/ente-wasm/src/crypto.rs
+++ b/rust/bindings/wasm/ente-wasm/src/crypto.rs
@@ -26,9 +26,9 @@ impl CryptoError {
}
}
-impl From<core_crypto::CryptoError> for CryptoError {
- fn from(e: core_crypto::CryptoError) -> Self {
- use core_crypto::CryptoError as E;
+impl From<core_crypto::Error> for CryptoError {
+ fn from(e: core_crypto::Error) -> Self {
+ use core_crypto::Error as E;
let code = match &e {
E::Base64Decode(_) => "base64_decode",
@@ -450,9 +450,7 @@ pub fn crypto_derive_subkey(
) -> Result<String, CryptoError> {
let key = core_crypto::decode_b64(key_b64)?;
let context: [u8; 8] = context.as_bytes().try_into().map_err(|_| {
- core_crypto::CryptoError::InvalidKeyDerivationParams(
- "KDF context must be exactly 8 bytes".into(),
- )
+ core_crypto::Error::InvalidKeyDerivationParams("KDF context must be exactly 8 bytes".into())
})?;
let subkey = core_crypto::kdf::derive_subkey(
&core_crypto::Key::try_from_slice(&key)?,
diff --git a/rust/crates/accounts/src/error.rs b/rust/crates/accounts/src/error.rs
index 0140b5d0c5..36eb32bc02 100644
--- a/rust/crates/accounts/src/error.rs
+++ b/rust/crates/accounts/src/error.rs
@@ -1,7 +1,7 @@
//! Shared error types for account flows.
use base64::DecodeError;
-use ente_core::{auth::AuthError, crypto::CryptoError, http_legacy::Error as HttpError};
+use ente_core::{auth::AuthError, crypto, http_legacy::Error as HttpError};
use thiserror::Error;
/// Result alias for the shared account crate.
@@ -75,11 +75,11 @@ impl Error {
}
}
-impl From<CryptoError> for Error {
- fn from(err: CryptoError) -> Self {
+impl From<crypto::Error> for Error {
+ fn from(err: crypto::Error) -> Self {
match err {
- CryptoError::Base64Decode(source) => Error::Base64Decode(source),
- CryptoError::Io(source) => Error::Generic(source.to_string()),
+ crypto::Error::Base64Decode(source) => Error::Base64Decode(source),
+ crypto::Error::Io(source) => Error::Generic(source.to_string()),
other => Error::Crypto(other.to_string()),
}
}
diff --git a/rust/crates/contacts/src/error.rs b/rust/crates/contacts/src/error.rs
index 003e2374e3..2eb0688e3c 100644
--- a/rust/crates/contacts/src/error.rs
+++ b/rust/crates/contacts/src/error.rs
@@ -1,4 +1,4 @@
-use ente_core::{auth::AuthError, crypto::CryptoError, http_legacy::Error as HttpError};
+use ente_core::{auth::AuthError, crypto, http_legacy::Error as HttpError};
use thiserror::Error;
#[derive(Debug, Error)]
@@ -7,7 +7,7 @@ pub enum ContactsError {
Http(#[from] HttpError),
#[error(transparent)]
- Crypto(#[from] CryptoError),
+ Crypto(#[from] crypto::Error),
#[error(transparent)]
Auth(#[from] AuthError),
diff --git a/rust/crates/core/src/auth/api.rs b/rust/crates/core/src/auth/api.rs
index da5fb0f070..ef1b1bebce 100644
--- a/rust/crates/core/src/auth/api.rs
+++ b/rust/crates/core/src/auth/api.rs
@@ -167,7 +167,7 @@ pub fn derive_kek(
/// Generate a KEK using the current adaptive sensitive client policy.
pub fn generate_sensitive_kek(password: &str) -> Result<GeneratedKek> {
let derived = argon::derive_sensitive_key(password).map_err(|e| match e {
- crypto::CryptoError::InvalidKeyDerivationParams(_) => AuthError::Crypto(e),
+ crypto::Error::InvalidKeyDerivationParams(_) => AuthError::Crypto(e),
_ => AuthError::InsufficientMemory,
})?;
diff --git a/rust/crates/core/src/auth/types.rs b/rust/crates/core/src/auth/types.rs
index 39bca73e03..35dddb3b30 100644
--- a/rust/crates/core/src/auth/types.rs
+++ b/rust/crates/core/src/auth/types.rs
@@ -200,7 +200,7 @@ pub enum AuthError {
/// Underlying cryptographic operation failed.
#[error("Crypto error: {0}")]
- Crypto(#[from] crate::crypto::CryptoError),
+ Crypto(#[from] crate::crypto::Error),
/// Failed to decode base64 or hex data.
#[error("Decode error: {0}")]
diff --git a/rust/crates/core/src/crypto/argon.rs b/rust/crates/core/src/crypto/argon.rs
index bc3adbab3b..97743d5d8f 100644
--- a/rust/crates/core/src/crypto/argon.rs
+++ b/rust/crates/core/src/crypto/argon.rs
@@ -13,7 +13,7 @@ use std::fmt;
use argon2::{Algorithm, Argon2, Params as Argon2Params, Version};
-use crate::crypto::{CryptoError, Key, Result, Salt};
+use crate::crypto::{Error, Key, Result, Salt};
/// Argon2id cost parameters: how much memory to use and how many passes to make.
///
@@ -101,7 +101,7 @@ impl fmt::Debug for DerivedKey {
/// # Errors
///
/// Returns
-/// [`InvalidKeyDerivationParams`](CryptoError::InvalidKeyDerivationParams) if
+/// [`InvalidKeyDerivationParams`](Error::InvalidKeyDerivationParams) if
/// `params` fall below the accepted minimum or memory is not a multiple of 1024
/// bytes.
///
@@ -113,7 +113,7 @@ pub fn derive_key(password: &str, salt: &Salt, params: Params) -> Result<Key> {
fn derive_key_impl(password: &[u8], salt: &Salt, params: Params) -> Result<Key> {
if params.mem_limit < Params::MIN.mem_limit {
- return Err(CryptoError::InvalidKeyDerivationParams(format!(
+ return Err(Error::InvalidKeyDerivationParams(format!(
"Memory limit {} is below minimum {}",
params.mem_limit,
Params::MIN.mem_limit
@@ -121,14 +121,14 @@ fn derive_key_impl(password: &[u8], salt: &Salt, params: Params) -> Result<Key>
}
if !params.mem_limit.is_multiple_of(1024) {
- return Err(CryptoError::InvalidKeyDerivationParams(format!(
+ return Err(Error::InvalidKeyDerivationParams(format!(
"Memory limit {} must be a multiple of 1024 bytes",
params.mem_limit
)));
}
if params.ops_limit < Params::MIN.ops_limit {
- return Err(CryptoError::InvalidKeyDerivationParams(format!(
+ return Err(Error::InvalidKeyDerivationParams(format!(
"Operations limit {} is below minimum {}",
params.ops_limit,
Params::MIN.ops_limit
@@ -141,14 +141,14 @@ fn derive_key_impl(password: &[u8], salt: &Salt, params: Params) -> Result<Key>
let p_cost = 1; // Parallelism degree
let argon2_params = Argon2Params::new(m_cost, t_cost, p_cost, Some(Key::BYTES))
- .map_err(|e| CryptoError::InvalidKeyDerivationParams(e.to_string()))?;
+ .map_err(|e| Error::InvalidKeyDerivationParams(e.to_string()))?;
let argon2 = Argon2::new(Algorithm::Argon2id, Version::V0x13, argon2_params);
let mut key = [0u8; Key::BYTES];
argon2
.hash_password_into(password, salt.as_bytes(), &mut key)
- .map_err(CryptoError::Argon2)?;
+ .map_err(Error::Argon2)?;
Ok(Key::from_bytes(key))
}
@@ -205,7 +205,7 @@ fn derive_sensitive_adaptive(password: &[u8], salt: &Salt) -> Result<DerivedKey>
.mem_limit
.is_multiple_of(Params::MODERATE.mem_limit)
{
- return Err(CryptoError::InvalidKeyDerivationParams(format!(
+ return Err(Error::InvalidKeyDerivationParams(format!(
"Memory limit {} must be divisible by {}",
Params::SENSITIVE.mem_limit,
Params::MODERATE.mem_limit
@@ -220,11 +220,11 @@ fn derive_sensitive_adaptive(password: &[u8], salt: &Salt) -> Result<DerivedKey>
.ops_limit
.checked_mul(factor)
.ok_or_else(|| {
- CryptoError::InvalidKeyDerivationParams("Operations limit overflow".to_string())
+ Error::InvalidKeyDerivationParams("Operations limit overflow".to_string())
})?;
if u64::from(mem_limit) * u64::from(ops_limit) != desired_strength {
- return Err(CryptoError::InvalidKeyDerivationParams(format!(
+ return Err(Error::InvalidKeyDerivationParams(format!(
"Unexpected mem/ops limits: mem_limit {}, ops_limit {}",
mem_limit, ops_limit
)));
@@ -256,7 +256,7 @@ fn derive_sensitive_adaptive(password: &[u8], salt: &Salt) -> Result<DerivedKey>
};
}
- Err(last_error.unwrap_or(CryptoError::KeyDerivationFailed))
+ Err(last_error.unwrap_or(Error::KeyDerivationFailed))
}
#[cfg(test)]
@@ -433,10 +433,7 @@ mod tests {
ops_limit: Params::INTERACTIVE.ops_limit,
},
);
- assert!(matches!(
- result,
- Err(CryptoError::InvalidKeyDerivationParams(_))
- ));
+ assert!(matches!(result, Err(Error::InvalidKeyDerivationParams(_))));
}
#[test]
diff --git a/rust/crates/core/src/crypto/blob.rs b/rust/crates/core/src/crypto/blob.rs
index be76a1e388..f6927d4f2c 100644
--- a/rust/crates/core/src/crypto/blob.rs
+++ b/rust/crates/core/src/crypto/blob.rs
@@ -23,7 +23,7 @@
//! (`header β€– ciphertext`).
use super::stream::{Decryptor, Encryptor};
-use crate::crypto::{CryptoError, Header, Key, Result};
+use crate::crypto::{Error, Header, Key, Result};
/// Size of the encryption key in bytes.
pub const KEY_BYTES: usize = Key::BYTES;
@@ -88,10 +88,10 @@ pub fn encrypt(data: &[u8], key: &Key) -> Result<EncryptedBlob> {
///
/// # Errors
///
-/// Returns [`CiphertextTooShort`](CryptoError::CiphertextTooShort) if `data` is
+/// Returns [`CiphertextTooShort`](Error::CiphertextTooShort) if `data` is
/// smaller than the per-message overhead,
-/// [`StreamTruncated`](CryptoError::StreamTruncated) if the final tag is absent,
-/// or [`StreamPullFailed`](CryptoError::StreamPullFailed) if the MAC does not
+/// [`StreamTruncated`](Error::StreamTruncated) if the final tag is absent,
+/// or [`StreamPullFailed`](Error::StreamPullFailed) if the MAC does not
/// verify, which happens when the key or header is wrong or the data was
/// tampered with.
///
@@ -99,7 +99,7 @@ pub fn encrypt(data: &[u8], key: &Key) -> Result<EncryptedBlob> {
pub fn decrypt(data: &[u8], header: &Header, key: &Key) -> Result<Vec<u8>> {
let (plaintext, is_final) = decrypt_impl(data, header, key)?;
if !is_final {
- return Err(CryptoError::StreamTruncated);
+ return Err(Error::StreamTruncated);
}
Ok(plaintext)
}
@@ -118,14 +118,14 @@ pub fn decrypt(data: &[u8], header: &Header, key: &Key) -> Result<Vec<u8>> {
/// # Errors
///
/// Same as [`decrypt`], except it never returns
-/// [`StreamTruncated`](CryptoError::StreamTruncated).
+/// [`StreamTruncated`](Error::StreamTruncated).
pub fn decrypt_legacy(data: &[u8], header: &Header, key: &Key) -> Result<Vec<u8>> {
Ok(decrypt_impl(data, header, key)?.0)
}
fn decrypt_impl(data: &[u8], header: &Header, key: &Key) -> Result<(Vec<u8>, bool)> {
if data.len() < ABYTES {
- return Err(CryptoError::CiphertextTooShort {
+ return Err(Error::CiphertextTooShort {
minimum: ABYTES,
actual: data.len(),
});
@@ -159,12 +159,12 @@ pub fn encrypt_combined(data: &[u8], key: &Key) -> Result<Vec<u8>> {
///
/// # Errors
///
-/// Returns [`CiphertextTooShort`](CryptoError::CiphertextTooShort) if `data` is
+/// Returns [`CiphertextTooShort`](Error::CiphertextTooShort) if `data` is
/// too short to hold a header and one message, otherwise the same errors as
/// [`decrypt`].
pub fn decrypt_combined(data: &[u8], key: &Key) -> Result<Vec<u8>> {
if data.len() < Header::BYTES + ABYTES {
- return Err(CryptoError::CiphertextTooShort {
+ return Err(Error::CiphertextTooShort {
minimum: Header::BYTES + ABYTES,
actual: data.len(),
});
@@ -179,7 +179,7 @@ pub fn decrypt_combined(data: &[u8], key: &Key) -> Result<Vec<u8>> {
/// The inverse is [`decrypt_json`].
pub fn encrypt_json<T: serde::Serialize>(value: &T, key: &Key) -> Result<EncryptedBlob> {
let json = serde_json::to_vec(value)
- .map_err(|e| CryptoError::Json(format!("JSON serialization failed: {}", e)))?;
+ .map_err(|e| Error::Json(format!("JSON serialization failed: {}", e)))?;
encrypt(&json, key)
}
@@ -189,7 +189,7 @@ pub fn encrypt_json<T: serde::Serialize>(value: &T, key: &Key) -> Result<Encrypt
/// [`decrypt_json_combined`].
pub fn encrypt_json_combined<T: serde::Serialize>(value: &T, key: &Key) -> Result<Vec<u8>> {
let json = serde_json::to_vec(value)
- .map_err(|e| CryptoError::Json(format!("JSON serialization failed: {}", e)))?;
+ .map_err(|e| Error::Json(format!("JSON serialization failed: {}", e)))?;
encrypt_combined(&json, key)
}
@@ -199,7 +199,7 @@ pub fn encrypt_json_combined<T: serde::Serialize>(value: &T, key: &Key) -> Resul
pub fn decrypt_json<T: serde::de::DeserializeOwned>(blob: &EncryptedBlob, key: &Key) -> Result<T> {
let plaintext = blob.decrypt(key)?;
serde_json::from_slice(&plaintext)
- .map_err(|e| CryptoError::Json(format!("JSON deserialization failed: {}", e)))
+ .map_err(|e| Error::Json(format!("JSON deserialization failed: {}", e)))
}
/// Decrypt a combined buffer and deserialize its plaintext from JSON into `T`.
@@ -211,7 +211,7 @@ pub fn decrypt_json_combined<T: serde::de::DeserializeOwned>(
) -> Result<T> {
let plaintext = decrypt_combined(combined, key)?;
serde_json::from_slice(&plaintext)
- .map_err(|e| CryptoError::Json(format!("JSON deserialization failed: {}", e)))
+ .map_err(|e| Error::Json(format!("JSON deserialization failed: {}", e)))
}
#[cfg(test)]
@@ -239,7 +239,7 @@ mod tests {
assert!(matches!(
decrypt(&ciphertext, &header, &key),
- Err(CryptoError::StreamTruncated)
+ Err(Error::StreamTruncated)
));
}
@@ -294,7 +294,7 @@ mod tests {
let encrypted = encrypt(b"Secret message", &key1).unwrap();
assert!(matches!(
encrypted.decrypt(&key2),
- Err(CryptoError::StreamPullFailed)
+ Err(Error::StreamPullFailed)
));
}
@@ -349,11 +349,11 @@ mod tests {
)
.unwrap();
- // Decrypt into a mismatched type; should be CryptoError::Json
+ // Decrypt into a mismatched type; should be Error::Json
let result: std::result::Result<Different, _> = decrypt_json(&encrypted, &key);
assert!(
- matches!(result, Err(CryptoError::Json(_))),
- "Expected CryptoError::Json, got: {:?}",
+ matches!(result, Err(Error::Json(_))),
+ "Expected Error::Json, got: {:?}",
result
);
}
@@ -365,7 +365,7 @@ mod tests {
assert!(matches!(
decrypt(&[0u8; ABYTES - 1], &header, &key),
- Err(CryptoError::CiphertextTooShort { .. })
+ Err(Error::CiphertextTooShort { .. })
));
}
diff --git a/rust/crates/core/src/crypto/encoding.rs b/rust/crates/core/src/crypto/encoding.rs
index 274f499c0e..7756d5a212 100644
--- a/rust/crates/core/src/crypto/encoding.rs
+++ b/rust/crates/core/src/crypto/encoding.rs
@@ -18,7 +18,7 @@ use crate::crypto::Result;
///
/// # Errors
///
-/// Returns [`Base64Decode`](crate::crypto::CryptoError::Base64Decode) if
+/// Returns [`Base64Decode`](crate::crypto::Error::Base64Decode) if
/// `input` is not valid standard base64.
pub fn decode_b64(input: &str) -> Result<Vec<u8>> {
Ok(BASE64.decode(input)?)
@@ -60,7 +60,7 @@ pub fn encode_b64_url_safe_no_padding(input: &[u8]) -> String {
///
/// # Errors
///
-/// Returns [`Base64Decode`](crate::crypto::CryptoError::Base64Decode) if
+/// Returns [`Base64Decode`](crate::crypto::Error::Base64Decode) if
/// `input` is not valid unpadded URL-safe base64.
pub fn decode_b64_url_safe_no_padding(input: &str) -> Result<Vec<u8>> {
Ok(BASE64_URL_SAFE_NO_PAD.decode(input)?)
@@ -75,7 +75,7 @@ pub fn str_to_bin(input: &str) -> Vec<u8> {
///
/// # Errors
///
-/// Returns [`HexDecode`](crate::crypto::CryptoError::HexDecode) if `input` is
+/// Returns [`HexDecode`](crate::crypto::Error::HexDecode) if `input` is
/// not valid hexadecimal.
pub fn decode_hex(input: &str) -> Result<Vec<u8>> {
Ok(hex::decode(input)?)
@@ -91,7 +91,7 @@ pub fn encode_hex(input: &[u8]) -> String {
///
/// # Errors
///
-/// Returns [`Base64Decode`](crate::crypto::CryptoError::Base64Decode) if `b64`
+/// Returns [`Base64Decode`](crate::crypto::Error::Base64Decode) if `b64`
/// is not valid standard base64.
pub fn b64_to_hex(b64: &str) -> Result<String> {
let bytes = decode_b64(b64)?;
@@ -102,7 +102,7 @@ pub fn b64_to_hex(b64: &str) -> Result<String> {
///
/// # Errors
///
-/// Returns [`HexDecode`](crate::crypto::CryptoError::HexDecode) if `hex_str` is
+/// Returns [`HexDecode`](crate::crypto::Error::HexDecode) if `hex_str` is
/// not valid hexadecimal.
pub fn hex_to_b64(hex_str: &str) -> Result<String> {
let bytes = decode_hex(hex_str)?;
diff --git a/rust/crates/core/src/crypto/error.rs b/rust/crates/core/src/crypto/error.rs
index af66782644..a021736cd4 100644
--- a/rust/crates/core/src/crypto/error.rs
+++ b/rust/crates/core/src/crypto/error.rs
@@ -8,7 +8,7 @@ use thiserror::Error;
/// [`code`](Self::code) maps a variant to a stable string identifier that
/// bindings forward to non-Rust callers.
#[derive(Error, Debug)]
-pub enum CryptoError {
+pub enum Error {
/// Base64 decoding failed.
#[error("Base64 decode error: {0}")]
Base64Decode(#[from] base64::DecodeError),
@@ -127,43 +127,43 @@ pub enum CryptoError {
Io(#[from] std::io::Error),
}
-impl CryptoError {
+impl Error {
/// A stable, machine-readable identifier for this error, suitable for
/// programmatic matching (e.g. `"invalid_key_length"`).
pub fn code(&self) -> &'static str {
match self {
- CryptoError::Base64Decode(_) => "base64_decode",
- CryptoError::HexDecode(_) => "hex_decode",
- CryptoError::InvalidKeyLength { .. } => "invalid_key_length",
- CryptoError::InvalidNonceLength { .. } => "invalid_nonce_length",
- CryptoError::InvalidSaltLength { .. } => "invalid_salt_length",
- CryptoError::InvalidHeaderLength { .. } => "invalid_header_length",
- CryptoError::CiphertextTooShort { .. } => "ciphertext_too_short",
- CryptoError::InvalidKeyDerivationParams(_) => "invalid_kdf_params",
- CryptoError::KeyDerivationFailed => "key_derivation_failed",
- CryptoError::EncryptionFailed => "encryption_failed",
- CryptoError::DecryptionFailed => "decryption_failed",
- CryptoError::StreamInitFailed => "stream_init_failed",
- CryptoError::StreamPushFailed => "stream_push_failed",
- CryptoError::StreamPullFailed => "stream_pull_failed",
- CryptoError::StreamTruncated => "stream_truncated",
- CryptoError::StreamTrailingData => "stream_trailing_data",
- CryptoError::SealedBoxOpenFailed => "sealed_box_open_failed",
- CryptoError::InvalidPublicKey => "invalid_public_key",
- CryptoError::Json(_) => "json",
- CryptoError::Argon2(_) => "argon2",
- CryptoError::Aead => "aead",
- CryptoError::ArrayConversion => "array_conversion",
- CryptoError::Io(_) => "io",
+ Error::Base64Decode(_) => "base64_decode",
+ Error::HexDecode(_) => "hex_decode",
+ Error::InvalidKeyLength { .. } => "invalid_key_length",
+ Error::InvalidNonceLength { .. } => "invalid_nonce_length",
+ Error::InvalidSaltLength { .. } => "invalid_salt_length",
+ Error::InvalidHeaderLength { .. } => "invalid_header_length",
+ Error::CiphertextTooShort { .. } => "ciphertext_too_short",
+ Error::InvalidKeyDerivationParams(_) => "invalid_kdf_params",
+ Error::KeyDerivationFailed => "key_derivation_failed",
+ Error::EncryptionFailed => "encryption_failed",
+ Error::DecryptionFailed => "decryption_failed",
+ Error::StreamInitFailed => "stream_init_failed",
+ Error::StreamPushFailed => "stream_push_failed",
+ Error::StreamPullFailed => "stream_pull_failed",
+ Error::StreamTruncated => "stream_truncated",
+ Error::StreamTrailingData => "stream_trailing_data",
+ Error::SealedBoxOpenFailed => "sealed_box_open_failed",
+ Error::InvalidPublicKey => "invalid_public_key",
+ Error::Json(_) => "json",
+ Error::Argon2(_) => "argon2",
+ Error::Aead => "aead",
+ Error::ArrayConversion => "array_conversion",
+ Error::Io(_) => "io",
}
}
}
/// Result type for crypto operations.
-pub type Result<T> = std::result::Result<T, CryptoError>;
+pub type Result<T> = std::result::Result<T, Error>;
-impl From<std::array::TryFromSliceError> for CryptoError {
+impl From<std::array::TryFromSliceError> for Error {
fn from(_: std::array::TryFromSliceError) -> Self {
- CryptoError::ArrayConversion
+ Error::ArrayConversion
}
}
diff --git a/rust/crates/core/src/crypto/hash.rs b/rust/crates/core/src/crypto/hash.rs
index 4a9ec109f5..e441bf72de 100644
--- a/rust/crates/core/src/crypto/hash.rs
+++ b/rust/crates/core/src/crypto/hash.rs
@@ -11,7 +11,7 @@
use blake2b_simd::{Params as Blake2bParams, State as Blake2bState};
use std::io::Read;
-use crate::crypto::{CryptoError, Result};
+use crate::crypto::{Error, Result};
/// Minimum hash output length in bytes.
pub const HASH_BYTES_MIN: usize = 16;
@@ -39,7 +39,7 @@ pub const KEY_BYTES_MAX: usize = 64;
///
/// # Errors
///
-/// Returns [`InvalidKeyLength`](CryptoError::InvalidKeyLength) if `out_len` is
+/// Returns [`InvalidKeyLength`](Error::InvalidKeyLength) if `out_len` is
/// outside 16 to 64 bytes, or if a non-empty `key` is outside that range.
///
/// Produces the same digest as libsodium's `crypto_generichash`.
@@ -47,7 +47,7 @@ pub fn hash(data: &[u8], out_len: Option<usize>, key: Option<&[u8]>) -> Result<V
let out_len = out_len.unwrap_or(HASH_BYTES);
if !(HASH_BYTES_MIN..=HASH_BYTES_MAX).contains(&out_len) {
- return Err(CryptoError::InvalidKeyLength {
+ return Err(Error::InvalidKeyLength {
expected: HASH_BYTES_MAX,
actual: out_len,
});
@@ -59,7 +59,7 @@ pub fn hash(data: &[u8], out_len: Option<usize>, key: Option<&[u8]>) -> Result<V
if let Some(k) = key {
// libsodium: key must be 0 OR 16-64 bytes
if !k.is_empty() && (k.len() < KEY_BYTES_MIN || k.len() > KEY_BYTES_MAX) {
- return Err(CryptoError::InvalidKeyLength {
+ return Err(Error::InvalidKeyLength {
expected: KEY_BYTES_MAX,
actual: k.len(),
});
@@ -98,13 +98,13 @@ impl HashState {
///
/// # Errors
///
- /// Returns [`InvalidKeyLength`](CryptoError::InvalidKeyLength) if `out_len`
+ /// Returns [`InvalidKeyLength`](Error::InvalidKeyLength) if `out_len`
/// or a non-empty `key` is outside 16 to 64 bytes.
pub fn new(out_len: Option<usize>, key: Option<&[u8]>) -> Result<Self> {
let out_len = out_len.unwrap_or(HASH_BYTES);
if !(HASH_BYTES_MIN..=HASH_BYTES_MAX).contains(&out_len) {
- return Err(CryptoError::InvalidKeyLength {
+ return Err(Error::InvalidKeyLength {
expected: HASH_BYTES_MAX,
actual: out_len,
});
@@ -116,7 +116,7 @@ impl HashState {
if let Some(k) = key {
// libsodium: key must be 0 OR 16-64 bytes
if !k.is_empty() && (k.len() < KEY_BYTES_MIN || k.len() > KEY_BYTES_MAX) {
- return Err(CryptoError::InvalidKeyLength {
+ return Err(Error::InvalidKeyLength {
expected: KEY_BYTES_MAX,
actual: k.len(),
});
@@ -157,8 +157,8 @@ pub fn hash_state_new() -> Result<HashState> {
///
/// # Errors
///
-/// Returns [`InvalidKeyLength`](CryptoError::InvalidKeyLength) if `out_len` is
-/// out of range, or an [`Io`](CryptoError::Io) error if the reader fails.
+/// Returns [`InvalidKeyLength`](Error::InvalidKeyLength) if `out_len` is
+/// out of range, or an [`Io`](Error::Io) error if the reader fails.
pub fn hash_reader<R: Read>(reader: &mut R, out_len: Option<usize>) -> Result<Vec<u8>> {
let mut state = HashState::new(out_len, None)?;
let mut buffer = vec![0u8; 4096];
diff --git a/rust/crates/core/src/crypto/kdf.rs b/rust/crates/core/src/crypto/kdf.rs
index 54869649cd..c26277560d 100644
--- a/rust/crates/core/src/crypto/kdf.rs
+++ b/rust/crates/core/src/crypto/kdf.rs
@@ -53,7 +53,7 @@ pub const LOGIN_SUBKEY_CONTEXT: &[u8; CONTEXT_BYTES] = b"loginctx";
///
/// # Errors
///
-/// Returns [`InvalidKeyLength`](crate::crypto::CryptoError::InvalidKeyLength) if
+/// Returns [`InvalidKeyLength`](crate::crypto::Error::InvalidKeyLength) if
/// `subkey_len` is outside 16 to 64 bytes.
///
/// Produces the same subkey as libsodium's `crypto_kdf_derive_from_key`.
@@ -64,7 +64,7 @@ pub fn derive_subkey(
context: &[u8; CONTEXT_BYTES],
) -> Result<SecretVec> {
if !(SUBKEY_BYTES_MIN..=SUBKEY_BYTES_MAX).contains(&subkey_len) {
- return Err(crate::crypto::CryptoError::InvalidKeyLength {
+ return Err(crate::crypto::Error::InvalidKeyLength {
expected: SUBKEY_BYTES_MAX,
actual: subkey_len,
});
diff --git a/rust/crates/core/src/crypto/mod.rs b/rust/crates/core/src/crypto/mod.rs
index 3ef34c5a6c..313c2f7eef 100644
--- a/rust/crates/core/src/crypto/mod.rs
+++ b/rust/crates/core/src/crypto/mod.rs
@@ -60,6 +60,6 @@ pub use encoding::{
b64_to_hex, base642bin, decode_b64, decode_b64_url_safe_no_padding, decode_hex, encode_b64,
encode_b64_url_safe, encode_b64_url_safe_no_padding, encode_hex, hex_to_b64, str_to_bin,
};
-pub use error::{CryptoError, Result};
+pub use error::{Error, Result};
pub use secret::{SecretString, SecretVec};
pub use types::{Header, Key, Nonce, PublicKey, Salt, SecretKey, random_bytes};
diff --git a/rust/crates/core/src/crypto/sealed.rs b/rust/crates/core/src/crypto/sealed.rs
index 973ed2aabc..5fc6e5eac5 100644
--- a/rust/crates/core/src/crypto/sealed.rs
+++ b/rust/crates/core/src/crypto/sealed.rs
@@ -28,7 +28,7 @@ use xsalsa20poly1305::aead::generic_array::GenericArray;
use xsalsa20poly1305::aead::{Aead, KeyInit};
use zeroize::Zeroize;
-use crate::crypto::{CryptoError, PublicKey, Result, SecretKey};
+use crate::crypto::{Error, PublicKey, Result, SecretKey};
/// Size of a public key in bytes.
pub const PUBLIC_KEY_BYTES: usize = PublicKey::BYTES;
@@ -87,7 +87,7 @@ fn is_contributory(shared_secret: &[u8; 32]) -> bool {
///
/// # Errors
///
-/// Returns [`InvalidPublicKey`](CryptoError::InvalidPublicKey) if `recipient_pk`
+/// Returns [`InvalidPublicKey`](Error::InvalidPublicKey) if `recipient_pk`
/// is a low-order point, which would make the X25519 exchange yield an all-zero
/// shared secret and provide no security.
///
@@ -109,7 +109,7 @@ pub fn seal(plaintext: &[u8], recipient_pk: &PublicKey) -> Result<Vec<u8>> {
// SECURITY: Reject non-contributory (small-order point)
if !is_contributory(shared_secret.as_bytes()) {
ephemeral_secret_bytes.zeroize();
- return Err(CryptoError::InvalidPublicKey);
+ return Err(Error::InvalidPublicKey);
}
// Derive encryption key
@@ -125,7 +125,7 @@ pub fn seal(plaintext: &[u8], recipient_pk: &PublicKey) -> Result<Vec<u8>> {
.encrypt(GenericArray::from_slice(&nonce), plaintext)
.map_err(|_| {
box_key.zeroize();
- CryptoError::EncryptionFailed
+ Error::EncryptionFailed
})?;
// Build output: ephemeral_pk || MAC || ciphertext
@@ -148,10 +148,10 @@ pub fn seal(plaintext: &[u8], recipient_pk: &PublicKey) -> Result<Vec<u8>> {
///
/// # Errors
///
-/// Returns [`CiphertextTooShort`](CryptoError::CiphertextTooShort) if
+/// Returns [`CiphertextTooShort`](Error::CiphertextTooShort) if
/// `ciphertext` is smaller than [`SEAL_OVERHEAD`],
-/// [`InvalidPublicKey`](CryptoError::InvalidPublicKey) if the embedded ephemeral
-/// key is low-order, or [`DecryptionFailed`](CryptoError::DecryptionFailed) if
+/// [`InvalidPublicKey`](Error::InvalidPublicKey) if the embedded ephemeral
+/// key is low-order, or [`DecryptionFailed`](Error::DecryptionFailed) if
/// the MAC does not verify, which happens with the wrong key pair or tampering.
///
/// Wire-compatible with libsodium's `crypto_box_seal_open`.
@@ -161,7 +161,7 @@ pub fn open(
recipient_sk: &SecretKey,
) -> Result<Vec<u8>> {
if ciphertext.len() < SEAL_OVERHEAD {
- return Err(CryptoError::CiphertextTooShort {
+ return Err(Error::CiphertextTooShort {
minimum: SEAL_OVERHEAD,
actual: ciphertext.len(),
});
@@ -170,7 +170,7 @@ pub fn open(
// Parse: ephemeral_pk (32) || MAC (16) || ciphertext
let ephemeral_pk_bytes: [u8; 32] = ciphertext[..32]
.try_into()
- .map_err(|_| CryptoError::ArrayConversion)?;
+ .map_err(|_| Error::ArrayConversion)?;
let encrypted = &ciphertext[32..]; // MAC || ciphertext
let ephemeral_pk = x25519_dalek::PublicKey::from(ephemeral_pk_bytes);
@@ -182,7 +182,7 @@ pub fn open(
// SECURITY: Reject non-contributory (small-order point)
if !is_contributory(shared_secret.as_bytes()) {
- return Err(CryptoError::InvalidPublicKey);
+ return Err(Error::InvalidPublicKey);
}
// Derive encryption key
@@ -197,7 +197,7 @@ pub fn open(
.decrypt(GenericArray::from_slice(&nonce), encrypted)
.map_err(|_| {
box_key.zeroize();
- CryptoError::DecryptionFailed
+ Error::DecryptionFailed
})?;
box_key.zeroize();
Ok(plaintext)
@@ -316,10 +316,7 @@ mod tests {
let bad_ciphertext = vec![0u8; 40]; // Less than SEAL_OVERHEAD
let result = open(&bad_ciphertext, &pk, &sk);
- assert!(matches!(
- result,
- Err(CryptoError::CiphertextTooShort { .. })
- ));
+ assert!(matches!(result, Err(Error::CiphertextTooShort { .. })));
}
#[test]
@@ -352,7 +349,7 @@ mod tests {
let zero_pk = PublicKey::from_bytes([0u8; 32]);
let result = seal(b"test", &zero_pk);
assert!(
- matches!(result, Err(CryptoError::InvalidPublicKey)),
+ matches!(result, Err(Error::InvalidPublicKey)),
"seal() should reject small-order public key, got: {:?}",
result
);
@@ -373,7 +370,7 @@ mod tests {
let result = open(&fake_ciphertext, &pk, &sk);
assert!(
- matches!(result, Err(CryptoError::InvalidPublicKey)),
+ matches!(result, Err(Error::InvalidPublicKey)),
"open() should reject small-order ephemeral key, got: {:?}",
result
);
diff --git a/rust/crates/core/src/crypto/secretbox.rs b/rust/crates/core/src/crypto/secretbox.rs
index 76525781e9..dd10d99acb 100644
--- a/rust/crates/core/src/crypto/secretbox.rs
+++ b/rust/crates/core/src/crypto/secretbox.rs
@@ -26,7 +26,7 @@ use xsalsa20poly1305::XSalsa20Poly1305;
use xsalsa20poly1305::aead::generic_array::GenericArray;
use xsalsa20poly1305::aead::{Aead, KeyInit};
-use crate::crypto::{CryptoError, Key, Nonce, Result};
+use crate::crypto::{Error, Key, Nonce, Result};
/// Size in bytes of the Poly1305 authentication tag that prefixes every
/// ciphertext.
@@ -97,15 +97,15 @@ fn encrypt_with_nonce(data: &[u8], nonce: &Nonce, key: &Key) -> Vec<u8> {
///
/// # Errors
///
-/// Returns [`CiphertextTooShort`](CryptoError::CiphertextTooShort) if `data` is
-/// smaller than the tag, or [`DecryptionFailed`](CryptoError::DecryptionFailed)
+/// Returns [`CiphertextTooShort`](Error::CiphertextTooShort) if `data` is
+/// smaller than the tag, or [`DecryptionFailed`](Error::DecryptionFailed)
/// if the tag does not verify, which is the case whenever the key, nonce, or
/// ciphertext is wrong or the data was tampered with.
///
/// Wire-compatible with libsodium's `crypto_secretbox_open_easy`.
pub fn decrypt(data: &[u8], nonce: &Nonce, key: &Key) -> Result<Vec<u8>> {
if data.len() < MAC_BYTES {
- return Err(CryptoError::CiphertextTooShort {
+ return Err(Error::CiphertextTooShort {
minimum: MAC_BYTES,
actual: data.len(),
});
@@ -116,7 +116,7 @@ pub fn decrypt(data: &[u8], nonce: &Nonce, key: &Key) -> Result<Vec<u8>> {
cipher
.decrypt(nonce_ga, data)
- .map_err(|_| CryptoError::DecryptionFailed)
+ .map_err(|_| Error::DecryptionFailed)
}
/// Encrypt `data` with `key` into one self-contained buffer.
@@ -147,14 +147,14 @@ pub fn encrypt_combined(data: &[u8], key: &Key) -> Vec<u8> {
///
/// # Errors
///
-/// Returns [`CiphertextTooShort`](CryptoError::CiphertextTooShort) if `data` is
+/// Returns [`CiphertextTooShort`](Error::CiphertextTooShort) if `data` is
/// too short to hold a nonce and tag, otherwise the same errors as [`decrypt`].
///
/// The body is wire-compatible with libsodium's `crypto_secretbox_open_easy`;
/// the leading nonce is an Ente convention.
pub fn decrypt_combined(data: &[u8], key: &Key) -> Result<Vec<u8>> {
if data.len() < Nonce::BYTES + MAC_BYTES {
- return Err(CryptoError::CiphertextTooShort {
+ return Err(Error::CiphertextTooShort {
minimum: Nonce::BYTES + MAC_BYTES,
actual: data.len(),
});
@@ -254,7 +254,7 @@ mod tests {
assert!(matches!(
encrypted.decrypt(&key),
- Err(CryptoError::DecryptionFailed)
+ Err(Error::DecryptionFailed)
));
}
@@ -264,11 +264,11 @@ mod tests {
assert!(matches!(
decrypt(&[0u8; 10], &Nonce::generate(), &key),
- Err(CryptoError::CiphertextTooShort { .. })
+ Err(Error::CiphertextTooShort { .. })
));
assert!(matches!(
decrypt_combined(&[0u8; 30], &key),
- Err(CryptoError::CiphertextTooShort { .. })
+ Err(Error::CiphertextTooShort { .. })
));
}
diff --git a/rust/crates/core/src/crypto/stream.rs b/rust/crates/core/src/crypto/stream.rs
index b6ae3a8727..826a01dc9b 100644
--- a/rust/crates/core/src/crypto/stream.rs
+++ b/rust/crates/core/src/crypto/stream.rs
@@ -28,7 +28,7 @@ use crypto_secretstream::{
use rand_core::OsRng;
use std::io::{Read, Write};
-use crate::crypto::{CryptoError, Header, Key, Result};
+use crate::crypto::{Error, Header, Key, Result};
// The typed Key/Header sizes must match the upstream secretstream sizes; the
// conversions below rely on it.
@@ -95,7 +95,7 @@ impl Encryptor {
let tag = if is_final { Tag::Final } else { Tag::Message };
self.stream
.push(buffer, &[], tag)
- .map_err(|_| CryptoError::StreamPushFailed)
+ .map_err(|_| Error::StreamPushFailed)
}
}
@@ -131,7 +131,7 @@ impl Decryptor {
///
/// # Errors
///
- /// Returns [`StreamPullFailed`](CryptoError::StreamPullFailed) if the chunk
+ /// Returns [`StreamPullFailed`](Error::StreamPullFailed) if the chunk
/// is shorter than the per-message overhead or its MAC does not verify.
pub fn pull(&mut self, data: &[u8]) -> Result<(Vec<u8>, bool)> {
let mut buffer = data.to_vec();
@@ -144,13 +144,13 @@ impl Decryptor {
/// final chunk.
fn pull_in_place(&mut self, buffer: &mut Vec<u8>) -> Result<bool> {
if buffer.len() < ABYTES {
- return Err(CryptoError::StreamPullFailed);
+ return Err(Error::StreamPullFailed);
}
let tag = self
.stream
.pull(buffer, &[])
- .map_err(|_| CryptoError::StreamPullFailed)?;
+ .map_err(|_| Error::StreamPullFailed)?;
let is_final = matches!(tag, Tag::Final);
if is_final {
@@ -167,13 +167,13 @@ impl Decryptor {
///
/// # Errors
///
- /// Returns [`StreamTruncated`](CryptoError::StreamTruncated) if no
+ /// Returns [`StreamTruncated`](Error::StreamTruncated) if no
/// final-tagged chunk was ever pulled.
pub fn finish(self) -> Result<()> {
if self.seen_final {
Ok(())
} else {
- Err(CryptoError::StreamTruncated)
+ Err(Error::StreamTruncated)
}
}
}
@@ -363,7 +363,7 @@ fn ensure_reader_exhausted<R: Read>(reader: &mut R) -> Result<()> {
loop {
match reader.read(&mut extra) {
Ok(0) => return Ok(()),
- Ok(_) => return Err(CryptoError::StreamTrailingData),
+ Ok(_) => return Err(Error::StreamTrailingData),
Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue,
Err(e) => return Err(e.into()),
}
@@ -392,10 +392,10 @@ impl<R: Read> StreamingDecryptor<R> {
///
/// # Errors
///
- /// Returns [`StreamTruncated`](CryptoError::StreamTruncated) if the stream
+ /// Returns [`StreamTruncated`](Error::StreamTruncated) if the stream
/// ends before the final tag,
- /// [`StreamTrailingData`](CryptoError::StreamTrailingData) if bytes follow
- /// the final chunk, or [`StreamPullFailed`](CryptoError::StreamPullFailed)
+ /// [`StreamTrailingData`](Error::StreamTrailingData) if bytes follow
+ /// the final chunk, or [`StreamPullFailed`](Error::StreamPullFailed)
/// if a chunk fails to decrypt.
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
// If we have buffered plaintext, return it first (O(1) via index)
@@ -444,7 +444,7 @@ impl<R: Read> StreamingDecryptor<R> {
// EOF reached - verify we saw the final tag (truncation detection)
self.buffer.clear();
if !self.seen_final {
- return Err(CryptoError::StreamTruncated);
+ return Err(Error::StreamTruncated);
}
self.finished = true;
return Ok(0);
@@ -579,11 +579,11 @@ pub fn encrypt_file<R: Read, W: Write>(
///
/// # Errors
///
-/// Returns [`StreamTruncated`](CryptoError::StreamTruncated) if EOF is reached
+/// Returns [`StreamTruncated`](Error::StreamTruncated) if EOF is reached
/// without the final tag (the truncation check), or
-/// [`StreamTrailingData`](CryptoError::StreamTrailingData) if bytes remain after
+/// [`StreamTrailingData`](Error::StreamTrailingData) if bytes remain after
/// the final chunk. A chunk that fails to decrypt yields
-/// [`StreamPullFailed`](CryptoError::StreamPullFailed).
+/// [`StreamPullFailed`](Error::StreamPullFailed).
pub fn decrypt_file<R: Read, W: Write>(
reader: &mut R,
writer: &mut W,
@@ -686,7 +686,7 @@ mod tests {
let result = decryptor.read_to_end();
assert!(
- matches!(result, Err(CryptoError::StreamTruncated)),
+ matches!(result, Err(Error::StreamTruncated)),
"Expected StreamTruncated error, got {:?}",
result
);
@@ -709,7 +709,7 @@ mod tests {
let result = decryptor.read_to_end();
assert!(
- matches!(result, Err(CryptoError::StreamTruncated)),
+ matches!(result, Err(Error::StreamTruncated)),
"Expected StreamTruncated error, got {:?}",
result
);
@@ -751,10 +751,7 @@ mod tests {
assert_eq!(pt2, b"chunk two");
assert!(!is_final1 && !is_final2);
- assert!(matches!(
- decryptor.finish(),
- Err(CryptoError::StreamTruncated)
- ));
+ assert!(matches!(decryptor.finish(), Err(Error::StreamTruncated)));
}
#[test]
@@ -1021,7 +1018,7 @@ mod tests {
let result = decryptor.pull(&ciphertext);
assert!(
- matches!(result, Err(CryptoError::StreamPullFailed)),
+ matches!(result, Err(Error::StreamPullFailed)),
"Expected StreamPullFailed error on tampered ciphertext, got {:?}",
result
);
@@ -1044,7 +1041,7 @@ mod tests {
let result = decryptor.pull(&ciphertext);
assert!(
- matches!(result, Err(CryptoError::StreamPullFailed)),
+ matches!(result, Err(Error::StreamPullFailed)),
"Expected StreamPullFailed error on tampered header, got {:?}",
result
);
@@ -1067,7 +1064,7 @@ mod tests {
let result = decryptor.pull(&ciphertext);
assert!(
- matches!(result, Err(CryptoError::StreamPullFailed)),
+ matches!(result, Err(Error::StreamPullFailed)),
"Expected StreamPullFailed error on tampered MAC, got {:?}",
result
);
@@ -1087,7 +1084,7 @@ mod tests {
let result = decryptor.pull(&ciphertext);
assert!(
- matches!(result, Err(CryptoError::StreamPullFailed)),
+ matches!(result, Err(Error::StreamPullFailed)),
"Expected StreamPullFailed error with wrong key, got {:?}",
result
);
@@ -1139,7 +1136,7 @@ mod tests {
let result = decryptor.pull(&[0u8; ABYTES - 1]);
assert!(
- matches!(result, Err(CryptoError::StreamPullFailed)),
+ matches!(result, Err(Error::StreamPullFailed)),
"Expected StreamPullFailed for short ciphertext, got {:?}",
result
);
@@ -1267,7 +1264,7 @@ mod tests {
let result = decrypt_file(&mut reader, &mut output, &header, &key);
assert!(
- matches!(result, Err(CryptoError::StreamTruncated)),
+ matches!(result, Err(Error::StreamTruncated)),
"Expected StreamTruncated for empty ciphertext, got {:?}",
result
);
@@ -1291,7 +1288,7 @@ mod tests {
let result = decrypt_file(&mut reader, &mut output, &header, &key);
assert!(
- matches!(result, Err(CryptoError::StreamTruncated)),
+ matches!(result, Err(Error::StreamTruncated)),
"Expected StreamTruncated at chunk boundary, got {:?}",
result
);
@@ -1357,7 +1354,7 @@ mod tests {
let result = decrypt_file(&mut reader, &mut output, &header, &key);
assert!(
- matches!(result, Err(CryptoError::StreamTrailingData)),
+ matches!(result, Err(Error::StreamTrailingData)),
"Expected StreamTrailingData for trailing bytes after FINAL, got {:?}",
result
);
@@ -1394,7 +1391,7 @@ mod tests {
let result = decrypt_file_data(&encrypted_chunk, &header, &key);
assert!(
- matches!(result, Err(CryptoError::StreamTruncated)),
+ matches!(result, Err(Error::StreamTruncated)),
"Expected StreamTruncated from decrypt_file_data, got {:?}",
result
);
@@ -1413,7 +1410,7 @@ mod tests {
let result = decrypt_file_data(&ciphertext, &header, &key);
assert!(
- matches!(result, Err(CryptoError::StreamTrailingData)),
+ matches!(result, Err(Error::StreamTrailingData)),
"Expected StreamTrailingData from decrypt_file_data, got {:?}",
result
);
@@ -1436,7 +1433,7 @@ mod tests {
let result = decryptor.read_to_end();
assert!(
- matches!(result, Err(CryptoError::StreamTrailingData)),
+ matches!(result, Err(Error::StreamTrailingData)),
"Expected StreamTrailingData from StreamingDecryptor, got {:?}",
result
);
diff --git a/rust/crates/core/src/crypto/types.rs b/rust/crates/core/src/crypto/types.rs
index ec10724459..0aa6ab5e7d 100644
--- a/rust/crates/core/src/crypto/types.rs
+++ b/rust/crates/core/src/crypto/types.rs
@@ -10,7 +10,7 @@ use rand_core::{OsRng, RngCore};
use subtle::ConstantTimeEq;
use zeroize::{Zeroize, ZeroizeOnDrop};
-use crate::crypto::{CryptoError, Result, SecretVec};
+use crate::crypto::{Error, Result, SecretVec};
/// A 256-bit symmetric encryption key.
///
@@ -43,7 +43,7 @@ impl Key {
/// Construct a key from a byte slice, validating its length.
pub fn try_from_slice(bytes: &[u8]) -> Result<Self> {
Ok(Self(bytes.try_into().map_err(|_| {
- CryptoError::InvalidKeyLength {
+ Error::InvalidKeyLength {
expected: Self::BYTES,
actual: bytes.len(),
}
@@ -58,7 +58,7 @@ impl Key {
/// Consumes the source, so it zeroizes on drop.
impl TryFrom<SecretVec> for Key {
- type Error = CryptoError;
+ type Error = Error;
fn try_from(secret: SecretVec) -> Result<Self> {
Self::try_from_slice(&secret)
@@ -103,7 +103,7 @@ impl Nonce {
/// Construct a nonce from a byte slice, validating its length.
pub fn try_from_slice(bytes: &[u8]) -> Result<Self> {
Ok(Self(bytes.try_into().map_err(|_| {
- CryptoError::InvalidNonceLength {
+ Error::InvalidNonceLength {
expected: Self::BYTES,
actual: bytes.len(),
}
@@ -139,7 +139,7 @@ impl Salt {
/// Construct a salt from a byte slice, validating its length.
pub fn try_from_slice(bytes: &[u8]) -> Result<Self> {
Ok(Self(bytes.try_into().map_err(|_| {
- CryptoError::InvalidSaltLength {
+ Error::InvalidSaltLength {
expected: Self::BYTES,
actual: bytes.len(),
}
@@ -167,7 +167,7 @@ impl Header {
/// Construct a header from a byte slice, validating its length.
pub fn try_from_slice(bytes: &[u8]) -> Result<Self> {
Ok(Self(bytes.try_into().map_err(|_| {
- CryptoError::InvalidHeaderLength {
+ Error::InvalidHeaderLength {
expected: Self::BYTES,
actual: bytes.len(),
}
@@ -196,7 +196,7 @@ impl PublicKey {
/// Construct a public key from a byte slice, validating its length.
pub fn try_from_slice(bytes: &[u8]) -> Result<Self> {
Ok(Self(bytes.try_into().map_err(|_| {
- CryptoError::InvalidKeyLength {
+ Error::InvalidKeyLength {
expected: Self::BYTES,
actual: bytes.len(),
}
@@ -237,7 +237,7 @@ impl SecretKey {
/// higher-entropy master secret.
pub fn from_seed(seed: &[u8]) -> Result<Self> {
Ok(Self(seed.try_into().map_err(|_| {
- CryptoError::InvalidKeyLength {
+ Error::InvalidKeyLength {
expected: Self::BYTES,
actual: seed.len(),
}
@@ -308,7 +308,7 @@ mod tests {
fn test_key_rejects_wrong_length() {
assert!(matches!(
Key::try_from_slice(&[1u8; 16]),
- Err(CryptoError::InvalidKeyLength { .. })
+ Err(Error::InvalidKeyLength { .. })
));
}
diff --git a/rust/crates/ensu/src/db/error.rs b/rust/crates/ensu/src/db/error.rs
index dc25d3617c..e8bddaaa3a 100644
--- a/rust/crates/ensu/src/db/error.rs
+++ b/rust/crates/ensu/src/db/error.rs
@@ -28,7 +28,7 @@ pub enum Error {
NotFound { entity: EntityType, id: uuid::Uuid },
#[error(transparent)]
- Crypto(#[from] ente_core::crypto::CryptoError),
+ Crypto(#[from] ente_core::crypto::Error),
#[error(transparent)]
SerdeJson(#[from] serde_json::Error),