-
Notifications
You must be signed in to change notification settings - Fork 20
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
Macro for deriving RandGen for some structs #231
Comments
@realcr can I take this one? |
Of course! Please send a message if you need any help. |
@realcr I am very new to Rust, I would like to work on this issue! |
I was going suggest a different approach: a blanket-impl for things implementing the two traits used in the implementation: This raises the question however: should |
@lladhibhutall : Sure thing, will be happy to help you out. @amosonn idea looks very interesting, maybe we can try it out. @amosonn: I couldn't remember myself, so I just checked and this chunk of code compiles: #[cfg(test)]
mod tests {
use super::*;
#[test]
fn check_private_key() {
let mut private_key = PrivateKey::default();
let _a: &mut [u8] = &mut private_key;
}
} Does it mean we are good to go with your idea? |
No, I meant it the other way around, that maybe The boilerplate impls could be replaced with a blanket impl for things which do implement Those impls of |
Now I understand. |
Right, the macro that was present for the others and not for Here are the relevant files: Having My suggestion for now would be to split at least this |
I began porting the cryptographic library away from @lladhibhutall : Sorry for all the complications. I actually thought that this is a very simple issue, but it turned out that there are turtles all the way down. I hope to update you when this issue becomes something more manageable, or when there is another interesting task to do at the codebase. |
So PR #300 is done. This means that traits like Possible obstacles I can think of:
|
I'm pretty sure serde doesn't need this DerefMut, and perhaps neither
quickcheck; it's also worth noting, that if you only allow valid data
inside say `PrivateKey`, then it's good that quickcheck will check exactly
that.
…On Fri, Jun 19, 2020, 14:24 real ***@***.***> wrote:
So PR #300 <#300> is done.
After going again over the code I began to better understand what @amosonn
<https://github.com/amosonn> was talking about.
The general idea is that it shouldn't be possible to create or modify
things like PublicKey and PrivateKey, except for using the proper ways.
For example, PrivateKey should only be created using a random generator,
and PublicKey can be derived from a PrivateKey.
There might be other structures like PrivateKey that probably deserve a
similar treatment.
This means that traits like DerefMut and Default should not be
implemented automatically.
Having this change will require fixes, hopefully minor, across other
places in the code.
Possible obstacles I can think of:
- serde serialization
- quickcheck automatic generation
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#231 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAX7HLI6FGKQSLWWSA7EQNTRXNKHZANCNFSM4IEAYXDQ>
.
|
The code at https://github.com/freedomlayer/offst/blob/master/components/crypto/src/rand.rs is very repetitive. Example:
We can create a macro that does this automatically, possibly a macro that that can be used like this:
derive_rand_gen!(InvoiceId);
This issue is suitable for beginners with Rust and with the Offst project.
The text was updated successfully, but these errors were encountered: