what-the-bank/sources/org/bouncycastle/asn1/ASN1Boolean.java

110 lines
3.8 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.asn1;
import com.google.common.primitives.UnsignedBytes;
import java.io.IOException;
import org.bouncycastle.util.Arrays;
/* loaded from: classes6.dex */
public class ASN1Boolean extends ASN1Primitive {
private final byte[] value;
private static final byte[] TRUE_VALUE = {-1};
private static final byte[] FALSE_VALUE = {0};
public static final ASN1Boolean FALSE = new ASN1Boolean(false);
public static final ASN1Boolean TRUE = new ASN1Boolean(true);
/* JADX INFO: Access modifiers changed from: package-private */
@Override // org.bouncycastle.asn1.ASN1Primitive
public int encodedLength() {
return 3;
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // org.bouncycastle.asn1.ASN1Primitive
public boolean isConstructed() {
return false;
}
public String toString() {
return this.value[0] != 0 ? "TRUE" : "FALSE";
}
public boolean isTrue() {
return this.value[0] != 0;
}
@Override // org.bouncycastle.asn1.ASN1Primitive, org.bouncycastle.asn1.ASN1Object
public int hashCode() {
return this.value[0];
}
/* JADX INFO: Access modifiers changed from: package-private */
@Override // org.bouncycastle.asn1.ASN1Primitive
public void encode(ASN1OutputStream aSN1OutputStream) throws IOException {
aSN1OutputStream.writeEncoded(1, this.value);
}
@Override // org.bouncycastle.asn1.ASN1Primitive
protected boolean asn1Equals(ASN1Primitive aSN1Primitive) {
return (aSN1Primitive instanceof ASN1Boolean) && this.value[0] == ((ASN1Boolean) aSN1Primitive).value[0];
}
public static ASN1Boolean getInstance(boolean z) {
return z ? TRUE : FALSE;
}
public static ASN1Boolean getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) {
ASN1Primitive object = aSN1TaggedObject.getObject();
return (z || (object instanceof ASN1Boolean)) ? getInstance(object) : fromOctetString(((ASN1OctetString) object).getOctets());
}
public static ASN1Boolean getInstance(Object obj) {
if (obj == null || (obj instanceof ASN1Boolean)) {
return (ASN1Boolean) 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 (ASN1Boolean) fromByteArray((byte[]) obj);
} catch (IOException e) {
StringBuilder sb2 = new StringBuilder("failed to construct boolean from byte[]: ");
sb2.append(e.getMessage());
throw new IllegalArgumentException(sb2.toString());
}
}
public static ASN1Boolean getInstance(int i) {
return i != 0 ? TRUE : FALSE;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static ASN1Boolean fromOctetString(byte[] bArr) {
if (bArr.length != 1) {
throw new IllegalArgumentException("BOOLEAN value should have 1 byte in it");
}
byte b = bArr[0];
return b == 0 ? FALSE : (b & UnsignedBytes.MAX_VALUE) == 255 ? TRUE : new ASN1Boolean(bArr);
}
/* JADX INFO: Access modifiers changed from: package-private */
public ASN1Boolean(byte[] bArr) {
if (bArr.length != 1) {
throw new IllegalArgumentException("byte value should have 1 byte in it");
}
byte b = bArr[0];
if (b == 0) {
this.value = FALSE_VALUE;
} else if ((b & UnsignedBytes.MAX_VALUE) == 255) {
this.value = TRUE_VALUE;
} else {
this.value = Arrays.clone(bArr);
}
}
public ASN1Boolean(boolean z) {
this.value = z ? TRUE_VALUE : FALSE_VALUE;
}
}