public CipherInputStream(BlockCipher tc, InputStream bi) { this.bi = bi; changeCipher(tc); }
private int internal_read(byte[] b, int off, int len) throws IOException { if (input_buffer_size < 0) return -1; if (input_buffer_pos >= input_buffer_size) { if (fill_buffer() <= 0) return -1; } int avail = input_buffer_size - input_buffer_pos; int thiscopy = (len > avail) ? avail : len; System.arraycopy(input_buffer, input_buffer_pos, b, off, thiscopy); input_buffer_pos += thiscopy; return thiscopy; }
public int read() throws IOException { if (pos >= blockSize) { getBlock(); } return buffer[pos++] & 0xff; }
public int read(byte[] dst) throws IOException { return read(dst, 0, dst.length); }
public int readPlain(byte[] b, int off, int len) throws IOException { if (pos != blockSize) throw new IOException("Cannot read plain since crypto buffer is not aligned."); int n = 0; while (n < len) { int cnt = internal_read(b, off + n, len - n); if (cnt < 0) throw new IOException("Cannot fill buffer, EOF reached."); n += cnt; } return n; } }
public TransportConnection(InputStream is, OutputStream os, SecureRandom rnd) { this.cis = new CipherInputStream(new NullCipher(), is); this.cos = new CipherOutputStream(new NullCipher(), os); this.rnd = rnd; }
public int read(byte[] dst) throws IOException { return read(dst, 0, dst.length); }
public int readPlain(byte[] b, int off, int len) throws IOException { if (pos != blockSize) throw new IOException("Cannot read plain since crypto buffer is not aligned."); int n = 0; while (n < len) { int cnt = internal_read(b, off + n, len - n); if (cnt < 0) throw new IOException("Cannot fill buffer, EOF reached."); n += cnt; } return n; } }
public TransportConnection(InputStream is, OutputStream os, SecureRandom rnd) { this.cis = new CipherInputStream(new NullCipher(), is); this.cos = new CipherOutputStream(new NullCipher(), os); this.rnd = rnd; }
public CipherInputStream(BlockCipher tc, InputStream bi) { this.bi = bi; changeCipher(tc); }
public int read(byte[] dst) throws IOException { return read(dst, 0, dst.length); }
public int read() throws IOException { if (pos >= blockSize) { getBlock(); } return buffer[pos++] & 0xff; }
public int readPlain(byte[] b, int off, int len) throws IOException { if (pos != blockSize) throw new IOException("Cannot read plain since crypto buffer is not aligned."); int n = 0; while (n < len) { int cnt = internal_read(b, off + n, len - n); if (cnt < 0) throw new IOException("Cannot fill buffer, EOF reached."); n += cnt; } return n; } }
public TransportConnection(InputStream is, OutputStream os, SecureRandom rnd) { this.cis = new CipherInputStream(new NullCipher(), is); this.cos = new CipherOutputStream(new NullCipher(), os); this.rnd = rnd; }
private int internal_read(byte[] b, int off, int len) throws IOException { if (input_buffer_size < 0) return -1; if (input_buffer_pos >= input_buffer_size) { if (fill_buffer() <= 0) return -1; } int avail = input_buffer_size - input_buffer_pos; int thiscopy = (len > avail) ? avail : len; System.arraycopy(input_buffer, input_buffer_pos, b, off, thiscopy); input_buffer_pos += thiscopy; return thiscopy; }
public CipherInputStream(BlockCipher tc, InputStream bi) { this.bi = bi; changeCipher(tc); }
public int peekNextMessageLength() throws IOException { if (recv_packet_header_present == false) { cis.read(recv_packet_header_buffer, 0, 5); recv_packet_header_present = true; } int packet_length = ((recv_packet_header_buffer[0] & 0xff) << 24) | ((recv_packet_header_buffer[1] & 0xff) << 16) | ((recv_packet_header_buffer[2] & 0xff) << 8) | ((recv_packet_header_buffer[3] & 0xff)); int padding_length = recv_packet_header_buffer[4] & 0xff; if (packet_length > 35000 || packet_length < 12) throw new IOException("Illegal packet size! (" + packet_length + ")"); int payload_length = packet_length - padding_length - 1; if (payload_length < 0) throw new IOException("Illegal padding_length in packet from remote (" + padding_length + ")"); return payload_length; }