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
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright 2020 Modio AB

//! A crate named caramel-client. The crate provides library API used to implement a Caramel Client in Rust.
//!
//! See [Caramel Client project](https://gitlab.com/ModioAB/caramel-client-rs) on GitLab for more information.

pub mod certs;
pub mod network;

#[derive(thiserror::Error, Debug, PartialEq)]
/// Enum `CcError` used for library error replies.
pub enum CcError {
    // certs.rs errors
    #[error("Unable to parse private key")]
    PrivateKeyParseFailure,

    #[error(
        "Private key is too short, {actual:} bits < {} bits threshold",
        certs::MIN_RSA_BITS
    )]
    PrivateKeyTooShort { actual: u32 },

    #[error("Could not create private RSA key")]
    PrivateKeyCreationFailure,

    #[error("CA certificate not self-signed")]
    CaCertNotSelfSigned,

    #[error("Unable to parse CA cert")]
    CaCertParseFailure,

    #[error("Certificate does not match private key")]
    CertKeyMismatch,

    #[error("Certificate signature is not valid")]
    CertSignatureInvalid,

    #[error("Certificate CommonName does not match client id")]
    CertCommonNameMismatch,

    #[error("Unable to validate certificate")]
    CertValidationFailure,

    #[error("Error while building new CSR Subject")]
    CsrBuildSubjectFailure,

    #[error("Error while building new Certificate Sign Request")]
    CsrBuildFailure,

    #[error("CSR (certificat signing request) not signed by our private key CSR")]
    CsrSignedWithWrongKey,

    #[error("CSR (certificat signing request) CommonName does not match client id")]
    CsrCommonNameMismatch,

    #[error("Unable to validate CSR (certificat signing request)")]
    CsrValidationFailure,

    // network.rs errors
    #[error("Unable to download certificate")]
    DownloadCertificateFailure,

    #[error("Error from Libcurl during network operations")]
    LibCurl,

    #[error("Unknown error happened in transfer")]
    Network,

    #[error("Server rejected our POST with reason: `{0}`")]
    NetworkPost(String),

    #[error("The certificate was not found")]
    NotFound,

    #[error("The CA certificate was not found")]
    CaNotFound,
}