package org.jboss.security.srp;
import java.io.Serializable;
import java.util.Arrays;
import org.jboss.security.Util;
public class SRPParameters implements Cloneable, Serializable
{
private static final long serialVersionUID = 6438772808805276693L;
public final byte[] N;
public final byte[] g;
public final byte[] s;
public final String hashAlgorithm;
public final String cipherAlgorithm;
public byte[] cipherIV;
public SRPParameters(byte[] N, byte[] g, byte[] s)
{
this(N, g, s, "SHA_Interleave", null);
}
public SRPParameters(byte[] N, byte[] g, byte[] s, String hashAlgorithm)
{
this(N, g, s, hashAlgorithm, null);
}
public SRPParameters(byte[] N, byte[] g, byte[] s, String hashAlgorithm,
String cipherAlgorithm)
{
this(N, g, s, hashAlgorithm, cipherAlgorithm, null);
}
public SRPParameters(byte[] N, byte[] g, byte[] s, String hashAlgorithm,
String cipherAlgorithm, byte[] cipherIV)
{
this.N = N;
this.g = g;
this.s = s;
if( hashAlgorithm == null )
hashAlgorithm = "SHA_Interleave";
this.hashAlgorithm = hashAlgorithm;
this.cipherAlgorithm = cipherAlgorithm;
this.cipherIV = cipherIV;
}
public Object clone()
{
Object clone = null;
try
{
clone = super.clone();
}
catch(CloneNotSupportedException e)
{
}
return clone;
}
public int hashCode()
{
int hashCode = hashAlgorithm.hashCode();
for(int i = 0; i < N.length; i ++)
hashCode += N[i];
for(int i = 0; i < g.length; i ++)
hashCode += g[i];
for(int i = 0; i < s.length; i ++)
hashCode += s[i];
return hashCode;
}
public boolean equals(Object obj)
{
boolean equals = false;
if( obj instanceof SRPParameters )
{
SRPParameters p = (SRPParameters) obj;
equals = hashAlgorithm.equals(p.hashAlgorithm);
if( equals == true )
equals = Arrays.equals(N, p.N);
if( equals == true )
equals = Arrays.equals(g, p.g);
if( equals == true )
equals = Arrays.equals(s, p.s);
}
return equals;
}
public String toString()
{
StringBuffer tmp = new StringBuffer(super.toString());
tmp.append('{');
tmp.append("N: ");
tmp.append(Util.encodeBase64(N));
tmp.append("|g: ");
tmp.append(Util.encodeBase64(g));
tmp.append("|s: ");
tmp.append(Util.encodeBase64(s));
tmp.append("|hashAlgorithm: ");
tmp.append(hashAlgorithm);
tmp.append("|cipherAlgorithm: ");
tmp.append(cipherAlgorithm);
tmp.append("|cipherIV: ");
tmp.append(cipherIV);
tmp.append('}');
return tmp.toString();
}
}