Factory: refactor into macros?
@npajkovsky is already working on this.
Since Aug 13, 2026.
Assessment
This issue has not been assessed yet.
Description
Currently the factory objects look like this:
pub enum HashFactory {
///
SHA224(sha2::SHA224),
///
SHA256(sha2::SHA256),
///
SHA384(sha2::SHA384),
///
SHA512(sha2::SHA512),
///
SHA3_224(sha3::SHA3_224),
///
SHA3_256(sha3::SHA3_256),
///
SHA3_384(sha3::SHA3_384),
///
SHA3_512(sha3::SHA3_512),
}
...
fn hash(self, data: &[u8]) -> Vec<u8> {
match self {
Self::SHA224(h) => h.hash(data),
Self::SHA256(h) => h.hash(data),
Self::SHA384(h) => h.hash(data),
Self::SHA512(h) => h.hash(data),
Self::SHA3_224(h) => h.hash(data),
Self::SHA3_256(h) => h.hash(data),
Self::SHA3_384(h) => h.hash(data),
Self::SHA3_512(h) => h.hash(data),
}
}
This code is highly repetitive and begging for a macro, maybe of the form:
impl_hash_factory!(SHA224, SHA256, SHA384, SHA512, SHA3_224, SHA3_256, SHA3_384, SHA3_512)
That said, I generally find macros for the sake of reducing the number of lines of code are not worth it because they make the code harder to read, harder to debug, and harder to test. So I think we should do the refactor of bouncycastle-factory to use macros, just to see what it looks like, and then decide if it is actually an improvement or not.
- Dominant language
- Rust
- Stars
- 25
- Forks
- 18
- Avg merge
- 16h 38m
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bcgit/bc-rust
-
good first issue refactor
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
gitbutlerapp/gitbutler#15998 · 1 comment ·
-
bug triage:deciding
Difficulty 1/5 Under an hour Newbie friendliness 88/100
open-telemetry/otel-arrow#4132 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100