package com.atlassian.bitbucket.ssh;

import com.atlassian.bitbucket.ssh.validation.EncodedPublicKey;
import com.atlassian.bitbucket.user.ApplicationUser;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
import java.security.PublicKey;

/**
 * An SSH key that can be used to authenticate with Bitbucket.
 */
public interface SshKey {

    /**
     * @return identifier for this key
     */
    @Nonnull
    Integer getId();

    /**
     * @return the key's label. Usually the user and hostname from where the key was created.
     */
    @Nullable
    String getLabel();

    /**
     * @return a String representation of the encoded public key bytes.
     */
    @NotNull(message = "{com.atlassian.bitbucket.validation.required.publickey.message}")
    @EncodedPublicKey
    String getText();

    /**
     * @return the {@link ApplicationUser user} associated with tke key, if any
     */
    @Nullable
    ApplicationUser getUser();

    /**
     * @return the public key as a {@link java.security.PublicKey}
     */
    @Nonnull
    PublicKey toPublicKey();
}
