package com.atlassian.bitbucket.ssh.api;

import com.atlassian.bitbucket.ssh.SshKey;
import com.atlassian.bitbucket.user.ApplicationUser;
import com.atlassian.bitbucket.user.TestApplicationUser;

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

public class TestSshKey implements SshKey, PublicKey {

    public static final TestApplicationUser USER = new TestApplicationUser("user");

    private final String name;

    public TestSshKey(String name) {
        this.name = name;
    }

    @Override
    public String getAlgorithm() {
        return "test";
    }

    @Override
    public String getFormat() {
        return "test";
    }

    @Override
    public byte[] getEncoded() {
        return name.getBytes();
    }

    @Override
    public String toString() {
        return "TestPublicKey{name='" + name + "'}";
    }

    @Nonnull
    @Override
    public Integer getId() {
        return name.hashCode();
    }

    @Override
    public String getText() {
        return name;
    }

    @Nonnull
    @Override
    public PublicKey toPublicKey() {
        return this;
    }

    @Override
    public String getLabel() {
        return name;
    }

    @Nullable
    @Override
    public ApplicationUser getUser() {
        return USER;
    }
}
