// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.jcajce.spec;

import org.bouncycastle.util.Strings;
import org.bouncycastle.util.Arrays;
import java.security.spec.EncodedKeySpec;

public class OpenSSHPublicKeySpec extends EncodedKeySpec
{
    private static final String[] allowedTypes;
    private final String type;
    
    public OpenSSHPublicKeySpec(final byte[] encodedKey) {
        super(encodedKey);
        int n = 0;
        final int n2 = (encodedKey[n++] & 0xFF) << 24 | (encodedKey[n++] & 0xFF) << 16 | (encodedKey[n++] & 0xFF) << 8 | (encodedKey[n++] & 0xFF);
        if (n + n2 >= encodedKey.length) {
            throw new IllegalArgumentException("invalid public key blob: type field longer than blob");
        }
        this.type = Strings.fromByteArray(Arrays.copyOfRange(encodedKey, n, n + n2));
        if (this.type.startsWith("ecdsa")) {
            return;
        }
        for (int i = 0; i < OpenSSHPublicKeySpec.allowedTypes.length; ++i) {
            if (OpenSSHPublicKeySpec.allowedTypes[i].equals(this.type)) {
                return;
            }
        }
        throw new IllegalArgumentException("unrecognised public key type " + this.type);
    }
    
    @Override
    public String getFormat() {
        return "OpenSSH";
    }
    
    public String getType() {
        return this.type;
    }
    
    static {
        allowedTypes = new String[] { "ssh-rsa", "ssh-ed25519", "ssh-dss" };
    }
}
