Skip to content

Commit

Permalink
Use references for ClientPin, CredentialManagement
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-nitrokey committed Mar 4, 2024
1 parent a9f8003 commit 62a822a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/ctap2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ pub enum Request<'a> {
// 0x4
GetInfo,
// 0x6
ClientPin(client_pin::Request),
ClientPin(client_pin::Request<'a>),
// 0x7
Reset,
// 0xA
CredentialManagement(credential_management::Request),
CredentialManagement(credential_management::Request<'a>),
// 0xB
Selection,
// 0xC
Expand Down
12 changes: 6 additions & 6 deletions src/ctap2/client_pin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Bytes, String};
use crate::Bytes;
use bitflags::bitflags;
use serde_indexed::{DeserializeIndexed, SerializeIndexed};
use serde_repr::{Deserialize_repr, Serialize_repr};
Expand Down Expand Up @@ -36,7 +36,7 @@ bitflags! {

#[derive(Clone, Debug, Eq, PartialEq, SerializeIndexed, DeserializeIndexed)]
#[serde_indexed(offset = 1)]
pub struct Request {
pub struct Request<'a> {
// 0x01
// PIN protocol version chosen by the client.
// For this version of the spec, this SHALL be the number 1.
Expand All @@ -56,18 +56,18 @@ pub struct Request {
// First 16 bytes of HMAC-SHA-256 of encrypted contents
// using `sharedSecret`.
#[serde(skip_serializing_if = "Option::is_none")]
pub pin_auth: Option<Bytes<256>>,
pub pin_auth: Option<&'a serde_bytes::Bytes>,

// 0x05
// Encrypted new PIN using `sharedSecret`.
// (Encryption over UTF-8 representation of new PIN).
#[serde(skip_serializing_if = "Option::is_none")]
pub new_pin_enc: Option<Bytes<80>>,
pub new_pin_enc: Option<&'a serde_bytes::Bytes>,

// 0x06
// Encrypted first 16 bytes of SHA-256 of PIN using `sharedSecret`.
#[serde(skip_serializing_if = "Option::is_none")]
pub pin_hash_enc: Option<Bytes<80>>,
pub pin_hash_enc: Option<&'a serde_bytes::Bytes>,

// 0x07
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -85,7 +85,7 @@ pub struct Request {
// 0x0A
// The RP ID to assign as the permissions RP ID
#[serde(skip_serializing_if = "Option::is_none")]
pub rp_id: Option<String<256>>,
pub rp_id: Option<&'a str>,
}

#[derive(Clone, Debug, Default, Eq, PartialEq, SerializeIndexed, DeserializeIndexed)]
Expand Down
15 changes: 8 additions & 7 deletions src/ctap2/credential_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
use crate::{
cose::PublicKey,
webauthn::{
PublicKeyCredentialDescriptor, PublicKeyCredentialRpEntity, PublicKeyCredentialUserEntity,
PublicKeyCredentialDescriptor, PublicKeyCredentialDescriptorRef,
PublicKeyCredentialRpEntity, PublicKeyCredentialUserEntity,
},
Bytes,
};
Expand Down Expand Up @@ -39,32 +40,32 @@ pub enum Subcommand {

#[derive(Clone, Debug, Eq, PartialEq, SerializeIndexed, DeserializeIndexed)]
#[serde_indexed(offset = 1)]
pub struct SubcommandParameters {
pub struct SubcommandParameters<'a> {
// 0x01
#[serde(skip_serializing_if = "Option::is_none")]
pub rp_id_hash: Option<Bytes32>,
pub rp_id_hash: Option<&'a serde_bytes::Bytes>,
// 0x02
#[serde(skip_serializing_if = "Option::is_none")]
pub credential_id: Option<PublicKeyCredentialDescriptor>,
pub credential_id: Option<PublicKeyCredentialDescriptorRef<'a>>,
// 0x03
#[serde(skip_serializing_if = "Option::is_none")]
pub user: Option<PublicKeyCredentialUserEntity>,
}

#[derive(Clone, Debug, Eq, PartialEq, SerializeIndexed, DeserializeIndexed)]
#[serde_indexed(offset = 1)]
pub struct Request {
pub struct Request<'a> {
// 0x01
pub sub_command: Subcommand,
// 0x02
#[serde(skip_serializing_if = "Option::is_none")]
pub sub_command_params: Option<SubcommandParameters>,
pub sub_command_params: Option<SubcommandParameters<'a>>,
// 0x03
#[serde(skip_serializing_if = "Option::is_none")]
pub pin_protocol: Option<u8>,
// 0x04
#[serde(skip_serializing_if = "Option::is_none")]
pub pin_auth: Option<Bytes<256>>,
pub pin_auth: Option<&'a serde_bytes::Bytes>,
}

#[derive(Clone, Debug, Default, Eq, PartialEq, SerializeIndexed)]
Expand Down

0 comments on commit 62a822a

Please sign in to comment.