use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.
the class X509Name method equals.
/**
* test for equality - note: case is ignored.
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof X509Name || obj instanceof ASN1Sequence)) {
return false;
}
ASN1Primitive derO = ((ASN1Encodable) obj).toASN1Primitive();
if (this.toASN1Primitive().equals(derO)) {
return true;
}
X509Name other;
try {
other = X509Name.getInstance(obj);
} catch (IllegalArgumentException e) {
return false;
}
int orderingSize = ordering.size();
if (orderingSize != other.ordering.size()) {
return false;
}
boolean[] indexes = new boolean[orderingSize];
int start, end, delta;
if (// guess forward
ordering.elementAt(0).equals(other.ordering.elementAt(0))) {
start = 0;
end = orderingSize;
delta = 1;
} else // guess reversed - most common problem
{
start = orderingSize - 1;
end = -1;
delta = -1;
}
for (int i = start; i != end; i += delta) {
boolean found = false;
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) ordering.elementAt(i);
String value = (String) values.elementAt(i);
for (int j = 0; j < orderingSize; j++) {
if (indexes[j]) {
continue;
}
ASN1ObjectIdentifier oOid = (ASN1ObjectIdentifier) other.ordering.elementAt(j);
if (oid.equals(oOid)) {
String oValue = (String) other.values.elementAt(j);
if (equivalentStrings(value, oValue)) {
indexes[j] = true;
found = true;
break;
}
}
}
if (!found) {
return false;
}
}
return true;
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.
the class DefaultSignatureNameFinder method getAlgorithmName.
/**
* Return the signature name for the passed in algorithm identifier. For signatures
* that require parameters, like RSASSA-PSS, this is the best one to use.
*
* @param algorithmIdentifier the AlgorithmIdentifier of interest.
* @return a string representation of the name.
*/
public String getAlgorithmName(AlgorithmIdentifier algorithmIdentifier) {
ASN1Encodable params = algorithmIdentifier.getParameters();
if (params != null && !DERNull.INSTANCE.equals(params)) {
if (algorithmIdentifier.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) {
RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);
AlgorithmIdentifier mgfAlg = rsaParams.getMaskGenAlgorithm();
if (mgfAlg.getAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1)) {
AlgorithmIdentifier digAlg = rsaParams.getHashAlgorithm();
ASN1ObjectIdentifier mgfHashOid = AlgorithmIdentifier.getInstance(mgfAlg.getParameters()).getAlgorithm();
if (mgfHashOid.equals(digAlg.getAlgorithm())) {
return getDigestName(digAlg.getAlgorithm()) + "WITHRSAANDMGF1";
} else {
return getDigestName(digAlg.getAlgorithm()) + "WITHRSAANDMGF1USING" + getDigestName(mgfHashOid);
}
}
return getDigestName(rsaParams.getHashAlgorithm().getAlgorithm()) + "WITHRSAAND" + mgfAlg.getAlgorithm().getId();
}
}
if (oids.containsKey(algorithmIdentifier.getAlgorithm())) {
return (String) oids.get(algorithmIdentifier.getAlgorithm());
}
return algorithmIdentifier.getAlgorithm().getId();
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.
the class CMSUtils method getOthersFromStore.
static Collection getOthersFromStore(ASN1ObjectIdentifier otherRevocationInfoFormat, Store otherRevocationInfos) {
List others = new ArrayList();
for (Iterator it = otherRevocationInfos.getMatches(null).iterator(); it.hasNext(); ) {
ASN1Encodable info = (ASN1Encodable) it.next();
OtherRevocationInfoFormat infoFormat = new OtherRevocationInfoFormat(otherRevocationInfoFormat, info);
validateInfoFormat(infoFormat);
others.add(new DERTaggedObject(false, 1, infoFormat));
}
return others;
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.
the class CMSUtils method isEquivalent.
static boolean isEquivalent(AlgorithmIdentifier algId1, AlgorithmIdentifier algId2) {
if (algId1 == null || algId2 == null) {
return false;
}
if (!algId1.getAlgorithm().equals(algId2.getAlgorithm())) {
return false;
}
ASN1Encodable params1 = algId1.getParameters();
ASN1Encodable params2 = algId2.getParameters();
if (params1 != null) {
return params1.equals(params2) || (params1.equals(DERNull.INSTANCE) && params2 == null);
}
return params2 == null || params2.equals(DERNull.INSTANCE);
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project jmulticard by ctt-gob-es.
the class PKCS7ProcessableObject method write.
public void write(OutputStream cOut) throws IOException, CMSException {
if (structure instanceof ASN1Sequence) {
ASN1Sequence s = ASN1Sequence.getInstance(structure);
for (Iterator it = s.iterator(); it.hasNext(); ) {
ASN1Encodable enc = (ASN1Encodable) it.next();
cOut.write(enc.toASN1Primitive().getEncoded(ASN1Encoding.DER));
}
} else {
byte[] encoded = structure.toASN1Primitive().getEncoded(ASN1Encoding.DER);
int index = 1;
while ((encoded[index] & 0xff) > 127) {
index++;
}
index++;
cOut.write(encoded, index, encoded.length - index);
}
}
Aggregations