mirrored from https://www.bouncycastle.org/repositories/bc-rust
-
Notifications
You must be signed in to change notification settings - Fork 14
API Design: Factory Pattern Friction With Rust #23
Copy link
Copy link
Open
Labels
discussionThis will involve some community discussion to choose the right designThis will involve some community discussion to choose the right designdocumentationImprovements or additions to documentationImprovements or additions to documentationhelp wantedCould be picked up by anyone in the communityCould be picked up by anyone in the community
Metadata
Metadata
Assignees
Labels
discussionThis will involve some community discussion to choose the right designThis will involve some community discussion to choose the right designdocumentationImprovements or additions to documentationImprovements or additions to documentationhelp wantedCould be picked up by anyone in the communityCould be picked up by anyone in the community
Type
Fields
Give feedbackNo fields configured for Task.
Problem
Rust is a multi-paradigm systems programming language that is not purely object-oriented. In comparison to other Bouncy Castle cryptography libraries that are expressed in native object-oriented languages (C# and Java, for example), Rust is unique given its strict nature.
As part of API design, factories are a contentious issue. In C# and Java counterparts, they are a utility class that creates cryptographic objects from encoded data without the caller needing to know the exact implementation type, which follows a factory pattern. They both use runtime data-driven dispatch (read and parse metadata, find discriminator field, choose constructor based on that value) to determine what specific cryptographic constructor to use.
Rust does not naturally model this pattern in the same way as Java or C#. As part of API design, we need to determine how factory-style decoding should be represented:
The goal is to provide a Rust-idiomatic API while preserving support for decoding algorithm-agnostic encoded data.