-
Notifications
You must be signed in to change notification settings - Fork 790
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
[crypto] Pass buffers by value. #20891
[crypto] Pass buffers by value. #20891
Conversation
0c0f251
to
e102b33
Compare
e102b33
to
23a952e
Compare
* | ||
* The order of `data` and `len` is important here for Rust compatibility; if | ||
* `data` comes first, the representation exactly matches slices and is easier | ||
* to call from Rust. |
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.
It's possible that the current compiler implementation always puts data
first, but the layout of slices is not guaranteed, so that's not something we can rely on.
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.
I see, that's a shame. I'll remove the comment.
Since word/byte buffers are structs containing only a pointer and a length, there is no need to make them pointers when they are return values, and this makes the API a little more ergonomic. Signed-off-by: Jade Philipoom <[email protected]>
This is helpful for compatibility when the cryptolib is called from Rust code. Signed-off-by: Jade Philipoom <[email protected]>
Signed-off-by: Jade Philipoom <[email protected]>
Now that the output buffer is passed by value, the length must be returned separately. Signed-off-by: Jade Philipoom <[email protected]>
7a8de7d
to
bd00104
Compare
Since word/byte buffers are structs containing only a pointer and a length, there is no need to make them pointers when they are return values, and this makes the API more ergonomic and easier to call from Rust (since you can just pass a slice directly). I also fixed the order of
data
andlen
in the buffer types for Rust compatibility in the second commit. The third commit applies the same change to hash digest structs (which look a lot like word buffers except they remember the hash mode used to construct them).