mirror of https://github.com/breard-r/acmed.git
Browse Source
Move common items to a dedicated lib
Move common items to a dedicated lib
In a near future, ACMEd will be composed of several binaries which will use some common functions and structures.pull/5/head
Rodolphe Breard
6 years ago
24 changed files with 160 additions and 131 deletions
-
25acme_common/Cargo.toml
-
87acme_common/src/error.rs
-
0acme_common/src/gen.rs
-
6acme_common/src/lib.rs
-
2acmed/Cargo.toml
-
6acmed/src/acme_proto.rs
-
2acmed/src/acme_proto/account.rs
-
15acmed/src/acme_proto/certificate.rs
-
4acmed/src/acme_proto/http.rs
-
10acmed/src/acme_proto/jws.rs
-
7acmed/src/acme_proto/jws/algorithms.rs
-
2acmed/src/acme_proto/structs.rs
-
2acmed/src/acme_proto/structs/account.rs
-
4acmed/src/acme_proto/structs/authorization.rs
-
2acmed/src/acme_proto/structs/directory.rs
-
99acmed/src/acme_proto/structs/error.rs
-
2acmed/src/acme_proto/structs/order.rs
-
2acmed/src/certificate.rs
-
2acmed/src/config.rs
-
2acmed/src/hooks.rs
-
2acmed/src/logs.rs
-
2acmed/src/main.rs
-
2acmed/src/main_event_loop.rs
-
4acmed/src/storage.rs
@ -0,0 +1,25 @@ |
|||
[package] |
|||
name = "acme_common" |
|||
version = "0.1.0" |
|||
authors = ["Rodolphe Breard <rodolphe@what.tf>"] |
|||
edition = "2018" |
|||
repository = "https://github.com/breard-r/libreauth" |
|||
readme = "../README.md" |
|||
license = "MIT OR Apache-2.0" |
|||
include = ["src/**/*", "Cargo.toml", "Licence_*.txt"] |
|||
|
|||
[lib] |
|||
name = "acme_common" |
|||
|
|||
[dependencies] |
|||
base64 = "0.10" |
|||
handlebars = "2.0.0-beta.1" |
|||
http_req = "0.4" |
|||
openssl = "0.10" |
|||
serde = { version = "1.0", features = ["derive"] } |
|||
serde_json = "1.0" |
|||
syslog = "4.0" |
|||
toml = "0.5" |
|||
|
|||
[target.'cfg(unix)'.dependencies] |
|||
nix = "0.13" |
@ -0,0 +1,87 @@ |
|||
use std::fmt;
|
|||
|
|||
#[derive(Debug)]
|
|||
pub struct Error {
|
|||
pub message: String,
|
|||
}
|
|||
|
|||
impl fmt::Display for Error {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|||
write!(f, "{}", self.message)
|
|||
}
|
|||
}
|
|||
|
|||
impl From<&str> for Error {
|
|||
fn from(error: &str) -> Self {
|
|||
Error {
|
|||
message: error.to_string(),
|
|||
}
|
|||
}
|
|||
}
|
|||
|
|||
impl From<String> for Error {
|
|||
fn from(error: String) -> Self {
|
|||
error.as_str().into()
|
|||
}
|
|||
}
|
|||
|
|||
impl From<&String> for Error {
|
|||
fn from(error: &String) -> Self {
|
|||
error.as_str().into()
|
|||
}
|
|||
}
|
|||
|
|||
impl From<std::io::Error> for Error {
|
|||
fn from(error: std::io::Error) -> Self {
|
|||
format!("IO error: {}", error).into()
|
|||
}
|
|||
}
|
|||
|
|||
impl From<std::string::FromUtf8Error> for Error {
|
|||
fn from(error: std::string::FromUtf8Error) -> Self {
|
|||
format!("UTF-8 error: {}", error).into()
|
|||
}
|
|||
}
|
|||
|
|||
impl From<syslog::Error> for Error {
|
|||
fn from(error: syslog::Error) -> Self {
|
|||
format!("syslog error: {}", error).into()
|
|||
}
|
|||
}
|
|||
|
|||
impl From<toml::de::Error> for Error {
|
|||
fn from(error: toml::de::Error) -> Self {
|
|||
format!("IO error: {}", error).into()
|
|||
}
|
|||
}
|
|||
|
|||
impl From<serde_json::error::Error> for Error {
|
|||
fn from(error: serde_json::error::Error) -> Self {
|
|||
format!("IO error: {}", error).into()
|
|||
}
|
|||
}
|
|||
|
|||
impl From<handlebars::TemplateRenderError> for Error {
|
|||
fn from(error: handlebars::TemplateRenderError) -> Self {
|
|||
format!("Template error: {}", error).into()
|
|||
}
|
|||
}
|
|||
|
|||
impl From<openssl::error::ErrorStack> for Error {
|
|||
fn from(error: openssl::error::ErrorStack) -> Self {
|
|||
format!("{}", error).into()
|
|||
}
|
|||
}
|
|||
|
|||
impl From<http_req::error::Error> for Error {
|
|||
fn from(error: http_req::error::Error) -> Self {
|
|||
format!("HTTP error: {}", error).into()
|
|||
}
|
|||
}
|
|||
|
|||
#[cfg(unix)]
|
|||
impl From<nix::Error> for Error {
|
|||
fn from(error: nix::Error) -> Self {
|
|||
format!("{}", error).into()
|
|||
}
|
|||
}
|
@ -0,0 +1,6 @@ |
|||
pub mod error;
|
|||
pub mod gen;
|
|||
|
|||
pub fn b64_encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String {
|
|||
base64::encode_config(input, base64::URL_SAFE_NO_PAD)
|
|||
}
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue