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

@newpavlovnewpavlov commented Apr 27, 2026

Copy link
Copy Markdown
Member

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 tarcieriApril 27, 2026 12:16
Comment threaddigest/src/lib.rs
fn try_new_customized(customization: &[u8]) -> Result<Self, Self::Error>;
}

impl<T: CustomizedInit> TryCustomizedInit for T {

@newpavlovnewpavlovApr 27, 2026

Copy link
Copy Markdown
MemberAuthor

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:

pubtraitTryCustomizedInit:Sized{typeError;fntry_new_customized(customization:&[u8]) -> Result<Self,Self::Error>;}pubtraitCustomizedInit:TryCustomizedInit<Error = Infallible>{fnnew_customized(customization:&[u8]) -> Self{letOk(res) = self.try_new_customized(customization);
res
}}impl<T:TryCustomizedInit<Error = Infallible>CustomizedInitforT{}

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

@newpavlov
newpavlov merged commit 086cf38 into masterMay 3, 2026
22 checks passed
@newpavlov
newpavlov deleted the digest/try_customized_init branch May 3, 2026 12:48
@newpavlovnewpavlov 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 freeto 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

@newpavlov@tarcieri