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
Permit algorithms to be used in associated consts #788
Conversation
5 similar comments
Bump. This is a tiny feature change that I just happen to need for my project. I don't believe it has the ability to break existing code (since statics can refer to consts, but not vice-versa), but I can't publish on Cargo if I continue to use my own fork as a dependency. |
My understanding, which may be wrong, is that using In your crate, do you really need to reference these as associated consts? Maybe your trait could instead have a method that returned a (static) reference to the algorithm instead. |
Ah, this is a fair point. So the only way to assign things to a static variables is by reference, i.e., So existing code, which only uses However, if it does concern you that a user might accidentally make a copy of a global const, you can simply hide the const definition and only expose a pub const Blah: &'static Foo = &_Blah;
const _Blah: Foo = Foo {
a: 10,
b: 11,
c: 12,
};
pub struct Foo {
a: u8,
b: u16,
c: u32,
}
fn do_something(f: &Foo) {
println!("nope");
}
fn main() {
do_something(Blah)
} Using this method seems to be the best of both worlds, and it doesn't seem too cumbersome. Though there is a chance that this would change your API, since the constants you expose would be references instead of statics. Let me know what you think. This change might not be worth it at this point, but I think as a first-principles option, the "private const, public |
@@ -194,7 +194,7 @@ fn twin_mul( | |||
/// | |||
/// See "`ECDSA_*_FIXED` Details" in `ring::signature`'s module-level | |||
/// documentation for more details. | |||
pub static ECDSA_P256_SHA256_FIXED: Algorithm = Algorithm { | |||
pub const ECDSA_P256_SHA256_FIXED: Algorithm = Algorithm { |
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.
What I'd like to do:
- Make this private static and rename:
static ECDSA_P256_SHA256_FIXED_VALUE: Algorithm = Algorithm { ... }
. - Expose a new
pub const
:pub const ECDSA_P256_SHA256_FIXED: &'static signature::Algorithm = &ECDSA_P256_SHA256_FIXED_VALUE
. - Remove the
pub use suite_b::ecdsa::Algorithm as EcdsaVerificationAlgorithm
.
In other words, I am more interested in this change if it allows us to stop exporting EcdsaVerificationAlgorithm
and related types. Does this work?
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.
Ah, nope, it doesn't work, for the same reason that you are filing this PR in the first place. It does work if the _VALUE
part is const
instead of static
though. So, that's another advantage to doing this.
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.
Yup, you can have a const item be a &'static
ref to another const item. So it'd be possible to expose only &'static
things instead of proper Algorithm
s. The downside, though, is that the types of all these top-level definitions would change, and you'd need a major version bump.
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.
The major version bump is not an issue. That's going to happen RSN for other reasons anyway.
Bibbity bump. Do you think this will make it into 0.15? This is the only Rust crypto library that provides all the primitives necessary to implement MLS, and the only workaround for the lack of this feature is to maintain my own fork of ring. Let me know if there's anything I can do. |
Are you still interested in including this in |
Update: This PR may be unnecessary. Will decide this week. |
I have to admit I didn't (don't) quite understand why this is so important. Now that your project is open source, I'll look at it this weekend and see what the deal is. |
Do you already have a version of your project that is based on a (modified) 0.16? |
I submitted a PR to your project to try to resolve this without changes to ring: rozbb/molasses#2. I'm not opposed to making a change to ring but I'm having trouble understanding why it's so important to do so since the current code seems to work well. |
I think you're right. Thank you for spending so much time on this! I actually do have a local copy that's working with 0.16.5. Changing all my Closing |
All I did was change a ton of algorithms'
pub static
s topub const
. This should not affect runtime performance or memory usage.The reason I think this is necessary is the following use case that I cannot currently get to work: (playground link here)
The error the compiler gives me is
From RFC 1440, my guess at the reason consts can't refer to statics is because statics can be types that have destructors, but consts cannot. Anyways, the problem is solved entirely by changing the
static MyAlgorithm
line toconst MyAlgorithm
.Please let me know if you have any issues with this. Thank you for your work!