(InputStream inputStream, OutputStream outputStream,FEntry toDownload,byte[] h3)
| 269 | return result; |
| 270 | } |
| 271 | public boolean decryptFileHash(InputStream inputStream, OutputStream outputStream,FEntry toDownload,byte[] h3) throws IOException{ |
| 272 | int BLOCKSIZE = 0x10000; |
| 273 | int HASHBLOCKSIZE = 0xFC00; |
| 274 | |
| 275 | long writeSize = HASHBLOCKSIZE; |
| 276 | long block = (toDownload.getFileOffset() / HASHBLOCKSIZE); |
| 277 | |
| 278 | long soffset = toDownload.getFileOffset() - (toDownload.getFileOffset() / HASHBLOCKSIZE * HASHBLOCKSIZE); |
| 279 | |
| 280 | long size = toDownload.getFileLength(); |
| 281 | |
| 282 | if( soffset+size > writeSize ) |
| 283 | writeSize = writeSize - soffset; |
| 284 | |
| 285 | |
| 286 | byte[] encryptedBlockBuffer = new byte[BLOCKSIZE]; |
| 287 | ByteArrayBuffer overflow = new ByteArrayBuffer(BLOCKSIZE); |
| 288 | |
| 289 | long wrote = 0; |
| 290 | int inBlockBuffer; |
| 291 | |
| 292 | if(progressListener != null){ |
| 293 | progressListener.setTotal(toDownload.getFileLength()/HASHBLOCKSIZE*BLOCKSIZE); |
| 294 | progressListener.resetCurrent(); |
| 295 | } |
| 296 | do{ |
| 297 | inBlockBuffer = Util.getChunkFromStream(inputStream,encryptedBlockBuffer,overflow,BLOCKSIZE); |
| 298 | if(progressListener != null){ |
| 299 | progressListener.addCurrent(inBlockBuffer); |
| 300 | } |
| 301 | if( writeSize > size ) |
| 302 | writeSize = size; |
| 303 | |
| 304 | byte[] output = decryptFileChunkHash(encryptedBlockBuffer, (int) block,toDownload.getContentID(),h3); |
| 305 | |
| 306 | if((wrote + writeSize) > toDownload.getFileLength()){ |
| 307 | writeSize = (int) (toDownload.getFileLength()- wrote); |
| 308 | } |
| 309 | |
| 310 | outputStream.write(output, (int)(0+soffset), (int)writeSize); |
| 311 | wrote +=writeSize; |
| 312 | |
| 313 | block++; |
| 314 | |
| 315 | if( soffset > 0) |
| 316 | { |
| 317 | writeSize = HASHBLOCKSIZE; |
| 318 | soffset = 0; |
| 319 | } |
| 320 | }while(wrote < toDownload.getFileLength() && (inBlockBuffer == BLOCKSIZE)); |
| 321 | |
| 322 | outputStream.close(); |
| 323 | inputStream.close(); |
| 324 | return true; |
| 325 | |
| 326 | } |
| 327 | |
| 328 | public boolean decryptContentHash(InputStream inputStream, OutputStream outputStream,Content content,byte[] h3) throws IOException{ |
no test coverage detected