google / google/coset

[Feature Request / Contribution Proposal] Private algorithm in builder pattern

Open
#105 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
48
Forks
26
PR merge metrics
No merged PRs in 30d

Description

Currently, the HeaderBuilder has:
```
/// Set the algorithm.
#[must_use]
pub fn algorithm(mut self, alg: iana::Algorithm) -> Self {
self.0.alg = Some(Algorithm::Assigned(alg));
self
}
```

Cose allows Private Use values (integers less than -65536), for non standardized algorithms. This can be useful for adopting algorithms widely regarded as safe and in certain contexts superior to the existing options (for example, XChaCha20, which has not been adopted into an RFC, but provides a clear benefit w.r.t. the nonce size).

This currently has to be represented as:
```
let mut protected_header = coset::HeaderBuilder::new().build();
protected_header.alg = Some(coset::Algorithm::PrivateUse(XCHACHA20_POLY1305));
```
not allowing to make use of the builder pattern.

My proposal is to add another option to the builder, along the lines of:
```
/// Set the algorithm.
#[must_use]
pub fn private_algorithm(mut self, alg: i64) -> Self {
self.0.alg = Some(Algorithm::PrivateUse(alg));
self
}
```

Unless there are concerns with this approach, I'm happy to send a PR adding this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.