Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude original_data field from PartialEq comparison #102

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ impl HeaderBuilder {
}

/// Structure representing a protected COSE header map.
#[derive(Clone, Debug, Default, PartialEq)]
#[derive(Clone, Debug, Default)]
pub struct ProtectedHeader {
/// If this structure was created by parsing serialized data, this field
/// holds the entire contents of the original `bstr` data.
Expand All @@ -353,6 +353,12 @@ pub struct ProtectedHeader {
pub header: Header,
}

impl PartialEq for ProtectedHeader {
fn eq(&self, other: &Self) -> bool {
self.header.eq(&other.header)
}
}

impl ProtectedHeader {
/// Constructor from a [`Value`] that holds a `bstr` encoded header.
#[inline]
Expand Down
15 changes: 3 additions & 12 deletions src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ fn test_header_encode() {
let got = header.clone().to_vec().unwrap();
assert_eq!(*header_data, hex::encode(&got), "case {}", i);

let mut got = Header::from_slice(&got).unwrap();
for sig in &mut got.counter_signatures {
sig.protected.original_data = None;
}
let got = Header::from_slice(&got).unwrap();
assert_eq!(*header, got);
assert!(!got.is_empty());

Expand All @@ -167,19 +164,13 @@ fn test_header_encode() {
let protected_data = protected.clone().to_vec().unwrap();
assert_eq!(*header_data, hex::encode(&protected_data), "case {}", i);

let mut got = ProtectedHeader::from_slice(&protected_data).unwrap();
for sig in &mut got.header.counter_signatures {
sig.protected.original_data = None;
}
let got = ProtectedHeader::from_slice(&protected_data).unwrap();
assert!(!got.is_empty());
assert_eq!(*header, got.header);

// Also try parsing as a protected header inside a `bstr`
let prot_bstr_val = protected.cbor_bstr().unwrap();
let mut got = ProtectedHeader::from_cbor_bstr(prot_bstr_val).unwrap();
for sig in &mut got.header.counter_signatures {
sig.protected.original_data = None;
}
let got = ProtectedHeader::from_cbor_bstr(prot_bstr_val).unwrap();
assert!(!got.is_empty());
assert_eq!(*header, got.header);
assert_eq!(
Expand Down