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 DERBMPString extends ASN1Primitive implements ASN1String { private final char[] string; /* JADX INFO: Access modifiers changed from: package-private */ @Override // org.bouncycastle.asn1.ASN1Primitive public boolean isConstructed() { return false; } public String toString() { return getString(); } @Override // org.bouncycastle.asn1.ASN1Primitive, org.bouncycastle.asn1.ASN1Object public int hashCode() { return Arrays.hashCode(this.string); } @Override // org.bouncycastle.asn1.ASN1String public String getString() { return new String(this.string); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // org.bouncycastle.asn1.ASN1Primitive public int encodedLength() { return StreamUtil.calculateBodyLength(this.string.length << 1) + 1 + (this.string.length << 1); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // org.bouncycastle.asn1.ASN1Primitive public void encode(ASN1OutputStream aSN1OutputStream) throws IOException { aSN1OutputStream.write(30); aSN1OutputStream.writeLength(this.string.length << 1); int i = 0; while (true) { char[] cArr = this.string; if (i == cArr.length) { return; } char c = cArr[i]; aSN1OutputStream.write((byte) (c >> '\b')); aSN1OutputStream.write((byte) c); i++; } } @Override // org.bouncycastle.asn1.ASN1Primitive protected boolean asn1Equals(ASN1Primitive aSN1Primitive) { if (aSN1Primitive instanceof DERBMPString) { return Arrays.areEqual(this.string, ((DERBMPString) aSN1Primitive).string); } return false; } public static DERBMPString getInstance(ASN1TaggedObject aSN1TaggedObject, boolean z) { ASN1Primitive object = aSN1TaggedObject.getObject(); return (z || (object instanceof DERBMPString)) ? getInstance(object) : new DERBMPString(ASN1OctetString.getInstance(object).getOctets()); } public static DERBMPString getInstance(Object obj) { if (obj == null || (obj instanceof DERBMPString)) { return (DERBMPString) 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 (DERBMPString) 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 DERBMPString(char[] cArr) { this.string = cArr; } DERBMPString(byte[] bArr) { int length = bArr.length / 2; char[] cArr = new char[length]; for (int i = 0; i != length; i++) { int i2 = i << 1; cArr[i] = (char) ((bArr[i2 + 1] & UnsignedBytes.MAX_VALUE) | (bArr[i2] << 8)); } this.string = cArr; } public DERBMPString(String str) { this.string = str.toCharArray(); } }