private static final class PublicKeyComparator implements Comparator<PublicKey> {
public int compare(PublicKey a, PublicKey b) {
if (a instanceof DSAPublicKey) {
if (b instanceof DSAPublicKey) {
DSAPublicKey da = (DSAPublicKey) a;
DSAPublicKey db = (DSAPublicKey) b;
int r = da.getParams().getG().compareTo(db.getParams().getG());
if (r != 0) {
return r;
}
r = da.getParams().getP().compareTo(db.getParams().getP());
if (r != 0) {
return r;
}
r = da.getParams().getQ().compareTo(db.getParams().getQ());
if (r != 0) {
return r;
}
return da.getY().compareTo(db.getY());
} else {
return -1;
}
} else if (a instanceof RSAPublicKey) {
if (b instanceof RSAPublicKey) {
RSAPublicKey da = (RSAPublicKey) a;
RSAPublicKey db = (RSAPublicKey) b;
int r = da.getPublicExponent().compareTo(db.getPublicExponent());
if (r != 0) {
return r;
}
return da.getModulus().compareTo(db.getModulus());
} else {
return -1;
}
} else {
throw new IllegalArgumentException("Only RSA and DAS keys are supported.");