105 lines
3.7 KiB
Java
105 lines
3.7 KiB
Java
package org.bouncycastle.asn1;
|
|
|
|
import com.google.common.primitives.UnsignedBytes;
|
|
import java.io.IOException;
|
|
import java.math.BigInteger;
|
|
import org.bouncycastle.util.Arrays;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class ASN1Enumerated extends ASN1Primitive {
|
|
private static ASN1Enumerated[] cache = new ASN1Enumerated[12];
|
|
private final byte[] bytes;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
public boolean isConstructed() {
|
|
return false;
|
|
}
|
|
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive, org.bouncycastle.asn1.ASN1Object
|
|
public int hashCode() {
|
|
return Arrays.hashCode(this.bytes);
|
|
}
|
|
|
|
public BigInteger getValue() {
|
|
return new BigInteger(this.bytes);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
public int encodedLength() {
|
|
return StreamUtil.calculateBodyLength(this.bytes.length) + 1 + this.bytes.length;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
public void encode(ASN1OutputStream aSN1OutputStream) throws IOException {
|
|
aSN1OutputStream.writeEncoded(10, this.bytes);
|
|
}
|
|
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
boolean asn1Equals(ASN1Primitive aSN1Primitive) {
|
|
if (aSN1Primitive instanceof ASN1Enumerated) {
|
|
return Arrays.areEqual(this.bytes, ((ASN1Enumerated) aSN1Primitive).bytes);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static ASN1Enumerated getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) {
|
|
ASN1Primitive object = aSN1TaggedObject.getObject();
|
|
return (z || (object instanceof ASN1Enumerated)) ? getInstance(object) : fromOctetString(((ASN1OctetString) object).getOctets());
|
|
}
|
|
|
|
public static ASN1Enumerated getInstance(Object obj) {
|
|
if (obj == null || (obj instanceof ASN1Enumerated)) {
|
|
return (ASN1Enumerated) obj;
|
|
}
|
|
if (!(obj instanceof byte[])) {
|
|
StringBuilder sb = new StringBuilder("illegal object in getInstance: ");
|
|
sb.append(obj.getClass().getName());
|
|
throw new IllegalArgumentException(sb.toString());
|
|
}
|
|
try {
|
|
return (ASN1Enumerated) fromByteArray((byte[]) obj);
|
|
} catch (Exception e) {
|
|
StringBuilder sb2 = new StringBuilder("encoding error in getInstance: ");
|
|
sb2.append(e.toString());
|
|
throw new IllegalArgumentException(sb2.toString());
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static ASN1Enumerated fromOctetString(byte[] bArr) {
|
|
if (bArr.length > 1) {
|
|
return new ASN1Enumerated(bArr);
|
|
}
|
|
if (bArr.length == 0) {
|
|
throw new IllegalArgumentException("ENUMERATED has zero length");
|
|
}
|
|
int i = bArr[0] & UnsignedBytes.MAX_VALUE;
|
|
ASN1Enumerated[] aSN1EnumeratedArr = cache;
|
|
if (i >= aSN1EnumeratedArr.length) {
|
|
return new ASN1Enumerated(Arrays.clone(bArr));
|
|
}
|
|
ASN1Enumerated aSN1Enumerated = aSN1EnumeratedArr[i];
|
|
if (aSN1Enumerated != null) {
|
|
return aSN1Enumerated;
|
|
}
|
|
ASN1Enumerated aSN1Enumerated2 = new ASN1Enumerated(Arrays.clone(bArr));
|
|
aSN1EnumeratedArr[i] = aSN1Enumerated2;
|
|
return aSN1Enumerated2;
|
|
}
|
|
|
|
public ASN1Enumerated(byte[] bArr) {
|
|
this.bytes = Arrays.clone(bArr);
|
|
}
|
|
|
|
public ASN1Enumerated(BigInteger bigInteger) {
|
|
this.bytes = bigInteger.toByteArray();
|
|
}
|
|
|
|
public ASN1Enumerated(int i) {
|
|
this.bytes = BigInteger.valueOf(i).toByteArray();
|
|
}
|
|
}
|