caramel_client/
lib.rs

1// SPDX-License-Identifier: Apache-2.0 OR MIT
2// Copyright 2020 Modio AB
3
4//! A crate named caramel-client. The crate provides library API used to implement a Caramel Client in Rust.
5//!
6//! See [Caramel Client project](https://gitlab.com/ModioAB/caramel-client-rs) on GitLab for more information.
7
8pub mod certs;
9pub mod network;
10
11#[derive(thiserror::Error, Debug, PartialEq)]
12/// Enum `CcError` used for library error replies.
13pub enum CcError {
14    // certs.rs errors
15    #[error("Unable to parse private key")]
16    PrivateKeyParseFailure,
17
18    #[error(
19        "Private key is too short, {actual:} bits < {} bits threshold",
20        certs::MIN_RSA_BITS
21    )]
22    PrivateKeyTooShort { actual: u32 },
23
24    #[error("Could not create private RSA key")]
25    PrivateKeyCreationFailure,
26
27    #[error("CA certificate not self-signed")]
28    CaCertNotSelfSigned,
29
30    #[error("Unable to parse CA cert")]
31    CaCertParseFailure,
32
33    #[error("Certificate does not match private key")]
34    CertKeyMismatch,
35
36    #[error("Certificate signature is not valid")]
37    CertSignatureInvalid,
38
39    #[error("Certificate CommonName does not match client id")]
40    CertCommonNameMismatch,
41
42    #[error("Unable to validate certificate")]
43    CertValidationFailure,
44
45    #[error("Error while building new CSR Subject")]
46    CsrBuildSubjectFailure,
47
48    #[error("Error while building new Certificate Sign Request")]
49    CsrBuildFailure,
50
51    #[error("CSR (certificat signing request) not signed by our private key CSR")]
52    CsrSignedWithWrongKey,
53
54    #[error("CSR (certificat signing request) CommonName does not match client id")]
55    CsrCommonNameMismatch,
56
57    #[error("Unable to validate CSR (certificat signing request)")]
58    CsrValidationFailure,
59
60    // network.rs errors
61    #[error("Unable to download certificate")]
62    DownloadCertificateFailure,
63
64    #[error("Error from Libcurl during network operations")]
65    LibCurl,
66
67    #[error("Unknown error happened in transfer")]
68    Network,
69
70    #[error("Server rejected our POST with reason: `{0}`")]
71    NetworkPost(String),
72
73    #[error("The certificate was not found")]
74    NotFound,
75
76    #[error("The CA certificate was not found")]
77    CaNotFound,
78}