/*
* This file is part of rockframework.
*
* rockframework is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* rockframework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>;.
*/
package br.net.woodstock.rockframework.security;
import java.io.Serializable;
import java.security.PrivateKey;
import java.security.cert.Certificate;
import br.net.woodstock.rockframework.core.RockFrameworkVersion;
import br.net.woodstock.rockframework.core.util.Assert;
import br.net.woodstock.rockframework.core.util.EqualsBuilder;
import br.net.woodstock.rockframework.core.util.HashCodeBuilder;
import br.net.woodstock.rockframework.core.util.ToStringBuilder;
public class Identity implements Serializable {
private static final long serialVersionUID = RockFrameworkVersion.VERSION;
private PrivateKey privateKey;
private Certificate[] chain;
public Identity(final PrivateKey privateKey, final Certificate[] chain) {
super();
Assert.notNull(privateKey, "privateKey");
Assert.notEmpty(chain, "chain");
this.privateKey = privateKey;
this.chain = chain;
}
public PrivateKey getPrivateKey() {
return this.privateKey;
}
public Certificate[] getChain() {
return this.chain;
}
@Override
public int hashCode() {
return new HashCodeBuilder().add(this.getPrivateKey()).add(this.getChain()).build().intValue();
}
@Override
public boolean equals(final Object obj) {
if (!(obj instanceof Identity)) {
return false;
}
Identity other = (Identity) obj;
return new EqualsBuilder().add(this.getPrivateKey(), other.getPrivateKey()).add(this.getChain(), other.getChain()).build().booleanValue();
}
@Override
public String toString() {
return new ToStringBuilder(this.getClass()).add("privateKey", this.getPrivateKey()).build();
}
}