All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkiverse.githubapp.runtime.config.PrivateKeyConverter Maven / Gradle / Ivy

There is a newer version: 2.7.0
Show newest version
package io.quarkiverse.githubapp.runtime.config;

import static io.quarkus.runtime.configuration.ConverterSupport.DEFAULT_QUARKUS_CONVERTER_PRIORITY;

import java.io.Serializable;
import java.security.GeneralSecurityException;
import java.security.PrivateKey;

import jakarta.annotation.Priority;

import org.eclipse.microprofile.config.spi.Converter;

import io.quarkiverse.githubapp.runtime.signing.PrivateKeyUtil;
import io.quarkus.runtime.configuration.ConfigurationException;

@Priority(DEFAULT_QUARKUS_CONVERTER_PRIORITY)
public class PrivateKeyConverter implements Converter, Serializable {

    public PrivateKeyConverter() {
    }

    @Override
    public PrivateKey convert(final String value) {
        String privateKeyValue = value.trim();

        if (privateKeyValue.isEmpty()) {
            return null;
        }

        try {
            return PrivateKeyUtil.loadKey(privateKeyValue);
        } catch (GeneralSecurityException e) {
            throw new ConfigurationException("Unable to interpret the provided private key", e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy