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

package org.bouncycastle.jcajce.provider.asymmetric.edec;

import org.bouncycastle.crypto.util.PrivateKeyFactory;
import java.security.PrivateKey;
import org.bouncycastle.crypto.util.PublicKeyFactory;
import java.security.InvalidKeyException;
import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
import java.security.PublicKey;

class EdECUtil
{
    public static AsymmetricKeyParameter generatePublicKeyParameter(final PublicKey publicKey) throws InvalidKeyException {
        if (publicKey instanceof BCXDHPublicKey) {
            return ((BCXDHPublicKey)publicKey).engineGetKeyParameters();
        }
        if (publicKey instanceof BCEdDSAPublicKey) {
            return ((BCEdDSAPublicKey)publicKey).engineGetKeyParameters();
        }
        try {
            final byte[] encoded = publicKey.getEncoded();
            if (encoded == null) {
                throw new InvalidKeyException("no encoding for EdEC/XDH public key");
            }
            return PublicKeyFactory.createKey(encoded);
        }
        catch (final Exception ex) {
            throw new InvalidKeyException("cannot identify EdEC/XDH public key: " + ex.getMessage());
        }
    }
    
    public static AsymmetricKeyParameter generatePrivateKeyParameter(final PrivateKey privateKey) throws InvalidKeyException {
        if (privateKey instanceof BCXDHPrivateKey) {
            return ((BCXDHPrivateKey)privateKey).engineGetKeyParameters();
        }
        if (privateKey instanceof BCEdDSAPrivateKey) {
            return ((BCEdDSAPrivateKey)privateKey).engineGetKeyParameters();
        }
        try {
            final byte[] encoded = privateKey.getEncoded();
            if (encoded == null) {
                throw new InvalidKeyException("no encoding for EdEC/XDH private key");
            }
            return PrivateKeyFactory.createKey(encoded);
        }
        catch (final Exception ex) {
            throw new InvalidKeyException("cannot identify EdEC/XDH private key: " + ex.getMessage());
        }
    }
}
