bip39/
error.rs

1use crate::mnemonic_type::MnemonicType;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum ErrorKind {
6    #[error("invalid checksum")]
7    InvalidChecksum,
8    #[error("invalid word in phrase with index {0}")]
9    InvalidWord(usize),
10    #[error("invalid keysize: {0}")]
11    InvalidKeysize(usize),
12    #[error("invalid number of words in phrase: {0}")]
13    InvalidWordLength(usize),
14    #[error("invalid entropy length {0}bits for mnemonic type {1:?}")]
15    InvalidEntropyLength(usize, MnemonicType),
16}
17
18#[cfg(test)]
19mod test {
20    use super::*;
21    #[cfg(target_arch = "wasm32")]
22    use wasm_bindgen_test::*;
23
24    #[cfg_attr(all(target_arch = "wasm32"), wasm_bindgen_test)]
25    #[cfg_attr(not(target_arch = "wasm32"), test)]
26    fn prints_correctly() {
27        assert_eq!(
28            format!("{}", ErrorKind::InvalidChecksum),
29            "invalid checksum",
30        );
31        assert_eq!(
32            format!("{}", ErrorKind::InvalidKeysize(42)),
33            "invalid keysize: 42",
34        );
35        assert_eq!(
36            format!(
37                "{}",
38                ErrorKind::InvalidEntropyLength(42, MnemonicType::Words12)
39            ),
40            "invalid entropy length 42bits for mnemonic type Words12",
41        );
42    }
43}