package com.atlassian.bitbucket.mesh.auth;

import com.atlassian.bitbucket.mesh.util.KeyUtils;

import javax.annotation.Nonnull;
import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.PublicKey;

import static java.util.Objects.requireNonNull;

public class SimpleSigningKey implements SigningKey {

    private final String fingerprint;
    private final PublicKey publicKey;
    private final PrivateKey privateKey;

    public SimpleSigningKey(@Nonnull KeyPair keyPair) {
        publicKey = requireNonNull(keyPair, "keyPair").getPublic();
        privateKey = keyPair.getPrivate();
        fingerprint = KeyUtils.getFingerprint(publicKey);
    }

    @Nonnull
    @Override
    public String getFingerprint() {
        return fingerprint;
    }

    @Nonnull
    @Override
    public PrivateKey getPrivate() {
        return privateKey;
    }

    @Nonnull
    @Override
    public PublicKey getPublic() {
        return publicKey;
    }
}
