Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
This patch removes code that has been commented out and empty files that
are not actually used.  It also removes the unused and undocumented
get_assertion::Responses typedef.
  • Loading branch information
robin-nitrokey committed Jun 12, 2024
1 parent 18d0c59 commit a59d966
Show file tree
Hide file tree
Showing 12 changed files with 7 additions and 284 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ license = "Apache-2.0 OR MIT"
description = "no_std friendly types for FIDO CTAP"
homepage = "https://github.com/solokeys/ctap-types"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bitflags = "1.3"
cbor-smol = "0.4"
Expand All @@ -30,5 +28,4 @@ log-all = ["cbor-smol/log-all"]
log-none = []

[patch.crates-io]
# heapless = { git = "https://github.com/nickray/heapless", branch = "bytebuf-0.5.6" }
serde-indexed = { git = "https://github.com/trussed-dev/serde-indexed.git", rev = "d95cbe064ef0bfd0ce2d01582110e29fbc22afbd" }
15 changes: 1 addition & 14 deletions src/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ use crate::ctap2;
pub use ctap1::Authenticator as Ctap1Authenticator;
pub use ctap2::Authenticator as Ctap2Authenticator;

// pub trait Authenticator {
// fn process(&mut self, request: &mut Request) -> Result<Response, Error>;
// }

#[derive(Clone, Debug, PartialEq)]
// clippy says (2022-02-26): large size difference
// - first is 88 bytes
Expand All @@ -31,15 +27,6 @@ pub enum Response {
}

/// Authenticator which supports both CTAP1 and CTAP2.
pub trait Authenticator: ctap1::Authenticator + ctap2::Authenticator {
// fn call(&mut self, request: &Request) -> Result<Response> {
// Ok(match request {
// Request::Ctap1(request) => Response::Ctap1(self.call_ctap1(request)?),
// Request::Ctap2(request) => Response::Ctap2(self.call_ctap2(request)?),
// })
// }
}
pub trait Authenticator: ctap1::Authenticator + ctap2::Authenticator {}

impl<A: ctap1::Authenticator + ctap2::Authenticator> Authenticator for A {}

// pub type Result<T> = core::result::Result<T, Error>;
Empty file removed src/authenticator/ctap1.rs
Empty file.
Empty file removed src/authenticator/ctap2.rs
Empty file.
10 changes: 0 additions & 10 deletions src/ctap1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ pub mod authenticate {
pub count: u32,
pub signature: Bytes<72>,
}

// impl AuthenticateResponse {
// pub fn new(user_presence: u8, count: u32, signature: Bytes<72>) -> Self {
// Self {
// user_presence,
// count,
// signature,
// }
// }
// }
}

pub mod register {
Expand Down
127 changes: 0 additions & 127 deletions src/ctap2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,6 @@ impl Response {
}
}

