class KeyDataUtil {

    public static KeyData marshal(final ConfigKeyPair keyPair) {

        final KeyData keyData = new KeyData();

        if (DirectKeyPair.class.isInstance(keyPair)) {
            DirectKeyPair kp = DirectKeyPair.class.cast(keyPair);
            keyData.setPublicKey(kp.getPublicKey());
            keyData.setPrivateKey(kp.getPrivateKey());
            return keyData;
        }

        if (InlineKeypair.class.isInstance(keyPair)) {
            InlineKeypair kp = InlineKeypair.class.cast(keyPair);
            keyData.setPublicKey(kp.getPublicKey());
            keyData.setConfig(kp.getPrivateKeyConfig());
            return keyData;
        }

        if (AzureVaultKeyPair.class.isInstance(keyPair)) {
            AzureVaultKeyPair kp = AzureVaultKeyPair.class.cast(keyPair);

            keyData.setAzureVaultPublicKeyId(kp.getPublicKeyId());
            keyData.setAzureVaultPrivateKeyId(kp.getPrivateKeyId());
            keyData.setAzureVaultPublicKeyVersion(kp.getPublicKeyVersion());
            keyData.setAzureVaultPrivateKeyVersion(kp.getPrivateKeyVersion());
            return keyData;
        }

        if (HashicorpVaultKeyPair.class.isInstance(keyPair)) {
            HashicorpVaultKeyPair kp = HashicorpVaultKeyPair.class.cast(keyPair);
            keyData.setHashicorpVaultPublicKeyId(kp.getPublicKeyId());
            keyData.setHashicorpVaultPrivateKeyId(kp.getPrivateKeyId());
            keyData.setHashicorpVaultSecretEngineName(kp.getSecretEngineName());
            keyData.setHashicorpVaultSecretName(kp.getSecretName());

            keyData.setHashicorpVaultSecretVersion(Objects.toString(kp.getSecretVersion(), null));
            return keyData;
        }

        if (AWSKeyPair.class.isInstance(keyPair)) {
            AWSKeyPair kp = AWSKeyPair.class.cast(keyPair);
            keyData.setAwsSecretsManagerPublicKeyId(kp.getPublicKeyId());
            keyData.setAwsSecretsManagerPrivateKeyId(kp.getPrivateKeyId());
            return keyData;
        }

        if (FilesystemKeyPair.class.isInstance(keyPair)) {
            FilesystemKeyPair kp = FilesystemKeyPair.class.cast(keyPair);
            keyData.setPublicKeyPath(kp.getPublicKeyPath());
            keyData.setPrivateKeyPath(kp.getPrivateKeyPath());
            return keyData;
        }

        if (UnsupportedKeyPair.class.isInstance(keyPair)) {
            UnsupportedKeyPair kp = UnsupportedKeyPair.class.cast(keyPair);
            return new KeyData(
                    kp.getConfig(),
                    kp.getPrivateKey(),
                    kp.getPublicKey(),
                    kp.getPrivateKeyPath(),
                    kp.getPublicKeyPath(),
                    kp.getAzureVaultPrivateKeyId(),
                    kp.getAzureVaultPublicKeyId(),
                    kp.getAzureVaultPublicKeyVersion(),
                    kp.getAzureVaultPrivateKeyVersion(),
                    kp.getHashicorpVaultPrivateKeyId(),
                    kp.getHashicorpVaultPublicKeyId(),
                    kp.getHashicorpVaultSecretEngineName(),
                    kp.getHashicorpVaultSecretName(),
                    kp.getHashicorpVaultSecretVersion(),
                    kp.getAwsSecretsManagerPublicKeyId(),
                    kp.getAwsSecretsManagerPrivateKeyId());
        }

        throw new UnsupportedOperationException("The keypair type " + keyPair.getClass() + " is not allowed");
    }

    private  KeyDataUtil();

}