aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/com/trilead/ssh2/crypto/cipher/CipherOutputStream.java
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2015-07-23 22:38:46 -0700
committerKenny Root <kenny@the-b.org>2015-07-24 15:35:39 -0700
commit147dae0102979a0217ac8a9eea82a4969a1ecf63 (patch)
tree40718fac7fc6a3afce07c910ffc243dd5d69d403 /app/src/main/java/com/trilead/ssh2/crypto/cipher/CipherOutputStream.java
parent739337624a5e69221a998cf10b1fd34fcc5ecd2d (diff)
downloadconnectbot-147dae0102979a0217ac8a9eea82a4969a1ecf63.tar.gz
connectbot-147dae0102979a0217ac8a9eea82a4969a1ecf63.tar.bz2
connectbot-147dae0102979a0217ac8a9eea82a4969a1ecf63.zip
Move to library-based build
Diffstat (limited to 'app/src/main/java/com/trilead/ssh2/crypto/cipher/CipherOutputStream.java')
-rw-r--r--app/src/main/java/com/trilead/ssh2/crypto/cipher/CipherOutputStream.java142
1 files changed, 0 insertions, 142 deletions
diff --git a/app/src/main/java/com/trilead/ssh2/crypto/cipher/CipherOutputStream.java b/app/src/main/java/com/trilead/ssh2/crypto/cipher/CipherOutputStream.java
deleted file mode 100644
index cf0db4a..0000000
--- a/app/src/main/java/com/trilead/ssh2/crypto/cipher/CipherOutputStream.java
+++ /dev/null
@@ -1,142 +0,0 @@
-
-package com.trilead.ssh2.crypto.cipher;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * CipherOutputStream.
- *
- * @author Christian Plattner, plattner@trilead.com
- * @version $Id: CipherOutputStream.java,v 1.1 2007/10/15 12:49:55 cplattne Exp $
- */
-public class CipherOutputStream
-{
- BlockCipher currentCipher;
- OutputStream bo;
- byte[] buffer;
- byte[] enc;
- int blockSize;
- int pos;
-
- /*
- * We cannot use java.io.BufferedOutputStream, since that is not available
- * in J2ME. Everything could be improved here alot.
- */
-
- final int BUFF_SIZE = 2048;
- byte[] out_buffer = new byte[BUFF_SIZE];
- int out_buffer_pos = 0;
-
- public CipherOutputStream(BlockCipher tc, OutputStream bo)
- {
- this.bo = bo;
- changeCipher(tc);
- }
-
- private void internal_write(byte[] src, int off, int len) throws IOException
- {
- while (len > 0)
- {
- int space = BUFF_SIZE - out_buffer_pos;
- int copy = (len > space) ? space : len;
-
- System.arraycopy(src, off, out_buffer, out_buffer_pos, copy);
-
- off += copy;
- out_buffer_pos += copy;
- len -= copy;
-
- if (out_buffer_pos >= BUFF_SIZE)
- {
- bo.write(out_buffer, 0, BUFF_SIZE);
- out_buffer_pos = 0;
- }
- }
- }
-
- private void internal_write(int b) throws IOException
- {
- out_buffer[out_buffer_pos++] = (byte) b;
- if (out_buffer_pos >= BUFF_SIZE)
- {
- bo.write(out_buffer, 0, BUFF_SIZE);
- out_buffer_pos = 0;
- }
- }
-
- public void flush() throws IOException
- {
- if (pos != 0)
- throw new IOException("FATAL: cannot flush since crypto buffer is not aligned.");
-
- if (out_buffer_pos > 0)
- {
- bo.write(out_buffer, 0, out_buffer_pos);
- out_buffer_pos = 0;
- }
- bo.flush();
- }
-
- public void changeCipher(BlockCipher bc)
- {
- this.currentCipher = bc;
- blockSize = bc.getBlockSize();
- buffer = new byte[blockSize];
- enc = new byte[blockSize];
- pos = 0;
- }
-
- private void writeBlock() throws IOException
- {
- try
- {
- currentCipher.transformBlock(buffer, 0, enc, 0);
- }
- catch (Exception e)
- {
- throw (IOException) new IOException("Error while decrypting block.").initCause(e);
- }
-
- internal_write(enc, 0, blockSize);
- pos = 0;
- }
-
- public void write(byte[] src, int off, int len) throws IOException
- {
- while (len > 0)
- {
- int avail = blockSize - pos;
- int copy = Math.min(avail, len);
-
- System.arraycopy(src, off, buffer, pos, copy);
- pos += copy;
- off += copy;
- len -= copy;
-
- if (pos >= blockSize)
- writeBlock();
- }
- }
-
- public void write(int b) throws IOException
- {
- buffer[pos++] = (byte) b;
- if (pos >= blockSize)
- writeBlock();
- }
-
- public void writePlain(int b) throws IOException
- {
- if (pos != 0)
- throw new IOException("Cannot write plain since crypto buffer is not aligned.");
- internal_write(b);
- }
-
- public void writePlain(byte[] b, int off, int len) throws IOException
- {
- if (pos != 0)
- throw new IOException("Cannot write plain since crypto buffer is not aligned.");
- internal_write(b, off, len);
- }
-}