-
Notifications
You must be signed in to change notification settings - Fork 3
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
added proptest & impl Arbitrary traits for quote #2
base: master
Are you sure you want to change the base?
Conversation
2c5f157
to
01b0e75
Compare
@@ -36,13 +51,89 @@ pub struct Header { | |||
pub user_data: [u8; 20], | |||
} | |||
|
|||
#[derive(Decode, Debug)] | |||
impl Arbitrary for Header { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code readability suffers when implementing traits manually like this, and it's error-prone. Consider using #[derive(Arbitrary)]
instead.
T: Encode + TryFrom<usize>, | ||
<T as TryFrom<usize>>::Error: std::fmt::Debug, | ||
{ | ||
fn encode(&self) -> Vec<u8> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer implementing fn encode_to
rather than fn encode
to avoid one extra heap allocation + data copying.
@@ -181,6 +529,16 @@ impl Decode for AuthDataV4 { | |||
} | |||
} | |||
|
|||
impl Encode for AuthDataV4 { | |||
fn encode(&self) -> Vec<u8> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer encode_to
let mut encoded = vec![]; | ||
header.encode_to(&mut encoded); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut encoded = vec![]; | |
header.encode_to(&mut encoded); | |
let encoded = header.encode(); |
Added the Arbitrary trait to each Quote struct to simplify mocking and testing.