Skip to content

fix builder try #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

fix builder try #5

wants to merge 2 commits into from

Conversation

dhuseby
Copy link
Member

@dhuseby dhuseby commented Feb 14, 2025

This fixes a small logic bug in the try_from_multikey functions for KDF and Cipher builders. It also fixes the Blsful dependency.

Signed-off-by: Dave Huseby dwh@linuxprogrammer.org

Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
@dhuseby
Copy link
Member Author

dhuseby commented Feb 14, 2025

@DougAnderson444 fixes a small logic bug in the KDF and Cipher builders that resulted in improperly initialized KDF and Cipher multikeys.

@DougAnderson444
Copy link
Collaborator

Good catch, this should have failed but this pattern relies on the defaults if the given values fail. Is Codec the only attribute that cannot fail during conversion? What if the other fields don't convert / aren't valid, it's ok to use the defaults in those cases?

If so, I think the patch is ok. The following Notes below are for related issues but don't stop this patch:

Another note: I have not generally seen try_from on Builders, usually it's T::try_from and we could even use trait TryFrom

impl TryFrom<Multikey> for Multikey { 
   fn try_from(value: Multikey) -> Result<Multikey, Self::Error>
}

which (is recommended) would gives us this direct conversion and just right to T without TBuilder.

Also the final try_build looks like it cannot fail... so does it really need to be try?

I know these comments go beyond this one fix but I might as well note them as I see them

Eventually it's be great to clean up this API and streamline the creation of the Multikey. Using something like bon would make the API pretty slick. If something is Option<T> the process should not fail if it is None - we should use the Rust type system to remove these type of footguns and generate compile time errors if the user leaves out a necessary field.

Signed-off-by: Dave Huseby <dwh@linuxprogrammer.org>
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