diff --git a/rust/vapid/CHANGELOG.md b/rust/vapid/CHANGELOG.md index 17ae579..aa62be1 100644 --- a/rust/vapid/CHANGELOG.md +++ b/rust/vapid/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.4.0 + +* Changed `VapidErrors` to be more Clippy friendly +* updates for latest rust + + # 0.2.0 Due to changes in the OpenSSL library, several calls changed form from `0.1.0` diff --git a/rust/vapid/Cargo.toml b/rust/vapid/Cargo.toml index b002def..4ae33c7 100644 --- a/rust/vapid/Cargo.toml +++ b/rust/vapid/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vapid" -version = "0.3.0" +version = "0.4.0" authors = ["jrconlin "] edition = "2018" description = "An implementation of the RFC 8292 Voluntary Application Server Identification (VAPID) Auth header generator" @@ -11,5 +11,5 @@ license = "MPL 2.0" openssl = "0.10" serde_json = "1.0" base64 = "0.13" -time = "0.2" +time = "0.3" failure = "0.1" diff --git a/rust/vapid/src/error.rs b/rust/vapid/src/error.rs index 6fd6505..3a3cefe 100644 --- a/rust/vapid/src/error.rs +++ b/rust/vapid/src/error.rs @@ -15,11 +15,11 @@ pub struct VapidError { #[derive(Clone, Eq, PartialEq, Debug, Fail)] pub enum VapidErrorKind { #[fail(display = "Invalid public key")] - PublicKeyError, + PublicKey, #[fail(display = "VAPID error: {}", _0)] - VapidError(String), + Protocol(String), #[fail(display = "Internal Error {:?}", _0)] - InternalError(String), + Internal(String), } impl Fail for VapidError { @@ -52,6 +52,6 @@ impl From> for VapidError { impl From for VapidError { fn from(err: Error) -> VapidError { - VapidErrorKind::InternalError(format!("Error: {:?}", err)).into() + VapidErrorKind::Internal(format!("Error: {:?}", err)).into() } } diff --git a/rust/vapid/src/lib.rs b/rust/vapid/src/lib.rs index b3e3c0f..179cdb6 100644 --- a/rust/vapid/src/lib.rs +++ b/rust/vapid/src/lib.rs @@ -112,7 +112,7 @@ impl Key { let group = ec::EcGroup::from_curve_name(nid::Nid::X9_62_PRIME256V1)?; if bytes.len() != 65 || bytes[0] != 4 { // It's not a properly tagged key. - return Err(error::VapidErrorKind::PublicKeyError.into()); + return Err(error::VapidErrorKind::PublicKey.into()); } let point = ec::EcPoint::from_bytes(&group, &bytes, &mut ctx)?; Ok(ec::EcKey::from_public_key(&group, &point)?) @@ -186,14 +186,14 @@ pub fn sign( match claims.get("sub") { Some(sub) => { if !sub.as_str().unwrap().starts_with("mailto") { - return Err(error::VapidErrorKind::VapidError( + return Err(error::VapidErrorKind::Protocol( "'sub' not a valid HTML reference".to_owned(), ) .into()); } } None => { - return Err(error::VapidErrorKind::VapidError("'sub' not found".to_owned()).into()); + return Err(error::VapidErrorKind::Protocol("'sub' not found".to_owned()).into()); } } let today = SystemTime::now(); @@ -205,13 +205,13 @@ pub fn sign( Some(exp) => { let exp_val = exp.as_i64().unwrap(); if (exp_val as u64) < to_secs(today) { - return Err(error::VapidErrorKind::VapidError( + return Err(error::VapidErrorKind::Protocol( r#""exp" already expired"#.to_owned(), ) .into()); } if (exp_val as u64) > to_secs(tomorrow) { - return Err(error::VapidErrorKind::VapidError( + return Err(error::VapidErrorKind::Protocol( r#""exp" set too far ahead"#.to_owned(), ) .into()); @@ -219,7 +219,7 @@ pub fn sign( } None => { // We already do an insertion on empty, so this should never trigger. - return Err(error::VapidErrorKind::VapidError( + return Err(error::VapidErrorKind::Protocol( r#""exp" failed to initialize"#.to_owned(), ) .into()); @@ -238,7 +238,7 @@ pub fn sign( let mut signer = match Signer::new(MessageDigest::sha256(), &pub_key) { Ok(t) => t, Err(err) => { - return Err(error::VapidErrorKind::VapidError(format!( + return Err(error::VapidErrorKind::Protocol(format!( "Could not sign the claims: {:?}", err )) @@ -290,8 +290,7 @@ pub fn sign( pub fn verify(auth_token: String) -> Result, String> { //Verify that the auth token string matches for the verification token string - let auth_token = - parse_auth_token(&auth_token).expect("Authorization header is invalid."); + let auth_token = parse_auth_token(&auth_token).expect("Authorization header is invalid."); let pub_ec_key = Key::from_public_raw(auth_token.k).expect("'k' token is not a valid public key"); let pub_key = &match PKey::from_ec_key(pub_ec_key) { @@ -401,18 +400,18 @@ mod tests { assert!(result.contains(" vapid ")); // tear apart the auth token for the happy bits - let token = result.split(" ").nth(2).unwrap(); - let sub_parts: Vec<&str> = token.split(",").collect(); + let token = result.split(' ').nth(2).unwrap(); + let sub_parts: Vec<&str> = token.split(',').collect(); let mut auth_parts: HashMap = HashMap::new(); for kvi in &sub_parts { - let kv: Vec = kvi.splitn(2, "=").map(|x| String::from(x)).collect(); + let kv: Vec = kvi.splitn(2, '=').map(String::from).collect(); auth_parts.insert(kv[0].clone(), kv[1].clone()); } assert!(auth_parts.contains_key("t")); assert!(auth_parts.contains_key("k")); // now tear apart the token - let token: Vec<&str> = auth_parts.get("t").unwrap().split(".").collect(); + let token: Vec<&str> = auth_parts.get("t").unwrap().split('.').collect(); assert_eq!(token.len(), 3); let content =