Skip to content

Commit 53ca3f9

Browse files
authored
Merge pull request #89 from 1Password/various-cleanup
Various cleanup
2 parents 6de11f0 + 3675189 commit 53ca3f9

File tree

6 files changed

+24
-83
lines changed

6 files changed

+24
-83
lines changed

passkey-authenticator/src/authenticator/make_credential/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ async fn make_credential_returns_err_when_rk_is_requested_but_not_supported() {
440440
// Assert
441441
assert_eq!(err, Ctap2Error::UnsupportedOption.into());
442442
}
443+
443444
#[tokio::test]
444445
async fn empty_store_with_exclude_credentials_succeeds() {
445446
// This test verifies the fix for the issue where an empty credential store

passkey-client/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ pub enum WebauthnError {
8080
RedirectError,
8181
/// Related Origins endpoint contains a number of labels exceeding the max limit
8282
ExceedsMaxLabelLimit,
83+
/// JSON serialization error
84+
SerializationError,
8385
}
8486

8587
impl WebauthnError {
@@ -253,8 +255,8 @@ where
253255
unknown_keys: Default::default(),
254256
};
255257

256-
// SAFETY: it is a developer error if serializing this struct fails.
257-
let client_data_json = serde_json::to_string(&collected_client_data).unwrap();
258+
let client_data_json = serde_json::to_string(&collected_client_data)
259+
.map_err(|_| WebauthnError::SerializationError)?;
258260
let client_data_json_hash = client_data
259261
.client_data_hash()
260262
.unwrap_or_else(|| sha256(client_data_json.as_bytes()).to_vec());
@@ -374,8 +376,8 @@ where
374376
unknown_keys: Default::default(),
375377
};
376378

377-
// SAFETY: it is a developer error if serializing this struct fails.
378-
let client_data_json = serde_json::to_string(&collected_client_data).unwrap();
379+
let client_data_json = serde_json::to_string(&collected_client_data)
380+
.map_err(|_| WebauthnError::SerializationError)?;
379381
let client_data_json_hash = client_data
380382
.client_data_hash()
381383
.unwrap_or_else(|| sha256(client_data_json.as_bytes()).to_vec());

passkey-client/src/quirks.rs

Lines changed: 0 additions & 64 deletions
This file was deleted.

passkey-types/src/ctap2/make_credential.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! <https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#authenticatorMakeCredential>
22
3-
use ciborium::{Value, cbor};
3+
use ciborium::cbor;
44
use serde::{Deserialize, Serialize};
55

66
use crate::{
@@ -11,8 +11,11 @@ use crate::{
1111
};
1212

1313
#[cfg(doc)]
14-
use crate::webauthn::{
15-
CollectedClientData, PublicKeyCredentialCreationOptions, PublicKeyCredentialDescriptor,
14+
use {
15+
crate::webauthn::{
16+
CollectedClientData, PublicKeyCredentialCreationOptions, PublicKeyCredentialDescriptor,
17+
},
18+
ciborium::value::Value,
1619
};
1720

1821
use super::extensions::{AuthenticatorPrfInputs, AuthenticatorPrfMakeOutputs, HmacGetSecretInput};
@@ -280,7 +283,7 @@ serde_workaround! {
280283
// TODO: Change to a flattened enum when `content, type` serde enums can use numbers as
281284
// the keys
282285
#[serde(rename = 0x03)]
283-
pub att_stmt: Value,
286+
pub att_stmt: ciborium::value::Value,
284287

285288
/// Indicates whether an enterprise attestation was returned for this credential.
286289
/// If `ep_att` is absent or present and set to false, then an enterprise attestation was not returned.
@@ -323,7 +326,7 @@ impl Response {
323326
"fmt" => "none",
324327
"attStmt" => {},
325328
// Explicitly define these fields as bytes since specialization is still fairly far
326-
"authData" => Value::Bytes(self.auth_data.to_vec()),
329+
"authData" => ciborium::value::Value::Bytes(self.auth_data.to_vec()),
327330
})
328331
.unwrap();
329332
ciborium::ser::into_writer(&attestation_object_value, &mut attestation_object).unwrap();

passkey-types/src/utils/bytes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ impl<'de> Deserialize<'de> for Bytes {
143143
where
144144
E: serde::de::Error,
145145
{
146+
// There have been some whitespace seen in incoming base64 encodings.
147+
let v = v.trim();
146148
v.try_into().map_err(|_| {
147149
E::invalid_value(
148150
serde::de::Unexpected::Str(v),

passkey-types/src/utils/serde.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ where
8383
Ok(de
8484
.deserialize_seq(IgnoreUnknown(std::marker::PhantomData))
8585
.unwrap_or_default())
86-
// de.deserialize_seq(IgnoreUnknown(std::marker::PhantomData))
8786
}
8887

8988
pub(crate) fn ignore_unknown_vec<'de, D, T>(de: D) -> Result<Vec<T>, D::Error>
@@ -141,15 +140,12 @@ where
141140
where
142141
E: Error,
143142
{
144-
match FromStr::from_str(v) {
145-
Ok(v) => Ok(v),
146-
_ => {
147-
if let Ok(v) = f64::from_str(v) {
148-
self.visit_f64(v)
149-
} else {
150-
Err(E::custom("Was not a stringified number"))
151-
}
152-
}
143+
if let Ok(v) = FromStr::from_str(v) {
144+
Ok(v)
145+
} else if let Ok(v) = f64::from_str(v) {
146+
self.visit_f64(v)
147+
} else {
148+
Err(E::custom("Was not a stringified number"))
153149
}
154150
}
155151

@@ -279,5 +275,6 @@ where
279275
{
280276
de.deserialize_any(StringOrBool)
281277
}
278+
282279
#[cfg(test)]
283280
mod tests;

0 commit comments

Comments
 (0)