104 lines
3.3 KiB
Java
104 lines
3.3 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 ASN1Integer extends ASN1Primitive {
|
|
private final byte[] bytes;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
public boolean isConstructed() {
|
|
return false;
|
|
}
|
|
|
|
public String toString() {
|
|
return getValue().toString();
|
|
}
|
|
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive, org.bouncycastle.asn1.ASN1Object
|
|
public int hashCode() {
|
|
int i = 0;
|
|
int i2 = 0;
|
|
while (true) {
|
|
byte[] bArr = this.bytes;
|
|
if (i == bArr.length) {
|
|
return i2;
|
|
}
|
|
i2 ^= (bArr[i] & UnsignedBytes.MAX_VALUE) << (i % 4);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
public BigInteger getValue() {
|
|
return new BigInteger(this.bytes);
|
|
}
|
|
|
|
public BigInteger getPositiveValue() {
|
|
return new BigInteger(1, 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(2, this.bytes);
|
|
}
|
|
|
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
|
boolean asn1Equals(ASN1Primitive aSN1Primitive) {
|
|
if (aSN1Primitive instanceof ASN1Integer) {
|
|
return Arrays.areEqual(this.bytes, ((ASN1Integer) aSN1Primitive).bytes);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static ASN1Integer getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) {
|
|
ASN1Primitive object = aSN1TaggedObject.getObject();
|
|
return (z || (object instanceof ASN1Integer)) ? getInstance(object) : new ASN1Integer(ASN1OctetString.getInstance(aSN1TaggedObject.getObject()).getOctets());
|
|
}
|
|
|
|
public static ASN1Integer getInstance(Object obj) {
|
|
if (obj == null || (obj instanceof ASN1Integer)) {
|
|
return (ASN1Integer) 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 (ASN1Integer) 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 ASN1Integer(byte[] bArr, boolean z) {
|
|
this.bytes = z ? Arrays.clone(bArr) : bArr;
|
|
}
|
|
|
|
public ASN1Integer(byte[] bArr) {
|
|
this(bArr, true);
|
|
}
|
|
|
|
public ASN1Integer(BigInteger bigInteger) {
|
|
this.bytes = bigInteger.toByteArray();
|
|
}
|
|
|
|
public ASN1Integer(long j) {
|
|
this.bytes = BigInteger.valueOf(j).toByteArray();
|
|
}
|
|
}
|