-
Notifications
You must be signed in to change notification settings - Fork 705
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
Document why *ring* does not use traits to model algorithm choice #21
Comments
Reconsider this after the placement box stuff is stable: rust-lang/rfcs#1228 |
It looks like the whole placement new stuff is being tracked in rust-lang/rust#27779. I asked about how to resolve the issues that ring has run into with Traits in rust-lang/rust#27779 (comment). |
See also https://www.ralfj.de/blog/2015/10/12/formalizing-rust.html: Traits are not in the subset of Rust that they are hoping to define semantics for and/or prove correct. |
Now in |
And, it was so awkward I ended up implementing wrapper types to hide the traits. Separately, I already had to explain this a bit on IRC:
|
It looks like With function pointers, the algorithm structs become much larger than the double-pointer sized From a security perspective, storing multiple function pointers in writable locations on the stack also seems much more dangerous than a reference to a vtable in read-only memory. |
Yes.
It's a real usability problem. But, it's not worse in ring than it is in other APIs.
It doesn't matter, because there is only one copy of every
Not really, because the best implementation of
True. OTOH, we don't have to worry about external crates' implementations when we refactor the code, because of this. People can contribute implementations of new algorithms to ring if they want more algorithms supported.
Very true, but the compiler should be able to put them in read-only memory since they are all |
There is an RFC somewhere to allow types to bring trait methods into scope. I forget where or what the syntax is, but maybe something like |
Ah, some of my arguments were based on the mistaken assumption that |
For example, why doesn't ring have a
DigestAlgorithm
trait that is implemented by types namedSHA256
,SHA384
, etc.? Why is everything dynamically dispatched instead of parameterized on types and statically dispatched? How does the current design avoids unnecessary heap usage and minimizes code size. That means we have to verify that there is actually a code size savings relative to the type parameterization and static dispatching approach that people seem to expect in Rust.The text was updated successfully, but these errors were encountered: