package com.jscape.inet.ssh.protocol.v2.marshaling;

import com.jscape.inet.ssh.protocol.messages.Message;
import com.jscape.inet.ssh.protocol.v2.marshaling.primitive.MpintCodec;
import com.jscape.inet.ssh.protocol.v2.messages.SshMsgKexDhGexGroup;
import com.jscape.util.io.DataCodec;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;

/**
 * @author Alex Usun
 */
public class SshMsgKexDhGexGroupCodec
        implements DataCodec<Message> {

    @Override
    public Message read(InputStream in)
            throws IOException {
        BigInteger p = MpintCodec.readValue(in);
        BigInteger g = MpintCodec.readValue(in);

        return new SshMsgKexDhGexGroup(p, g);
    }

    @Override
    public void write(Message value, OutputStream out)
            throws IOException {
        SshMsgKexDhGexGroup message = (SshMsgKexDhGexGroup) value;
        MpintCodec.writeValue(message.p, out);
        MpintCodec.writeValue(message.g, out);
    }
}
