package be.iminds.ilabt.jfed.lowlevel.ssh_key_info;

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

/**
 * Ssh Key info. This offers access to various info needed for SSH.
 * Sometimes, this might require making temporary files.
 * */
public interface SshKeyInfo {

    /**
     * @return Does this SSH key info have access to the unencrypted private key?
     */
    boolean hasUnencryptedPrivateKey();

    /**
     * @return Whether the private key is available and encrypted.
     * The return value of this function is undefined when no private key is available.
     */
    boolean isLocked();

    /**
     * @param password  to unlock the file
     * @return whether the unlocking of the file succeeded
     * @throws IllegalStateException Thrown when you try to unlock an already unlocked file
     */
    boolean unlock(char[] password);

    @Nonnull
    PublicKey getPublicKey();

    /**
     * @return This method returns the unlocked private key. If this key is unavailable (eg. the underlying private key file
     * is still locked), then you must unlock it first!
     */
    @Nullable
    PrivateKey getPrivateKey();

    @Nullable
    String getComment();
}