Skip to content

Commit

Permalink
add Debug and Error impls for block-modes error types. fixes #44
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Feb 4, 2019
1 parent 80932a0 commit 1fdb4dc
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
4 changes: 2 additions & 2 deletions block-modes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "block-modes"
version = "0.3.1"
version = "0.3.2"
authors = ["RustCrypto Developers"]
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
description = "Block cipher modes of operation"
documentation = "https://docs.rs/block-modes"
repository = "https://github.com/RustCrypto/block-ciphers"
Expand Down
3 changes: 2 additions & 1 deletion block-modes/src/ecb.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use block_cipher_trait::BlockCipher;
use block_cipher_trait::generic_array::typenum::Unsigned;
use block_padding::Padding;
use traits::{BlockMode, InvalidKeyIvLength};
use traits::BlockMode;
use errors::InvalidKeyIvLength;
use utils::{Block, get_par_blocks};
use core::marker::PhantomData;

Expand Down
37 changes: 37 additions & 0 deletions block-modes/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use core::fmt;
#[cfg(feature = "std")]
use std::error;

/// Block mode error.
#[derive(Clone, Copy, Debug)]
pub struct BlockModeError;

/// Invalid key or IV length error.
#[derive(Clone, Copy, Debug)]
pub struct InvalidKeyIvLength;

impl fmt::Display for BlockModeError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str("BlockModeError")
}
}

#[cfg(feature = "std")]
impl error::Error for BlockModeError {
fn description(&self) -> &str {
"block mode error"
}
}

impl fmt::Display for InvalidKeyIvLength {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str("InvalidKeyIvLength")
}
}

#[cfg(feature = "std")]
impl error::Error for InvalidKeyIvLength {
fn description(&self) -> &str {
"invalid key or IV length during block cipher mode initialization"
}
}
4 changes: 3 additions & 1 deletion block-modes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ extern crate std;

mod utils;
mod traits;
pub use traits::{BlockMode, BlockModeError, InvalidKeyIvLength};
mod errors;
pub use traits::BlockMode;
pub use errors::{BlockModeError, InvalidKeyIvLength};

mod cbc;
pub use cbc::Cbc;
Expand Down
9 changes: 1 addition & 8 deletions block-modes/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ use block_cipher_trait::generic_array::GenericArray;
use block_cipher_trait::generic_array::typenum::Unsigned;
use block_padding::Padding;
use utils::{Block, Key, to_blocks};

/// Block mode error.
#[derive(Clone, Copy, Debug)]
pub struct BlockModeError;

/// Invalid key or IV length error.
#[derive(Clone, Copy, Debug)]
pub struct InvalidKeyIvLength;
use errors::{InvalidKeyIvLength, BlockModeError};

/// Trait for a block cipher mode of operation that is used to apply a block cipher
/// operation to input data to transform it into a variable-length output message.
Expand Down

0 comments on commit 1fdb4dc

Please sign in to comment.