Skip to content

digest: add TryCustomizedInit trait#2395

Merged
newpavlov merged 3 commits into
masterfrom
digest/try_customized_init
May 3, 2026
Merged

digest: add TryCustomizedInit trait#2395
newpavlov merged 3 commits into
masterfrom
digest/try_customized_init

Conversation

@newpavlov
Copy link
Copy Markdown
Member

@newpavlov newpavlov commented Apr 27, 2026

Some algorithms (e.g. Ascon-CXOF128 and bash-prg-hash) place restrictions on customization strings, so with the current version of digest we either have to panic on invalid strings or use inherent methods. This PR amends this by introducing a fallible variant of CustomizedInit with the blanket impl to act as a bridge between the traits.

@newpavlov newpavlov requested a review from tarcieri April 27, 2026 12:16
Comment thread digest/src/lib.rs
fn try_new_customized(customization: &[u8]) -> Result<Self, Self::Error>;
}

impl<T: CustomizedInit> TryCustomizedInit for T {
Copy link
Copy Markdown
Member Author

@newpavlov newpavlov Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually I would prefer to do this instead:

pub trait TryCustomizedInit: Sized {
    type Error;
    fn try_new_customized(customization: &[u8]) -> Result<Self, Self::Error>;
}

pub trait CustomizedInit: TryCustomizedInit<Error = Infallible> {
    fn new_customized(customization: &[u8]) -> Self {
        let Ok(res) = self.try_new_customized(customization);
        res
    }
}

impl<T: TryCustomizedInit<Error = Infallible> CustomizedInit for T {}

But it would be a breaking change, so it has to be deferred until a future breaking release.

@newpavlov newpavlov merged commit 086cf38 into master May 3, 2026
22 checks passed
@newpavlov newpavlov deleted the digest/try_customized_init branch May 3, 2026 12:48
@newpavlov newpavlov mentioned this pull request May 3, 2026
newpavlov added a commit that referenced this pull request May 3, 2026
### Added
- `dev::initialized_mac_test` function ([#2367])
- `TryCustomizedInit` trait ([#2395])

[#2367]: #2367
[#2395]: #2395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants