Repository navigation
Description
We have a number of tickets open about factories. I think we agree that the current design of the factory basically needs to be deleted and re-designed from scratch.
Design goals:
- Provide an abstraction layer that keeps algorithm-specific code out of calling applications. For example, if an application needs a signature algorithm, it should be possible to build it abstractly so that the developer doesn't know or care whether it's ML-DSA-44, ML-DSA-87, ECDSA-P256, or something else. That essentially means that the abstraction layer should operate at the level of traits so that you only need to know that you're holding a
&dyn Signer, or similar. - Provide a string-to-object mapping; ie something that behaves something like
let signer = SignerFactory::new_from_name("ML-DSA-65"); - That scaffolding will make it easy to build protocols like X.509, CMS, JWT, CWT, TLS (if we go there) because they just need a mapping table from however that protocol names algorithms (OIDs, codepoints, etc) to our canonical internal name, and then they can use the factory. In particular, that does separation of layers by keeping algorithm-specific junk out of the protocol layer.
We get to decide at what level of std, no_std+alloc, no_std, no_alloc we want the factory to be functional at. The current factory is attempting to be operable without an allocator, and this is the root of all the complexity. Doing this at the no_std+alloc level would be much simpler because then you'd have access to Box, which would make the whole thing easier.
PS -- if we trash the current factory crate, then that might soften the requirement that our traits.rs all need to be dyn-compatible, which would allow us to roll-back some of the hideous designs, like the fact that Hash's hash() isn't a static, but instead requires SHA256::new().hash(&msg); when it really should be SHA256::hash(&msg); for no good reason except that the latter is not dyn-compatible.
Activity
dghgit commentedon Nov 7, 2026
I agree we definitely need some examples of 3 first - there seems to be far to many options for how to roll this kind of stuff in Rust, each with their own particular set of, erm..., "advantages and disadvantages". If we could just get enough ASN.1 parsing/encoding to be able to sign/verify a certificate we'd then know what things would look like for everything from CMS to PGP (cashing in on bc-java/bc-csharp experience here). Although I suspect 1 and 2 will fall out of that, so perhaps things are reversed. Use of dyn does seem to be a popular lever though, there's still a bit to be done to support it.
There's one wish that's come true already:
actually works now.
dghgit commentedon Nov 10, 2026
From PR #180