001 package org.bouncycastle.crypto.io; 002 003 import java.io.FilterInputStream; 004 import java.io.IOException; 005 import java.io.InputStream; 006 import org.bouncycastle.crypto.BufferedBlockCipher; 007 import org.bouncycastle.crypto.StreamCipher; 008 009 public class CipherInputStream extends FilterInputStream 010 { 011 private BufferedBlockCipher field_74859_a; 012 private StreamCipher field_74857_b; 013 private byte[] field_74858_c; 014 private byte[] field_74855_d; 015 private int field_74856_e; 016 private int field_74853_f; 017 private boolean field_74854_g; 018 019 public CipherInputStream(InputStream par1InputStream, BufferedBlockCipher par2BufferedBlockCipher) 020 { 021 super(par1InputStream); 022 this.field_74859_a = par2BufferedBlockCipher; 023 this.field_74858_c = new byte[par2BufferedBlockCipher.func_71789_b(2048)]; 024 this.field_74855_d = new byte[2048]; 025 } 026 027 private int func_74852_a() throws IOException 028 { 029 int var1 = super.available(); 030 031 if (var1 <= 0) 032 { 033 var1 = 1; 034 } 035 036 if (var1 > this.field_74855_d.length) 037 { 038 var1 = super.read(this.field_74855_d, 0, this.field_74855_d.length); 039 } 040 else 041 { 042 var1 = super.read(this.field_74855_d, 0, var1); 043 } 044 045 if (var1 < 0) 046 { 047 if (this.field_74854_g) 048 { 049 return -1; 050 } 051 052 try 053 { 054 if (this.field_74859_a != null) 055 { 056 this.field_74853_f = this.field_74859_a.func_71790_a(this.field_74858_c, 0); 057 } 058 else 059 { 060 this.field_74853_f = 0; 061 } 062 } 063 catch (Exception var4) 064 { 065 throw new IOException("error processing stream: " + var4.toString()); 066 } 067 068 this.field_74856_e = 0; 069 this.field_74854_g = true; 070 071 if (this.field_74856_e == this.field_74853_f) 072 { 073 return -1; 074 } 075 } 076 else 077 { 078 this.field_74856_e = 0; 079 080 try 081 { 082 if (this.field_74859_a != null) 083 { 084 this.field_74853_f = this.field_74859_a.func_71791_a(this.field_74855_d, 0, var1, this.field_74858_c, 0); 085 } 086 else 087 { 088 this.field_74857_b.func_74850_a(this.field_74855_d, 0, var1, this.field_74858_c, 0); 089 this.field_74853_f = var1; 090 } 091 } 092 catch (Exception var3) 093 { 094 throw new IOException("error processing stream: " + var3.toString()); 095 } 096 097 if (this.field_74853_f == 0) 098 { 099 return this.func_74852_a(); 100 } 101 } 102 103 return this.field_74853_f; 104 } 105 106 public int read() throws IOException 107 { 108 return this.field_74856_e == this.field_74853_f && this.func_74852_a() < 0 ? -1 : this.field_74858_c[this.field_74856_e++] & 255; 109 } 110 111 public int read(byte[] par1ArrayOfByte) throws IOException 112 { 113 return this.read(par1ArrayOfByte, 0, par1ArrayOfByte.length); 114 } 115 116 public int read(byte[] par1ArrayOfByte, int par2, int par3) throws IOException 117 { 118 if (this.field_74856_e == this.field_74853_f && this.func_74852_a() < 0) 119 { 120 return -1; 121 } 122 else 123 { 124 int var4 = this.field_74853_f - this.field_74856_e; 125 126 if (par3 > var4) 127 { 128 System.arraycopy(this.field_74858_c, this.field_74856_e, par1ArrayOfByte, par2, var4); 129 this.field_74856_e = this.field_74853_f; 130 return var4; 131 } 132 else 133 { 134 System.arraycopy(this.field_74858_c, this.field_74856_e, par1ArrayOfByte, par2, par3); 135 this.field_74856_e += par3; 136 return par3; 137 } 138 } 139 } 140 141 public long skip(long par1) throws IOException 142 { 143 if (par1 <= 0L) 144 { 145 return 0L; 146 } 147 else 148 { 149 int var3 = this.field_74853_f - this.field_74856_e; 150 151 if (par1 > (long)var3) 152 { 153 this.field_74856_e = this.field_74853_f; 154 return (long)var3; 155 } 156 else 157 { 158 this.field_74856_e += (int)par1; 159 return (long)((int)par1); 160 } 161 } 162 } 163 164 public int available() throws IOException 165 { 166 return this.field_74853_f - this.field_74856_e; 167 } 168 169 public void close() throws IOException 170 { 171 super.close(); 172 } 173 174 public boolean markSupported() 175 { 176 return false; 177 } 178 }