XORSocket.java

package fr.umlv.ji.io;
import java.net.*;
import java.io.*;
/**
 * Classe de socket chiffrant les données transmises.
 */
public class XORSocket extends Socket {
  /** Clef de chiffrement. */
  private int key;
  /** Flots d'entrée et de sortie de la socket de chiffrement. */
  private InputStream in = null;
  private OutputStream out = null;
  /** Constructeur utilisé par les sockets serveurs.
      Il n'y a pas ouverture de connexion. */
  XORSocket(int key) throws IOException {
    this.key = key;
  }  
  /** Constructeur effectuant la connexion TCP. */
  public XORSocket(String host, int port, int key) throws IOException {
    super(host, port);
    this.key = key;
  }
  /** Méthode qui retourne un flot déchiffrant la connexion TCP. */
  public InputStream getInputStream() throws IOException {
    if (in!=null)
      return in;
    return new XORInputStream(super.getInputStream(),key);
  }
  /** Méthode qui retourne un flot chiffrant la connexion. */
  public OutputStream getOutputStream() throws IOException {
    if (out != null)
      return out;
    return new XOROutputStream(super.getOutputStream(), key);
  }
}