pgp/
error.rs

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use std::path::PathBuf;

#[cfg(feature = "key-discovery")]
use hyper::Uri;
use native::{SecretKeyParamsBuilderError, SubkeyParamsBuilderError};
use thiserror::Error;
use tokio::task::JoinError;

/// The global `Result` alias of the library.
pub type Result<T> = std::result::Result<T, Error>;

/// The global `Error` enum of the library.
#[derive(Debug, Error)]
pub enum Error {
    #[error("cannot import armored pgp message")]
    ImportMessageFromArmorError(#[source] native::errors::Error),
    #[error("cannot decrypt pgp message")]
    DecryptMessageError(#[source] native::errors::Error),
    #[error("cannot decompress pgp message")]
    DecompressMessageError(#[source] native::errors::Error),
    #[error("cannot get pgp message content")]
    GetMessageContentError(#[source] native::errors::Error),
    #[error("cannot get empty pgp message content")]
    GetMessageContentEmptyError,
    #[error("cannot get empty pgp message")]
    GetMessageEmptyError,

    #[error("cannot find pgp secret key for signing message")]
    FindSignedSecretKeyForSigningError,
    #[error("cannot sign pgp message")]
    SignMessageError(#[source] native::errors::Error),
    #[error("cannot export signed pgp message as armored string")]
    ExportSignedMessageToArmoredBytesError(#[source] native::errors::Error),
    #[error("cannot encrypt message using pgp")]
    EncryptMessageError(#[source] native::errors::Error),
    #[error("cannot export encrypted pgp message as armored string")]
    ExportEncryptedMessageToArmorError(#[source] native::errors::Error),
    #[error("cannot compress pgp message")]
    CompressMessageError(#[source] native::errors::Error),
    #[cfg(feature = "key-discovery")]
    #[error("cannot parse body from {1}")]
    ParseBodyWithUriError(#[source] hyper::Error, Uri),
    #[cfg(feature = "key-discovery")]
    #[error("cannot get public key at {1}: {0}: {2}")]
    GetPublicKeyError(Uri, hyper::StatusCode, String),
    #[cfg(feature = "key-discovery")]
    #[error("cannot parse response from {1}")]
    FetchResponseError(#[source] hyper_util::client::legacy::Error, Uri),
    #[cfg(feature = "key-discovery")]
    #[error("cannot parse pgp public key from {1}")]
    ParsePublicKeyError(#[source] native::errors::Error, Uri),
    #[cfg(feature = "key-discovery")]
    #[error("cannot find pgp public key for email {0}")]
    FindPublicKeyError(String),
    #[error("cannot build pgp secret key params")]
    BuildSecretKeyParamsError(#[source] SecretKeyParamsBuilderError),
    #[error("cannot generate pgp secret key")]
    GenerateSecretKeyError(#[source] native::errors::Error),
    #[error("cannot sign pgp secret key")]
    SignSecretKeyError(#[source] native::errors::Error),
    #[error("cannot verify pgp secret key")]
    VerifySecretKeyError(#[source] native::errors::Error),

    #[error("cannot build pgp public subkey params")]
    BuildPublicKeyParamsError(#[source] SubkeyParamsBuilderError),
    #[error("cannot sign pgp public subkey")]
    SignPublicKeyError(#[source] native::errors::Error),
    #[error("cannot verify pgp public subkey")]
    VerifyPublicKeyError(#[source] native::errors::Error),

    #[error("cannot read armored public key at {1}")]
    ReadArmoredPublicKeyError(#[source] std::io::Error, PathBuf),
    #[error("cannot parse armored public key from {1}")]
    ParseArmoredPublicKeyError(#[source] native::errors::Error, PathBuf),

    #[error("cannot read armored secret key file {1}")]
    ReadArmoredSecretKeyFromPathError(#[source] std::io::Error, PathBuf),
    #[error("cannot parse armored secret key from {1}")]
    ParseArmoredSecretKeyFromPathError(#[source] native::errors::Error, PathBuf),
    #[error("cannot parse armored secret key from string")]
    ParseArmoredSecretKeyFromStringError(#[source] native::errors::Error),

    #[error("cannot import pgp signature from armor")]
    ReadStandaloneSignatureFromArmoredBytesError(#[source] native::errors::Error),

    #[error("cannot verify pgp signature")]
    VerifySignatureError(#[source] native::errors::Error),
    #[error("cannot parse email address {0}")]
    ParseEmailAddressError(String),
    #[cfg(feature = "key-discovery")]
    #[error("cannot create HTTP connector")]
    CreateHttpConnectorError(#[source] std::io::Error),
    #[cfg(feature = "key-discovery")]
    #[error("cannot parse url {1}")]
    ParseUrlError(#[source] url::ParseError, String),
    #[cfg(feature = "key-discovery")]
    #[error("cannot parse uri {1}")]
    ParseUriError(#[source] hyper::http::uri::InvalidUri, String),
    #[cfg(feature = "key-discovery")]
    #[error("cannot parse response")]
    ParseResponseError(#[source] hyper_util::client::legacy::Error),
    #[error("cannot parse response: too many redirect")]
    RedirectOverflowError,
    #[cfg(feature = "key-discovery")]
    #[error("cannot parse body")]
    ParseBodyError(#[source] hyper::Error),
    #[error("cannot parse certificate")]
    ParseCertError(#[source] native::errors::Error),

    #[error(transparent)]
    JoinError(#[from] JoinError),
}