Skip to content

reuse the hasher after finalized? #429

@ibigbug

Description

@ibigbug

it seems the finalize() will consume the hasher:

Retrieve result and consume hasher instance.

https://docs.rs/md-5/latest/md5/trait.Digest.html#tymethod.finalize

how ever it doesn't reset the state.

how to reuse and write more data into the hasher after finalized()?

Activity

tarcieri

tarcieri commented on Nov 4, 2022

@tarcieri
Member

Use finalize_reset

ibigbug

ibigbug commented on Nov 5, 2022

@ibigbug
Author

i think i didn't make it clear - it's not about resetting the state. i.e. continue to write more data after finalize() and finalize() again with more data.

tarcieri

tarcieri commented on Nov 5, 2022

@tarcieri
Member

Then you want to Clone prior to finalization

burdges

burdges commented on Nov 5, 2022

@burdges

Also, merlin was more designed for this sort of thing.

As an aside, rust maybe needs some replace_with method that makes reset methods unnecessary by ensuring zero copies: rust-lang/rfcs#2884 (comment)

burdges

burdges commented on Nov 5, 2022

@burdges

It appears https://docs.rs/replace_with/ provides equivalent functionality to the *reset methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tarcieri@ibigbug@burdges

        Issue actions

          reuse the hasher after finalized? · Issue #429 · RustCrypto/hashes