Skip to content

Salt with invalid character fails with error SaltToLong #706

Description

@Szymongib

Overview

When trying to create Salt via Salt::new(...) with an invalid PHC character, the operation fails with the Error::SaltToLong error which was a little confusing until I looked into the code here:
https://github.com/RustCrypto/traits/blob/master/password-hash/src/salt.rs#L108

Example salt to reproduce: 1234_mysalt.

From the left todo, I assume it might have been a known issue.

Possible solution

Perhaps the Error::ParamValueInvalid could be extended to contain the cause of the invalid value:

...
pub enum Error {
...
    ParamValueInvalid(ParamValueError)
...
}

pub enum ParamValueError {
    ToLong,
    ToShort,
    InvalidChar,
    // ... and any other possible issues
}

This might be treated as a breaking change from the library perspective tho.

I can try to draft the PR if there is any interest in this solution, otherwise happy to discuss further 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions