package org.bouncycastle.gpg.keybox;

import java.io.IOException;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
import org.bouncycastle.util.Strings;

/* JADX INFO: loaded from: classes2.dex */
public class Blob {
    protected static final byte[] magicBytes = Strings.toByteArray("KBXf");
    protected final int base;
    protected final long length;
    protected final BlobType type;
    protected final int version;

    protected Blob(int i, long j, BlobType blobType, int i2) {
        this.base = i;
        this.length = j;
        this.type = blobType;
        this.version = i2;
    }

    static Blob getInstance(Object obj, KeyFingerPrintCalculator keyFingerPrintCalculator, BlobVerifier blobVerifier) throws IOException {
        if (obj == null) {
            throw new IllegalArgumentException("Cannot take get instance of null");
        }
        KeyBoxByteBuffer keyBoxByteBufferWrap = KeyBoxByteBuffer.wrap(obj);
        if (!keyBoxByteBufferWrap.hasRemaining()) {
            return null;
        }
        int iPosition = keyBoxByteBufferWrap.position();
        long jU32 = keyBoxByteBufferWrap.u32();
        BlobType blobTypeFromByte = BlobType.fromByte(keyBoxByteBufferWrap.u8());
        int iU8 = keyBoxByteBufferWrap.u8();
        switch (blobTypeFromByte) {
            case EMPTY_BLOB:
            default:
                return null;
            case FIRST_BLOB:
                return FirstBlob.parseContent(iPosition, jU32, blobTypeFromByte, iU8, keyBoxByteBufferWrap);
            case X509_BLOB:
                return CertificateBlob.parseContent(iPosition, jU32, blobTypeFromByte, iU8, keyBoxByteBufferWrap, blobVerifier);
            case OPEN_PGP_BLOB:
                return PublicKeyRingBlob.parseContent(iPosition, jU32, blobTypeFromByte, iU8, keyBoxByteBufferWrap, keyFingerPrintCalculator, blobVerifier);
        }
    }

    public BlobType getType() {
        return this.type;
    }

    public int getVersion() {
        return this.version;
    }
}
