Skip to content
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

Salt length limit #34

Open
laurikimmel opened this issue Jan 18, 2021 · 0 comments
Open

Salt length limit #34

laurikimmel opened this issue Jan 18, 2021 · 0 comments

Comments

@laurikimmel
Copy link

Metadata

Issue type: bug/documentation improvement

Description

Only first x characters of a salt have effect on encoding result. It's undocumented and not clear whether it's a feature or a bug.

Steps to Reproduce

Following test is failing

    @Test
    public void testSaltLenght() {
        int limit = 128;
        int minHashLength = 7;
        long input = 1;
        for (int i = 0; i < limit; i++) {
            String prefix = org.apache.commons.lang3.RandomStringUtils.randomAscii(i);
            Hashids h1 = new Hashids.Builder().minLength(minHashLength).salt(prefix + "A").build();
            Hashids h2 = new Hashids.Builder().minLength(minHashLength).salt(prefix + "B").build();
            String s1 = h1.encode(input);
            String s2 = h2.encode(input);
            assertThat("i: " + i + "; prfix: '" + prefix + "'", s1, is(not(equalTo(s2))));
        }
    }

Expected Behavior

Test case above should not fail in case salt length is unlimited.

Actual Behavior

Test case fails usually around i = 45. Lowest I have seen is i = 32 which is likely related to randomly generated prefix value.

Input value looks to have effect too. When input = Hashids.MAX_INTEROP_NUMBER_SIZE test case fails usually when 41 < i < 44.

Example

Environment and Versions

IceCore Hashids: 0.4.0
OS: MacOS 11.0.1
JDK: OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)
Running in IDE and Gradle

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

No branches or pull requests

1 participant