Skip to content

Commit

Permalink
Use constants instead of hardcoded values
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKotowick committed Nov 5, 2024
1 parent b7a4259 commit 2fe6e1b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repository = "https://github.com/trussed-dev/ctap-types"
arbitrary = { version = "1.3.2", features = ["derive"], optional = true }
bitflags = "1.3"
cbor-smol = { version = "0.5", features = ["heapless-bytes-v0-3"] }
cfg-if = "1.0"
cosey = "0.3.1"
delog = "0.1"
heapless = { version = "0.7", default-features = false, features = ["serde"] }
Expand Down
5 changes: 3 additions & 2 deletions src/ctap1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod authenticate {

pub mod register {
use super::Bytes;
use crate::sizes::MAX_MESSAGE_LENGTH;

#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Request<'a> {
Expand All @@ -42,7 +43,7 @@ pub mod register {
pub header_byte: u8,
pub public_key: Bytes<65>,
pub key_handle: Bytes<255>,
pub attestation_certificate: Bytes<1024>,
pub attestation_certificate: Bytes<MAX_MESSAGE_LENGTH>,
pub signature: Bytes<72>,
}

Expand All @@ -52,7 +53,7 @@ pub mod register {
public_key: &cosey::EcdhEsHkdf256PublicKey,
key_handle: Bytes<255>,
signature: Bytes<72>,
attestation_certificate: Bytes<1024>,
attestation_certificate: Bytes<MAX_MESSAGE_LENGTH>,
) -> Self {
let mut public_key_bytes = Bytes::new();
public_key_bytes.push(0x04).unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/ctap2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use bitflags::bitflags;
use cbor_smol::cbor_deserialize;
use serde::{Deserialize, Serialize};

use crate::sizes::MAX_MESSAGE_LENGTH;
use crate::{sizes::*, Bytes, TryFromStrError, Vec};

pub use crate::operation::{Operation, VendorOperation};
Expand Down Expand Up @@ -301,7 +302,7 @@ pub struct PackedAttestationStatement {
pub alg: i32,
pub sig: Bytes<ASN1_SIGNATURE_LENGTH>,
#[serde(skip_serializing_if = "Option::is_none")]
pub x5c: Option<Vec<Bytes<1024>, 1>>,
pub x5c: Option<Vec<Bytes<MAX_MESSAGE_LENGTH>, 1>>,
}

#[derive(Clone, Debug, Default, Eq, PartialEq)]
Expand Down
13 changes: 13 additions & 0 deletions src/sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ pub const THEORETICAL_MAX_MESSAGE_SIZE: usize = PACKET_SIZE - 7 + 128 * (PACKET_
pub const LARGE_BLOB_MAX_FRAGMENT_LENGTH: usize = 0;
#[cfg(feature = "large-blobs")]
pub const LARGE_BLOB_MAX_FRAGMENT_LENGTH: usize = 3008;

// TODO: update these, and grab them from a common crate?
cfg_if::cfg_if! {
if #[cfg(feature = "backend-dilithium5")] {
pub const MAX_MESSAGE_LENGTH: usize = 7523 + 57 + 30;
} else if #[cfg(feature = "backend-dilithium3")] {
pub const MAX_MESSAGE_LENGTH: usize = 6019 + 57 + 30;
} else if #[cfg(feature = "backend-dilithium2")] {
pub const MAX_MESSAGE_LENGTH: usize = 3907 + 57 + 30;
} else {
pub const MAX_MESSAGE_LENGTH: usize = 1024;
}
}

0 comments on commit 2fe6e1b

Please sign in to comment.