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

[ELY-1573] equals/hashCode methods for PasswordSpec classes #1148

Merged
merged 1 commit into from Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,6 +18,8 @@

package org.wildfly.security.password.spec;

import java.util.Arrays;

import org.wildfly.common.Assert;

/**
Expand Down Expand Up @@ -47,4 +49,14 @@ public ClearPasswordSpec(final char[] encodedPassword) {
public char[] getEncodedPassword() {
return encodedPassword;
}

@Override
public boolean equals(Object other) {
return other instanceof ClearPasswordSpec && Arrays.equals(encodedPassword, ((ClearPasswordSpec)other).encodedPassword);
}

@Override
public int hashCode() {
return Arrays.hashCode(encodedPassword);
}
}
Expand Up @@ -17,6 +17,11 @@
*/
package org.wildfly.security.password.spec;

import static org.wildfly.common.math.HashMath.multiHashOrdered;

import java.util.Arrays;
import java.util.Objects;

/**
* A {@link PasswordSpec} for a password represented by a Digest Response as seen in Digest-MD5 SASL/HTTP mechanism.
*
Expand Down Expand Up @@ -61,4 +66,15 @@ public byte[] getDigest() {
return digest;
}

@Override
public boolean equals(Object other) {
if (! (other instanceof DigestPasswordSpec)) return false;
DigestPasswordSpec o = (DigestPasswordSpec) other;
return Objects.equals(username, o.username) && Objects.equals(realm, o.realm) && Arrays.equals(digest, o.digest);
}

@Override
public int hashCode() {
return multiHashOrdered(multiHashOrdered(Objects.hashCode(username), Objects.hashCode(realm)), Arrays.hashCode(digest));
}
}
Expand Up @@ -18,7 +18,11 @@

package org.wildfly.security.password.spec;

import static org.wildfly.common.math.HashMath.multiHashOrdered;

import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays;
import java.util.Objects;

import org.wildfly.common.Assert;

Expand Down Expand Up @@ -60,4 +64,16 @@ public char[] getPassword() {
public AlgorithmParameterSpec getAlgorithmParameterSpec() {
return algorithmParameterSpec;
}

@Override
public boolean equals(Object other) {
if (! (other instanceof EncryptablePasswordSpec)) return false;
EncryptablePasswordSpec o = (EncryptablePasswordSpec) other;
return Arrays.equals(password, o.password) && Objects.equals(algorithmParameterSpec, o.algorithmParameterSpec);
}

@Override
public int hashCode() {
return multiHashOrdered(Arrays.hashCode(password), Objects.hashCode(algorithmParameterSpec));
}
}
Expand Up @@ -18,6 +18,8 @@

package org.wildfly.security.password.spec;

import java.util.Arrays;

import org.wildfly.common.Assert;

/**
Expand Down Expand Up @@ -47,4 +49,14 @@ public HashPasswordSpec(final byte[] digest) {
public byte[] getDigest() {
return digest;
}

@Override
public boolean equals(Object other) {
return other instanceof HashPasswordSpec && Arrays.equals(digest, ((HashPasswordSpec)other).digest);
}

@Override
public int hashCode() {
return Arrays.hashCode(digest);
}
}
Expand Up @@ -17,6 +17,10 @@
*/
package org.wildfly.security.password.spec;

import static org.wildfly.common.math.HashMath.multiHashOrdered;

import java.util.Arrays;

import org.wildfly.common.Assert;

/**
Expand Down Expand Up @@ -59,4 +63,15 @@ public int getIterationCount() {
return this.iterationCount;
}

@Override
public boolean equals(Object other) {
if (! (other instanceof IteratedHashPasswordSpec)) return false;
IteratedHashPasswordSpec o = (IteratedHashPasswordSpec) other;
return Arrays.equals(hash, o.hash) && iterationCount == o.iterationCount;
}

@Override
public int hashCode() {
return multiHashOrdered(Arrays.hashCode(hash), iterationCount);
}
}
Expand Up @@ -17,6 +17,10 @@
*/
package org.wildfly.security.password.spec;

import static org.wildfly.common.math.HashMath.multiHashOrdered;

import java.util.Arrays;

import org.wildfly.common.Assert;

/**
Expand Down Expand Up @@ -71,4 +75,16 @@ public byte[] getSalt() {
public int getIterationCount() {
return this.iterationCount;
}

@Override
public boolean equals(Object other) {
if (! (other instanceof IteratedSaltedHashPasswordSpec)) return false;
IteratedSaltedHashPasswordSpec o = (IteratedSaltedHashPasswordSpec) other;
return Arrays.equals(hash, o.hash) && Arrays.equals(salt, o.salt) && iterationCount == o.iterationCount;
}

@Override
public int hashCode() {
return multiHashOrdered(multiHashOrdered(Arrays.hashCode(hash), Arrays.hashCode(salt)), iterationCount);
}
}
Expand Up @@ -18,6 +18,10 @@

package org.wildfly.security.password.spec;

import static org.wildfly.common.math.HashMath.multiHashOrdered;

import java.util.Arrays;

import org.wildfly.common.Assert;

/**
Expand Down Expand Up @@ -84,4 +88,16 @@ public byte[] getSalt() {
public byte[] getMaskedPasswordBytes() {
return maskedPasswordBytes;
}

@Override
public boolean equals(Object other) {
if (! (other instanceof MaskedPasswordSpec)) return false;
MaskedPasswordSpec o = (MaskedPasswordSpec) other;
return Arrays.equals(initialKeyMaterial, o.initialKeyMaterial) && iterationCount == o.iterationCount && salt == o.salt && maskedPasswordBytes == o.maskedPasswordBytes;
}

@Override
public int hashCode() {
return multiHashOrdered(multiHashOrdered(multiHashOrdered(Arrays.hashCode(initialKeyMaterial), iterationCount), Arrays.hashCode(salt)), Arrays.hashCode(maskedPasswordBytes));
}
}
Expand Up @@ -17,6 +17,11 @@
*/
package org.wildfly.security.password.spec;

import static org.wildfly.common.math.HashMath.multiHashOrdered;

import java.util.Arrays;
import java.util.Objects;

import org.wildfly.common.Assert;

/**
Expand Down Expand Up @@ -71,4 +76,16 @@ public String getSeed() {
public int getSequenceNumber() {
return sequenceNumber;
}

@Override
public boolean equals(Object other) {
if (! (other instanceof OneTimePasswordSpec)) return false;
OneTimePasswordSpec o = (OneTimePasswordSpec) other;
return Arrays.equals(hash, o.hash) && Objects.equals(seed, o.seed) && sequenceNumber == o.sequenceNumber;
}

@Override
public int hashCode() {
return multiHashOrdered(multiHashOrdered(Arrays.hashCode(hash), Objects.hashCode(seed)), sequenceNumber);
}
}
Expand Up @@ -17,6 +17,10 @@
*/
package org.wildfly.security.password.spec;

import static org.wildfly.common.math.HashMath.multiHashOrdered;

import java.util.Arrays;

import org.wildfly.common.Assert;

/**
Expand Down Expand Up @@ -59,4 +63,16 @@ public byte[] getHash() {
public byte[] getSalt() {
return this.salt;
}

@Override
public boolean equals(Object other) {
if (! (other instanceof SaltedHashPasswordSpec)) return false;
SaltedHashPasswordSpec o = (SaltedHashPasswordSpec) other;
return Arrays.equals(hash, o.hash) && Arrays.equals(salt, o.salt);
}

@Override
public int hashCode() {
return multiHashOrdered(Arrays.hashCode(hash), Arrays.hashCode(salt));
}
}