1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::io;
use std::path::{Path, PathBuf};

use error_chain::error_chain;
use user_error::UFE;
//use thiserror::Error;

error_chain! {
    types {
        Error, ErrorKind, ResultExt;
    }
    
    foreign_links {
        Io(io::Error);
        Ser(toml::ser::Error);
        Deser(toml::de::Error);
    }
    
    errors {
        KeyInvalid {
            description("Key length invalid"),
        }
        
        KeyMismatch {
            description("Public and secret keys do not match"),
        }
        
        NonceInvalid {
            description("Invalid nonce length"),
        }
        
        PassphraseIncorrect {
            description("Incorrect passphrase"),
        }
        
        PassphraseMismatch {
            description("Passphrases did not match"),
        }
        
        Path(path: PathBuf) {
            display("{}: ", path.display()),
        }
    }
    
    skip_msg_variant
}

impl UFE for Error {}

// Allow .chain_err(|| path )
impl From<&Path> for ErrorKind {
    fn from(path: &Path) -> ErrorKind {
        ErrorKind::Path(path.to_path_buf())
    }
}

impl From<&PathBuf> for ErrorKind {
    fn from(path: &PathBuf) -> ErrorKind {
        ErrorKind::Path(path.clone())
    }
}