package org.bouncycastle.asn1.x509; import java.io.IOException; import java.util.Hashtable; import java.util.Vector; import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1Encoding; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.DEROctetString; /* loaded from: classes6.dex */ public class ExtensionsGenerator { private Hashtable extensions = new Hashtable(); private Vector extOrdering = new Vector(); public void reset() { this.extensions = new Hashtable(); this.extOrdering = new Vector(); } public boolean isEmpty() { return this.extOrdering.isEmpty(); } public Extensions generate() { Extension[] extensionArr = new Extension[this.extOrdering.size()]; for (int i = 0; i != this.extOrdering.size(); i++) { extensionArr[i] = (Extension) this.extensions.get(this.extOrdering.elementAt(i)); } return new Extensions(extensionArr); } public void addExtension(Extension extension) { if (!this.extensions.containsKey(extension.getExtnId())) { this.extOrdering.addElement(extension.getExtnId()); this.extensions.put(extension.getExtnId(), extension); } else { StringBuilder sb = new StringBuilder("extension "); sb.append(extension.getExtnId()); sb.append(" already added"); throw new IllegalArgumentException(sb.toString()); } } public void addExtension(ASN1ObjectIdentifier aSN1ObjectIdentifier, boolean z, byte[] bArr) { if (!this.extensions.containsKey(aSN1ObjectIdentifier)) { this.extOrdering.addElement(aSN1ObjectIdentifier); this.extensions.put(aSN1ObjectIdentifier, new Extension(aSN1ObjectIdentifier, z, new DEROctetString(bArr))); } else { StringBuilder sb = new StringBuilder("extension "); sb.append(aSN1ObjectIdentifier); sb.append(" already added"); throw new IllegalArgumentException(sb.toString()); } } public void addExtension(ASN1ObjectIdentifier aSN1ObjectIdentifier, boolean z, ASN1Encodable aSN1Encodable) throws IOException { addExtension(aSN1ObjectIdentifier, z, aSN1Encodable.toASN1Primitive().getEncoded(ASN1Encoding.DER)); } }