From ab38851c3391899bb3ff0f0d88d65ef62b6d614b Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Thu, 17 Feb 2022 14:38:24 -0800 Subject: [PATCH] remove allow(dead_code) for all glory Signed-off-by: Erik Hollensbe --- src/acme/ca.rs | 1 + src/acme/handlers/account.rs | 4 ---- src/acme/handlers/mod.rs | 5 +++-- src/acme/handlers/order.rs | 4 ---- src/acme/jose.rs | 1 + src/acme/mod.rs | 3 --- src/errors/mod.rs | 15 ++++++++++++--- src/lib.rs | 1 - src/models/mod.rs | 1 + src/models/order.rs | 2 ++ src/test/mod.rs | 13 +++---------- 11 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/acme/ca.rs b/src/acme/ca.rs index 7c5b5b2..314b113 100644 --- a/src/acme/ca.rs +++ b/src/acme/ca.rs @@ -258,6 +258,7 @@ impl CACollector { } } +#[cfg(test)] mod tests { use openssl::{error::ErrorStack, x509::X509Req}; diff --git a/src/acme/handlers/account.rs b/src/acme/handlers/account.rs index 651941a..f77d1c2 100644 --- a/src/acme/handlers/account.rs +++ b/src/acme/handlers/account.rs @@ -103,10 +103,6 @@ impl NewAccount { self.contact.clone() } - pub fn is_deleted(&self) -> bool { - self.contact.is_none() || self.contact.as_ref().unwrap().is_empty() - } - pub fn to_account(&self) -> Account { Account { status: AccountStatus::Valid, diff --git a/src/acme/handlers/mod.rs b/src/acme/handlers/mod.rs index 5e943ed..e2b6ed7 100644 --- a/src/acme/handlers/mod.rs +++ b/src/acme/handlers/mod.rs @@ -27,7 +27,8 @@ pub(crate) mod directory; pub(crate) mod nonce; pub(crate) mod order; -pub(crate) const REPLAY_NONCE_HEADER: &str = "Replay-Nonce"; +const REPLAY_NONCE_HEADER: &str = "Replay-Nonce"; +const ACME_CONTENT_TYPE: &str = "application/jose+json"; /// ServiceState is the carried state globally for the application. It contains many items the /// handlers need to function. @@ -77,7 +78,7 @@ impl HandlerState { } Ok(builder - .header("content-type", "application/json") + .header("content-type", ACME_CONTENT_TYPE) .header(REPLAY_NONCE_HEADER, self.clone().nonce.unwrap()) .header( "Link", diff --git a/src/acme/handlers/order.rs b/src/acme/handlers/order.rs index 8022db4..2527e65 100644 --- a/src/acme/handlers/order.rs +++ b/src/acme/handlers/order.rs @@ -18,10 +18,6 @@ use crate::{ use super::{uri_to_url, HandlerState, ServiceState}; -pub struct OrdersList { - orders: Vec, -} - /// RFC8555 7.1.3. Detailed read. #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/src/acme/jose.rs b/src/acme/jose.rs index 5a7e989..40829b5 100644 --- a/src/acme/jose.rs +++ b/src/acme/jose.rs @@ -290,6 +290,7 @@ impl JWK { /// from_jws transforms a JSON web signature into a JWK. It uses the ACME-derived `alg` field /// from the protected header to determine what crypto to use. + #[allow(dead_code)] fn from_jws(jws: &mut JWS) -> Result { let mut aph = jws.protected()?; let alg = aph.alg.clone(); diff --git a/src/acme/mod.rs b/src/acme/mod.rs index f58486e..51fc381 100644 --- a/src/acme/mod.rs +++ b/src/acme/mod.rs @@ -29,9 +29,6 @@ use crate::{ use self::dns::DNSName; -const DEFAULT_NONCE_SIZE: usize = 16; -const ACME_CONTENT_TYPE: &str = "application/jose+json"; - lazy_static! { /// List of supported algorithms, with the ACME preferred one first; in our case this is /// "ES256". diff --git a/src/errors/mod.rs b/src/errors/mod.rs index 2620b49..1973ebd 100644 --- a/src/errors/mod.rs +++ b/src/errors/mod.rs @@ -169,7 +169,7 @@ const ACME_URN_NAMESPACE: &str = "urn:ietf:params:acme:error:"; /// RFCError is for reporting errors conformant to the ACME RFC. These are used in the `type` field /// of the "problem details" document returned to ACME clients. -#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Clone, Deserialize)] pub enum RFCError { AccountDoesNotExist, AlreadyRevoked, @@ -199,7 +199,16 @@ pub enum RFCError { impl RFCError { /// to_string converts an enum error into the string you should return to the client. - fn to_string(self) -> String { + fn serde_serialize(&self, s: S) -> Result + where + S: serde::Serializer, + { + s.serialize_str(&self.to_string()) + } +} + +impl ToString for RFCError { + fn to_string(&self) -> String { ACME_URN_NAMESPACE.to_string() + match self { RFCError::AccountDoesNotExist => "accountDoesNotExist", @@ -247,7 +256,7 @@ pub enum ValidationError { #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Error { /// the type of error we have experienced. - #[serde(rename = "type")] + #[serde(rename = "type", serialize_with = "RFCError::serde_serialize")] error_type: RFCError, /// subproblems, if any, will be here. #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/lib.rs b/src/lib.rs index 1b849fb..34c5619 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -#![allow(dead_code)] //! Coyote lets you make ACME servers, which are not guaranteed to not explode in //! your face. You have to code that out yourself. //! diff --git a/src/models/mod.rs b/src/models/mod.rs index 5759b18..9aa262e 100644 --- a/src/models/mod.rs +++ b/src/models/mod.rs @@ -78,6 +78,7 @@ impl Postgres { /// resets the database, destroying all data in the public schema. /// useful for tests. + #[cfg(test)] pub(crate) async fn reset(&self) -> Result<(), SaveError> { let c = Self::connect_one(&self.config).await?; c.execute("drop schema public cascade", &[]).await?; diff --git a/src/models/order.rs b/src/models/order.rs index 69144bf..29a0b4f 100644 --- a/src/models/order.rs +++ b/src/models/order.rs @@ -149,6 +149,8 @@ impl Order { Ok(o) } + // FIXME this is only used in tests rn + #[cfg(test)] pub(crate) async fn challenges( &self, tx: &Transaction<'_>, diff --git a/src/test/mod.rs b/src/test/mod.rs index ea0d660..00e829f 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -38,8 +38,6 @@ fn is_debug() -> bool { !std::env::var(DEBUG_VAR).unwrap_or_default().is_empty() } -pub(crate) const DEFAULT_CONTACT: &str = "erik@hollensbe.org"; - impl From for eggshell::Error { fn from(me: MigrationError) -> Self { Self::Generic(me.to_string()) @@ -53,7 +51,7 @@ pub struct PGTest { docker: Arc>, // NOTE: the only reason we keep this is to ensure it lives the same lifetime as the PGTest // struct; otherwise the temporary directory is removed prematurely. - temp: Arc>, + _temp: Arc>, } fn pull_images(images: Vec<&str>) -> () { @@ -189,7 +187,7 @@ impl PGTest { docker, gs: Arc::new(Mutex::new(gs)), postgres, - temp: Arc::new(Mutex::new(temp)), + _temp: Arc::new(Mutex::new(temp)), }) } @@ -200,11 +198,8 @@ impl PGTest { pub fn eggshell(self) -> Arc> { self.gs } - - pub fn docker(&self) -> Arc> { - self.docker.clone() - } } + #[derive(Debug, Clone, Error)] pub(crate) enum ContainerError { #[error("Unknown error encountered: {0}")] @@ -228,7 +223,6 @@ fn short_hash(s: String) -> String { #[derive(Clone)] pub(crate) struct TestService { pub pg: Box, - pub nonce: PostgresNonceValidator, pub app: ratpack::app::TestApp, pub url: String, } @@ -279,7 +273,6 @@ impl TestService { Self { pg: Box::new(pg), - nonce: validator, app: TestApp::new(app), url, }