(InputStream inputStream, OutputStream outputStream,FEntry toDownload)
| 197 | } |
| 198 | |
| 199 | public boolean decryptFile(InputStream inputStream, OutputStream outputStream,FEntry toDownload) throws IOException{ |
| 200 | int BLOCKSIZE = 0x8000; |
| 201 | long dlFileLength = toDownload.getFileLength(); |
| 202 | if(dlFileLength > (dlFileLength/BLOCKSIZE)*BLOCKSIZE){ |
| 203 | dlFileLength = ((dlFileLength/BLOCKSIZE)*BLOCKSIZE) +BLOCKSIZE; |
| 204 | } |
| 205 | |
| 206 | byte[] IV = new byte[16]; |
| 207 | IV[1] = (byte)toDownload.getContentID(); |
| 208 | |
| 209 | byte[] blockBuffer = new byte[BLOCKSIZE]; |
| 210 | |
| 211 | int inBlockBuffer; |
| 212 | long wrote = 0; |
| 213 | |
| 214 | boolean first = true; |
| 215 | ByteArrayBuffer overflow = new ByteArrayBuffer(BLOCKSIZE); |
| 216 | if(progressListener != null){ |
| 217 | progressListener.setTotal(toDownload.getFileLength()); |
| 218 | progressListener.resetCurrent(); |
| 219 | } |
| 220 | |
| 221 | |
| 222 | MessageDigest sha1 = null; |
| 223 | try { |
| 224 | sha1 = MessageDigest.getInstance("SHA1"); |
| 225 | } catch (NoSuchAlgorithmException e) { |
| 226 | e.printStackTrace(); |
| 227 | } |
| 228 | |
| 229 | do{ |
| 230 | inBlockBuffer = Util.getChunkFromStream(inputStream,blockBuffer,overflow,BLOCKSIZE); |
| 231 | if(first){ |
| 232 | first = false; |
| 233 | }else{ |
| 234 | IV = null; |
| 235 | } |
| 236 | |
| 237 | byte[] output = decryptFileChunk(blockBuffer,BLOCKSIZE,IV); |
| 238 | |
| 239 | if(sha1 != null){ |
| 240 | sha1.update(output); |
| 241 | } |
| 242 | |
| 243 | if((wrote + inBlockBuffer) > toDownload.getFileLength()){ |
| 244 | inBlockBuffer = (int) (toDownload.getFileLength()- wrote); |
| 245 | } |
| 246 | if(progressListener != null){ |
| 247 | progressListener.addCurrent(inBlockBuffer); |
| 248 | } |
| 249 | wrote += inBlockBuffer; |
| 250 | outputStream.write(output, 0, inBlockBuffer); |
| 251 | }while(inBlockBuffer == BLOCKSIZE); |
| 252 | |
| 253 | byte[] hash = sha1.digest(); |
| 254 | byte[] real_hash = toDownload.getHash(); |
| 255 | |
| 256 | boolean result = true; |
no test coverage detected