103 lines
3.6 KiB
Java
103 lines
3.6 KiB
Java
|
package org.bouncycastle.asn1;
|
||
|
|
||
|
import java.io.ByteArrayInputStream;
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
import org.bouncycastle.util.Arrays;
|
||
|
import org.bouncycastle.util.Strings;
|
||
|
import org.bouncycastle.util.encoders.Hex;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public abstract class ASN1OctetString extends ASN1Primitive implements ASN1OctetStringParser {
|
||
|
byte[] string;
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
||
|
public abstract void encode(ASN1OutputStream aSN1OutputStream) throws IOException;
|
||
|
|
||
|
public ASN1OctetStringParser parser() {
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
public String toString() {
|
||
|
StringBuilder sb = new StringBuilder("#");
|
||
|
sb.append(Strings.fromByteArray(Hex.encode(this.string)));
|
||
|
return sb.toString();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
||
|
public ASN1Primitive toDLObject() {
|
||
|
return new DEROctetString(this.string);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
||
|
public ASN1Primitive toDERObject() {
|
||
|
return new DEROctetString(this.string);
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.asn1.ASN1Primitive, org.bouncycastle.asn1.ASN1Object
|
||
|
public int hashCode() {
|
||
|
return Arrays.hashCode(getOctets());
|
||
|
}
|
||
|
|
||
|
public byte[] getOctets() {
|
||
|
return this.string;
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.asn1.ASN1OctetStringParser
|
||
|
public InputStream getOctetStream() {
|
||
|
return new ByteArrayInputStream(this.string);
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.asn1.InMemoryRepresentable
|
||
|
public ASN1Primitive getLoadedObject() {
|
||
|
return toASN1Primitive();
|
||
|
}
|
||
|
|
||
|
@Override // org.bouncycastle.asn1.ASN1Primitive
|
||
|
boolean asn1Equals(ASN1Primitive aSN1Primitive) {
|
||
|
if (aSN1Primitive instanceof ASN1OctetString) {
|
||
|
return Arrays.areEqual(this.string, ((ASN1OctetString) aSN1Primitive).string);
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static ASN1OctetString getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) {
|
||
|
ASN1Primitive object = aSN1TaggedObject.getObject();
|
||
|
return (z || (object instanceof ASN1OctetString)) ? getInstance(object) : BEROctetString.fromSequence(ASN1Sequence.getInstance(object));
|
||
|
}
|
||
|
|
||
|
public static ASN1OctetString getInstance(Object obj) {
|
||
|
if (obj == null || (obj instanceof ASN1OctetString)) {
|
||
|
return (ASN1OctetString) obj;
|
||
|
}
|
||
|
if (obj instanceof byte[]) {
|
||
|
try {
|
||
|
return getInstance(ASN1Primitive.fromByteArray((byte[]) obj));
|
||
|
} catch (IOException e) {
|
||
|
StringBuilder sb = new StringBuilder("failed to construct OCTET STRING from byte[]: ");
|
||
|
sb.append(e.getMessage());
|
||
|
throw new IllegalArgumentException(sb.toString());
|
||
|
}
|
||
|
}
|
||
|
if (obj instanceof ASN1Encodable) {
|
||
|
ASN1Primitive aSN1Primitive = ((ASN1Encodable) obj).toASN1Primitive();
|
||
|
if (aSN1Primitive instanceof ASN1OctetString) {
|
||
|
return (ASN1OctetString) aSN1Primitive;
|
||
|
}
|
||
|
}
|
||
|
StringBuilder sb2 = new StringBuilder("illegal object in getInstance: ");
|
||
|
sb2.append(obj.getClass().getName());
|
||
|
throw new IllegalArgumentException(sb2.toString());
|
||
|
}
|
||
|
|
||
|
public ASN1OctetString(byte[] bArr) {
|
||
|
if (bArr == null) {
|
||
|
throw new NullPointerException("string cannot be null");
|
||
|
}
|
||
|
this.string = bArr;
|
||
|
}
|
||
|
}
|