// TODO: this is a bit weird to model...
// Need to be able to "skip unknown keys" in deserialization
//
// I think we want to model this is a "set of enums",
// and allow skipping unknown enum entries during deserialization
//
// NB: This depends on the command
//
// We need two things:
// - skip unknown fields
// #[derive(Clone,Debug,Eq,PartialEq,Serialize,Deserialize)]
// pub struct AuthenticatorExtensions {
// // #[serde(skip_serializing_if = "Option::is_none")]
// // pub cred_protect:
// }

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct AuthenticatorOptions {
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -204,81 +188,6 @@ pub struct AuthenticatorOptions {
pub uv: Option<bool>,
}

// #[derive(Clone,Debug,Eq,PartialEq,SerializeIndexed,DeserializeIndexed)]
// // #[serde(rename_all = "camelCase")]
// #[serde_indexed(offset = 1)]
// pub struct GetAssertionParameters {
// pub rp_id: String<64>,
// pub client_data_hash: Bytes<32>,
// pub allow_list: Vec<PublicKeyCredentialDescriptor, 8>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub extensions: Option<AuthenticatorExtensions>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub options: Option<AuthenticatorOptions>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub pin_auth: Option<Bytes<16>>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub pin_protocol: Option<u32>,
// }

//// This is some pretty weird stuff ^^
//// Example serialization:
//// { 1: 2, // kty (key type): tstr / int [ 2 = EC2 = elliptic curve with x and y coordinate pair
//// 1 = OKP = Octet Key Pair = for EdDSA
//// // kid, bstr
//// 3: -7, // alg: tstr / int
//// [ 4: // key_ops: tstr / int 1 = sign, 2 = verify, 3 = encrypt, 4 = decrypt, ...many more
////
//// // the curve: 1 = P-256
//// -1: 1,
//// // x-coordinate
//// -2: b'\xa0\xc3\x14\x06!\xefM\xcc\x06u\xf0\xf5v\x0bXa\xe6\xacm\x8d\xd9O`\xbd\x81\xf1\xe0_\x1a*\xdd\x9e',
//// // y-coordinate
//// -3: b'\xb4\xd4L\x94-\xbeVr\xe9C\x13u V\xf4t^\xe4.\xa2\x87I\xfe \xa4\xb0KY\x03\x00\x8c\x01'}
////
//// EdDSA
//// 1: 1
//// 3: -8,
//// -1: 6,
//// -2: public key bytes
//#[derive(Clone,Debug,Eq,PartialEq,Serialize,Deserialize)]
//#[serde(rename_all = "camelCase")]
//pub struct CredentialPublicKey {
//}

// #[derive(Clone,Debug,Eq,PartialEq)]
// // #[serde(rename_all = "camelCase")]
// pub struct AuthenticatorData {
// pub rp_id_hash: Bytes<32>,
// pub flags: u8,
// pub sign_count: u32,
// // this can get pretty long
// pub attested_credential_data: Option<Bytes<ATTESTED_CREDENTIAL_DATA_LENGTH>>,
// // pub extensions: ?
// }

// impl AuthenticatorData {
// pub fn serialize(&self) -> Bytes<AUTHENTICATOR_DATA_LENGTH> {
// let mut bytes = Vec::<u8, AUTHENTICATOR_DATA_LENGTH>::new();

// // 32 bytes, the RP id's hash
// bytes.extend_from_slice(&self.rp_id_hash).unwrap();
// // flags
// bytes.push(self.flags).unwrap();
// // signature counts as 32-bit unsigned big-endian integer.
// bytes.extend_from_slice(&self.sign_count.to_be_bytes()).unwrap();
// match &self.attested_credential_data {
// Some(ref attested_credential_data) => {
// // finally the attested credential data
// bytes.extend_from_slice(&attested_credential_data).unwrap();
// },
// None => {},
// }

// Bytes::from(bytes)
// }
// }

bitflags! {
pub struct AuthenticatorDataFlags: u8 {
const USER_PRESENCE = 1 << 0;
Expand All @@ -293,13 +202,10 @@ pub trait SerializeAttestedCredentialData {
}

#[derive(Clone, Debug, Eq, PartialEq)]
// #[serde(rename_all = "camelCase")]
pub struct AuthenticatorData<A, E> {
pub rp_id_hash: Bytes<32>,
pub flags: AuthenticatorDataFlags,
pub sign_count: u32,
// this can get pretty long
// pub attested_credential_data: Option<Bytes<ATTESTED_CREDENTIAL_DATA_LENGTH>>,
pub attested_credential_data: Option<A>,
pub extensions: Option<E>,
}
Expand All @@ -311,7 +217,6 @@ pub type SerializedAuthenticatorData = Bytes<AUTHENTICATOR_DATA_LENGTH>;
impl<A: SerializeAttestedCredentialData, E: serde::Serialize> AuthenticatorData<A, E> {
#[inline(never)]
pub fn serialize(&self) -> SerializedAuthenticatorData {
// let mut bytes = Vec::<u8, AUTHENTICATOR_DATA_LENGTH>::new();
let mut bytes = SerializedAuthenticatorData::new();

// 32 bytes, the RP id's hash
Expand Down Expand Up @@ -341,38 +246,6 @@ impl<A: SerializeAttestedCredentialData, E: serde::Serialize> AuthenticatorData<
}
}

// // TODO: add Default and builder
// #[derive(Clone,Debug,Eq,PartialEq,Serialize)]
// pub struct AuthenticatorInfo<'l> {
// pub(crate) versions: &'l[&'l str],
// #[serde(skip_serializing_if = "Option::is_none")]
// pub(crate) extensions: Option<&'l[&'l str]>,
// // #[serde(serialize_with = "serde_bytes::serialize")]
// pub(crate) aaguid: &'l [u8],//; 16],
// #[serde(skip_serializing_if = "Option::is_none")]
// pub(crate) options: Option<CtapOptions>,
// // TODO: this is actually the constant MESSAGE_SIZE
// #[serde(skip_serializing_if = "Option::is_none")]
// pub(crate) max_msg_size: Option<usize>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub(crate) pin_protocols: Option<&'l[u8]>,

// // not in the CTAP spec, but see https://git.io/JeNxG
// #[serde(skip_serializing_if = "Option::is_none")]
// pub(crate) max_creds_in_list: Option<usize>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub(crate) max_cred_id_length: Option<usize>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub(crate) transports: Option<&'l[u8]>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub(crate) algorithms: Option<&'l[u8]>,
// }

// pub enum Algorithm {
// ES256,
// EdDSA,
// }

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Error {
Success = 0x00,
Expand Down
19 changes: 6 additions & 13 deletions src/ctap2/credential_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,23 @@ use crate::{
type Bytes32 = Bytes<32>;

#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize_repr, Deserialize_repr)]
// #[derive(Clone,Debug,Eq,PartialEq,Serialize, Deserialize)]
// #[serde(tag = "credProtect")]
#[repr(u8)]
pub enum CredentialProtectionPolicy {
// #[serde(rename = "userVerificationOptional")]
#[default]
Optional = 1,
// #[serde(rename = "userVerificationOptionalWithCredentialIDList")] // <-- len = 44
OptionalWithCredentialIdList = 2,
// #[serde(rename = "userVerificationRequired")]
Required = 3,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum Subcommand {
GetCredsMetadata = 0x01, // 1, 2
EnumerateRpsBegin = 0x02, // 3, 4, 5
EnumerateRpsGetNextRp = 0x03, // 3, 4
EnumerateCredentialsBegin = 0x04, // 6, 7, 8 ,9, A
EnumerateCredentialsGetNextCredential = 0x05, // 6, 7, 8, A
DeleteCredential = 0x06, // -
GetCredsMetadata = 0x01,
EnumerateRpsBegin = 0x02,
EnumerateRpsGetNextRp = 0x03,
EnumerateCredentialsBegin = 0x04,
EnumerateCredentialsGetNextCredential = 0x05,
DeleteCredential = 0x06,
UpdateUserInformation = 0x07,
}

Expand Down Expand Up @@ -70,7 +65,6 @@ pub struct Request<'a> {

#[derive(Clone, Debug, Default, Eq, PartialEq, SerializeIndexed)]
#[serde_indexed(offset = 1)]
// #[derive(Clone,Debug, Default,Eq,PartialEq,Serialize,Deserialize)]
pub struct Response {
// Metadata

Expand Down Expand Up @@ -104,7 +98,6 @@ pub struct Response {
// 0x08
#[serde(skip_serializing_if = "Option::is_none")]
pub public_key: Option<PublicKey>,
// pub public_key: Option<Bytes<COSE_KEY_LENGTH>>, // <-- AAAAHH. no Bytes, just COSE_Key
// 0x09
#[serde(skip_serializing_if = "Option::is_none")]
pub total_credentials: Option<u32>,
Expand Down
10 changes: 0 additions & 10 deletions src/ctap2/get_assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ use super::AuthenticatorOptions;
use crate::sizes::*;
use crate::webauthn::*;

// #[derive(Clone,Debug,Eq,PartialEq,Serialize,Deserialize)]
// pub struct AuthenticatorExtensions {
// #[serde(rename = "hmac-secret")]
// #[serde(skip_serializing_if = "Option::is_none")]
// pub hmac_secret: Option<bool>,
// }

#[derive(Clone, Debug, Eq, PartialEq, SerializeIndexed, DeserializeIndexed)]
#[serde_indexed(offset = 1)]
pub struct HmacSecretInput {
Expand Down Expand Up @@ -57,7 +50,6 @@ pub type AuthenticatorData = super::AuthenticatorData<NoAttestedCredentialData,
pub type AllowList<'a> = Vec<PublicKeyCredentialDescriptorRef<'a>, MAX_CREDENTIAL_COUNT_IN_LIST>;

#[derive(Clone, Debug, Eq, PartialEq, SerializeIndexed, DeserializeIndexed)]
// #[serde(rename_all = "camelCase")]
#[serde_indexed(offset = 1)]
pub struct Request<'a> {
pub rp_id: String<64>,
Expand Down Expand Up @@ -95,5 +87,3 @@ pub struct Response {
#[serde(skip_serializing_if = "Option::is_none")]
pub large_blob_key: Option<Bytes<32>>,
}

pub type Responses = Vec<Response, 8>;
7 changes: 0 additions & 7 deletions src/ctap2/get_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@ pub struct Response {
pub extensions: Option<Vec<String<13>, 4>>,

// 0x03
// #[serde(with = "serde_bytes")]
// #[serde(serialize_with = "serde_bytes::serialize", deserialize_with = "serde_bytes::deserialize")]
// #[serde(serialize_with = "serde_bytes::serialize")]
// pub(crate) aaguid: Vec<u8, 16>,
pub aaguid: Bytes<16>,

// 0x04
#[serde(skip_serializing_if = "Option::is_none")]
pub options: Option<CtapOptions>,

// 0x05
// TODO: this is actually the constant MESSAGE_SIZE
#[serde(skip_serializing_if = "Option::is_none")]
pub max_msg_size: Option<usize>,

Expand All @@ -54,8 +49,6 @@ pub struct Response {
// FIDO_2_1
#[serde(skip_serializing_if = "Option::is_none")]
pub algorithms: Option<FilteredPublicKeyCredentialParameters>,
// #[serde(skip_serializing_if = "Option::is_none")]
// pub(crate) algorithms: Option<&'l[u8]>,

// 0x0B
// FIDO_2_1
Expand Down
Loading

0 comments on commit a59d966

Please sign in to comment.