Skip to content

Commit

Permalink
Implement Debug, PartialEq, Eq, Clone and Copy on all relevant structs
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jun 6, 2024
1 parent 3ab25a9 commit 922e4b1
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 135 deletions.
4 changes: 2 additions & 2 deletions generate_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def flatten(items):
response_lifetime = "<'data>"


outfile.write("#[derive(Clone, Debug)]\n")
outfile.write("#[derive(Clone, Debug, PartialEq, Eq)]\n")
outfile.write("#[cfg_attr(feature = \"builder\", derive(typed_builder::TypedBuilder))]\n")
outfile.write(f'pub struct {name}{payload_lifetime} {{\n')

Expand Down Expand Up @@ -236,7 +236,7 @@ def flatten(items):
outfile.write("}\n")

if "response" in v:
outfile.write("#[derive(Clone, Debug)]\n")
outfile.write("#[derive(Clone, Debug, PartialEq, Eq)]\n")
outfile.write(f'pub struct {name}Response{response_lifetime} {{\n')

for arg_name, arg in v["response"].items():
Expand Down
24 changes: 12 additions & 12 deletions src/se05x.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Se05X<Twi, D> {

pub const MAX_APDU_PAYLOAD_LENGTH: usize = 889;

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
Unknown,
Line(u32),
Expand Down Expand Up @@ -371,7 +371,7 @@ impl<Twi: I2CForT1, D: DelayUs<u32>> Se05X<Twi, D> {
}

bitflags! {
#[derive(Debug,Clone,Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AppletConfig: u16 {
const ECDAA = 0x0001;
const ECDSA_ECDH_ECDHE = 0x0002;
Expand All @@ -394,7 +394,7 @@ bitflags! {
}

pub struct Select;
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Atr {
pub major: u8,
pub minor: u8,
Expand Down Expand Up @@ -440,7 +440,7 @@ impl<'a> TryFrom<&'a [u8]> for Atr {

pub type VersionInfo = Atr;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ObjectAttributes {
identifier: ObjectId,
class: SecureObjectType,
Expand Down Expand Up @@ -583,7 +583,7 @@ impl<W: Writer, C: Se05XCommand<W>> Se05XCommand<W> for ProcessSessionCmd<C> {
type Response<'a> = C::Response<'a>;
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Se05xChallenge {
pub key_diversification_data: [u8; 10],
pub key_information: [u8; 3],
Expand Down Expand Up @@ -1090,7 +1090,7 @@ pub const SCP_REQUIRED: u8 = 0x01;
pub const SCP_NOT_REQUIRED: u8 = 0x02;

/// Big-endian encoded integer
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Be<I>(pub I);

impl<I> From<I> for Be<I> {
Expand Down Expand Up @@ -1262,15 +1262,15 @@ macro_rules! enum_data {
}

enum_data!(
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum TransientIndicator {
Transient = TRANSIENT_LOCK,
Persistent = PERSISTENT_LOCK,
}
);

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LockState {
Locked,
Unlocked,
Expand Down Expand Up @@ -1320,7 +1320,7 @@ impl<W: Writer> DataStream<W> for LockState {
}

enum_data!(
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum P1KeyType {
Na = P1_DEFAULT,
Expand All @@ -1331,7 +1331,7 @@ enum_data!(
);

enum_data!(
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum RsaFormat {
Crt = P2_DEFAULT,
Expand All @@ -1340,7 +1340,7 @@ enum_data!(
);

enum_data!(
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum EcCurve {
NistP192 = NIST_P192,
Expand All @@ -1366,7 +1366,7 @@ enum_data!(
);

enum_data!(
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum EcCurveParam {
ParamA = CURVE_PARAM_A,
Expand Down
Loading

0 comments on commit 922e4b1

Please sign in to comment.