what-the-bank/sources/org/bouncycastle/asn1/cms/CMSAlgorithmProtection.java

91 lines
3.6 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.asn1.cms;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.ASN1TaggedObject;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.DERTaggedObject;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
/* loaded from: classes6.dex */
public class CMSAlgorithmProtection extends ASN1Object {
public static final int MAC = 2;
public static final int SIGNATURE = 1;
private final AlgorithmIdentifier digestAlgorithm;
private final AlgorithmIdentifier macAlgorithm;
private final AlgorithmIdentifier signatureAlgorithm;
@Override // org.bouncycastle.asn1.ASN1Object, org.bouncycastle.asn1.ASN1Encodable
public ASN1Primitive toASN1Primitive() {
ASN1EncodableVector aSN1EncodableVector = new ASN1EncodableVector();
aSN1EncodableVector.add(this.digestAlgorithm);
if (this.signatureAlgorithm != null) {
aSN1EncodableVector.add(new DERTaggedObject(false, 1, this.signatureAlgorithm));
}
if (this.macAlgorithm != null) {
aSN1EncodableVector.add(new DERTaggedObject(false, 2, this.macAlgorithm));
}
return new DERSequence(aSN1EncodableVector);
}
public AlgorithmIdentifier getSignatureAlgorithm() {
return this.signatureAlgorithm;
}
public AlgorithmIdentifier getMacAlgorithm() {
return this.macAlgorithm;
}
public AlgorithmIdentifier getDigestAlgorithm() {
return this.digestAlgorithm;
}
public static CMSAlgorithmProtection getInstance(Object obj) {
if (obj instanceof CMSAlgorithmProtection) {
return (CMSAlgorithmProtection) obj;
}
if (obj != null) {
return new CMSAlgorithmProtection(ASN1Sequence.getInstance(obj));
}
return null;
}
public CMSAlgorithmProtection(AlgorithmIdentifier algorithmIdentifier, int i, AlgorithmIdentifier algorithmIdentifier2) {
if (algorithmIdentifier == null || algorithmIdentifier2 == null) {
throw new NullPointerException("AlgorithmIdentifiers cannot be null");
}
this.digestAlgorithm = algorithmIdentifier;
if (i == 1) {
this.signatureAlgorithm = algorithmIdentifier2;
this.macAlgorithm = null;
} else {
if (i != 2) {
throw new IllegalArgumentException("Unknown type: ".concat(String.valueOf(i)));
}
this.signatureAlgorithm = null;
this.macAlgorithm = algorithmIdentifier2;
}
}
private CMSAlgorithmProtection(ASN1Sequence aSN1Sequence) {
if (aSN1Sequence.size() != 2) {
throw new IllegalArgumentException("Sequence wrong size: One of signatureAlgorithm or macAlgorithm must be present");
}
this.digestAlgorithm = AlgorithmIdentifier.getInstance(aSN1Sequence.getObjectAt(0));
ASN1TaggedObject aSN1TaggedObject = ASN1TaggedObject.getInstance(aSN1Sequence.getObjectAt(1));
if (aSN1TaggedObject.getTagNo() == 1) {
this.signatureAlgorithm = AlgorithmIdentifier.getInstance(aSN1TaggedObject, false);
this.macAlgorithm = null;
} else if (aSN1TaggedObject.getTagNo() == 2) {
this.signatureAlgorithm = null;
this.macAlgorithm = AlgorithmIdentifier.getInstance(aSN1TaggedObject, false);
} else {
StringBuilder sb = new StringBuilder("Unknown tag found: ");
sb.append(aSN1TaggedObject.getTagNo());
throw new IllegalArgumentException(sb.toString());
}
}
}