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

feat: Allow public access to bytes #250

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions oqs/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ macro_rules! newtype_buffer {
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct $name {
bytes: Vec<u8>,
pub bytes: Vec<u8>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I will not merge this: it does not provide faster reference than as_ref and this allows to mutually access bytes which I do not think is a) idiomatic Rust and b) good and safe API design.

Copy link
Author

Choose a reason for hiding this comment

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

We need the ability to construct this given a Vec<u8>. The AsRef<u8> impl is only good for reading the data.

Copy link
Author

Choose a reason for hiding this comment

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

So, if you're interesed in idiomatic rust, we could do:

impl From<Vec<u8>> for $name {
    fn from(bytes: Vec<u8>>) -> $name {
        $name { bytes }
    }
}

}

impl $name {
Expand All @@ -31,7 +31,7 @@ macro_rules! newtype_buffer {

impl<'a> $name_ref<'a> {
/// Construct a new container around this reference version
fn new(bytes: &'a [u8]) -> $name_ref<'a> {
pub fn new(bytes: &'a [u8]) -> $name_ref<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Implementing this requires an assertion on the length of bytes.

Copy link
Author

Choose a reason for hiding this comment

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

True, especially if we're dealing with pointer arithmetic under the hood. In idiomatic rust would use result types instead of assertions, especially if we decide to hand over partial control of building these wrappers to the user.

$name_ref { bytes }
}

Expand Down
Loading