package com.jscape.inet.ssh.protocol.v2.transport.keyexchange;

import com.jscape.crypto.Hash;
import com.jscape.inet.ssh.protocol.v2.marshaling.algorithms.KeyFactory;

import java.security.PublicKey;
import java.util.Arrays;

import static com.jscape.util.Parameters.assertNotNull;

/**
 * The SSH key exchange result.
 *
 * @author Alex Usun
 */
public class KeyExchangeResult {

    public final Hash hash;
    public final byte[] sharedSecret;
    public final byte[] exchangeHash;
    public final PublicKey hostKey;

    public KeyExchangeResult(Hash hash, byte[] sharedSecret, byte[] exchangeHash, PublicKey hostKey) {
        assertNotNull(hash);
        this.hash = hash;

        assertNotNull(sharedSecret);
        this.sharedSecret = sharedSecret;

        assertNotNull(exchangeHash);
        this.exchangeHash = exchangeHash;

        this.hostKey = hostKey;
    }

    public KeyFactory asKeyFactory(byte[] sessionId) {
        return new KeyFactory(this.hash, this.sharedSecret, this.exchangeHash, sessionId);
    }

    @Override
    public String toString() {
        return "KeyExchangeResult {"
               + "hash=" + this.hash
               + ", sharedSecret=" + Arrays.toString(this.sharedSecret)
               + ", exchangeHash=" + Arrays.toString(this.exchangeHash)
               + ", hostKey=" + this.hostKey
               + '}';
    }
}
