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

Add trait for StatusBytes and allow lazyly configuring the initialization of the RNG #26

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

sosthene-nitrokey
Copy link

@sosthene-nitrokey sosthene-nitrokey commented Jul 29, 2024

No description provided.

src/admin.rs Outdated
Comment on lines 184 to 193
/// Trait indicating that a value can be used as a status
pub trait StatusBytes: AsRef<[u8]> {
// Set the flag indicating that the random generator could properly be created (`false`) or not (`true`)
fn set_random_error(&mut self, value: bool);
// Get the flag indicating that the random generator could properly be created (`false`) or not (`true`)
fn get_random_error(&self) -> bool;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be easier to only serialize on demand so we don’t need to parse and modify the bytes representation in the runner.

Suggested change
/// Trait indicating that a value can be used as a status
pub trait StatusBytes: AsRef<[u8]> {
// Set the flag indicating that the random generator could properly be created (`false`) or not (`true`)
fn set_random_error(&mut self, value: bool);
// Get the flag indicating that the random generator could properly be created (`false`) or not (`true`)
fn get_random_error(&self) -> bool;
}
/// Trait indicating that a value can be used as a status
pub trait Status {
// Returns the flag indicating that the random generator could properly be created (`false`) or not (`true`)
fn random_error(&mut self, value: bool) -> &mut Option<bool>;
// Writes the byte representation of this status value to a vec.
fn serialize_bytes<const N: usize>(&self, v: &mut Vec<u8, N>);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I were to do this this way I would probably do it with

pub trait Status {
    type Serialized: AsRef<[u8]>; 
    fn serialize(&self) -> Self::Serialized;
}

@sosthene-nitrokey sosthene-nitrokey marked this pull request as ready for review July 31, 2024 07:44
Copy link
Member

@robin-nitrokey robin-nitrokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d rather avoid the de-/serialization round trips required for get_random_error/set_random_error, otherwise LGTM.

@sosthene-nitrokey sosthene-nitrokey merged commit c241491 into main Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants