Skip to content

Commit a60bcc8

Browse files
authored
chore: Updates for 2021 Q3 (#98)
Closes #97
1 parent 0de9f9f commit a60bcc8

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

rust/vapid/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.4.0
2+
3+
* Changed `VapidErrors` to be more Clippy friendly
4+
* updates for latest rust
5+
6+
17
# 0.2.0
28

39
Due to changes in the OpenSSL library, several calls changed form from `0.1.0`

rust/vapid/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vapid"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors = ["jrconlin <jconlin+git@mozilla.com>"]
55
edition = "2018"
66
description = "An implementation of the RFC 8292 Voluntary Application Server Identification (VAPID) Auth header generator"
@@ -11,5 +11,5 @@ license = "MPL 2.0"
1111
openssl = "0.10"
1212
serde_json = "1.0"
1313
base64 = "0.13"
14-
time = "0.2"
14+
time = "0.3"
1515
failure = "0.1"

rust/vapid/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ pub struct VapidError {
1515
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
1616
pub enum VapidErrorKind {
1717
#[fail(display = "Invalid public key")]
18-
PublicKeyError,
18+
PublicKey,
1919
#[fail(display = "VAPID error: {}", _0)]
20-
VapidError(String),
20+
Protocol(String),
2121
#[fail(display = "Internal Error {:?}", _0)]
22-
InternalError(String),
22+
Internal(String),
2323
}
2424

2525
impl Fail for VapidError {
@@ -52,6 +52,6 @@ impl From<Context<VapidErrorKind>> for VapidError {
5252

5353
impl From<Error> for VapidError {
5454
fn from(err: Error) -> VapidError {
55-
VapidErrorKind::InternalError(format!("Error: {:?}", err)).into()
55+
VapidErrorKind::Internal(format!("Error: {:?}", err)).into()
5656
}
5757
}

rust/vapid/src/lib.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Key {
112112
let group = ec::EcGroup::from_curve_name(nid::Nid::X9_62_PRIME256V1)?;
113113
if bytes.len() != 65 || bytes[0] != 4 {
114114
// It's not a properly tagged key.
115-
return Err(error::VapidErrorKind::PublicKeyError.into());
115+
return Err(error::VapidErrorKind::PublicKey.into());
116116
}
117117
let point = ec::EcPoint::from_bytes(&group, &bytes, &mut ctx)?;
118118
Ok(ec::EcKey::from_public_key(&group, &point)?)
@@ -186,14 +186,14 @@ pub fn sign<S: BuildHasher>(
186186
match claims.get("sub") {
187187
Some(sub) => {
188188
if !sub.as_str().unwrap().starts_with("mailto") {
189-
return Err(error::VapidErrorKind::VapidError(
189+
return Err(error::VapidErrorKind::Protocol(
190190
"'sub' not a valid HTML reference".to_owned(),
191191
)
192192
.into());
193193
}
194194
}
195195
None => {
196-
return Err(error::VapidErrorKind::VapidError("'sub' not found".to_owned()).into());
196+
return Err(error::VapidErrorKind::Protocol("'sub' not found".to_owned()).into());
197197
}
198198
}
199199
let today = SystemTime::now();
@@ -205,21 +205,21 @@ pub fn sign<S: BuildHasher>(
205205
Some(exp) => {
206206
let exp_val = exp.as_i64().unwrap();
207207
if (exp_val as u64) < to_secs(today) {
208-
return Err(error::VapidErrorKind::VapidError(
208+
return Err(error::VapidErrorKind::Protocol(
209209
r#""exp" already expired"#.to_owned(),
210210
)
211211
.into());
212212
}
213213
if (exp_val as u64) > to_secs(tomorrow) {
214-
return Err(error::VapidErrorKind::VapidError(
214+
return Err(error::VapidErrorKind::Protocol(
215215
r#""exp" set too far ahead"#.to_owned(),
216216
)
217217
.into());
218218
}
219219
}
220220
None => {
221221
// We already do an insertion on empty, so this should never trigger.
222-
return Err(error::VapidErrorKind::VapidError(
222+
return Err(error::VapidErrorKind::Protocol(
223223
r#""exp" failed to initialize"#.to_owned(),
224224
)
225225
.into());
@@ -238,7 +238,7 @@ pub fn sign<S: BuildHasher>(
238238
let mut signer = match Signer::new(MessageDigest::sha256(), &pub_key) {
239239
Ok(t) => t,
240240
Err(err) => {
241-
return Err(error::VapidErrorKind::VapidError(format!(
241+
return Err(error::VapidErrorKind::Protocol(format!(
242242
"Could not sign the claims: {:?}",
243243
err
244244
))
@@ -290,8 +290,7 @@ pub fn sign<S: BuildHasher>(
290290

291291
pub fn verify(auth_token: String) -> Result<HashMap<String, serde_json::Value>, String> {
292292
//Verify that the auth token string matches for the verification token string
293-
let auth_token =
294-
parse_auth_token(&auth_token).expect("Authorization header is invalid.");
293+
let auth_token = parse_auth_token(&auth_token).expect("Authorization header is invalid.");
295294
let pub_ec_key =
296295
Key::from_public_raw(auth_token.k).expect("'k' token is not a valid public key");
297296
let pub_key = &match PKey::from_ec_key(pub_ec_key) {
@@ -401,18 +400,18 @@ mod tests {
401400
assert!(result.contains(" vapid "));
402401

403402
// tear apart the auth token for the happy bits
404-
let token = result.split(" ").nth(2).unwrap();
405-
let sub_parts: Vec<&str> = token.split(",").collect();
403+
let token = result.split(' ').nth(2).unwrap();
404+
let sub_parts: Vec<&str> = token.split(',').collect();
406405
let mut auth_parts: HashMap<String, String> = HashMap::new();
407406
for kvi in &sub_parts {
408-
let kv: Vec<String> = kvi.splitn(2, "=").map(|x| String::from(x)).collect();
407+
let kv: Vec<String> = kvi.splitn(2, '=').map(String::from).collect();
409408
auth_parts.insert(kv[0].clone(), kv[1].clone());
410409
}
411410
assert!(auth_parts.contains_key("t"));
412411
assert!(auth_parts.contains_key("k"));
413412

414413
// now tear apart the token
415-
let token: Vec<&str> = auth_parts.get("t").unwrap().split(".").collect();
414+
let token: Vec<&str> = auth_parts.get("t").unwrap().split('.').collect();
416415
assert_eq!(token.len(), 3);
417416

418417
let content =

0 commit comments

Comments
 (0)