function decryptpayload(filebuf,decryptor,pos) {

		var block;
		var len=filebuf.length;
		// 49 bytes is the minimum payload size (16 bytes encrypted data + 1 mod byte + 32 byte hmac)
		// if we are at the end of file, just encrypt what we have left.
		// if filebuf is an uint8array, pos will/should be defined
		if(filebuf.eof || pos !== undefined) {
				//console.log("got eof, doing rest of file, len="+len);

				//this should only be 33 or more.
				if (len<33) return -1;
				if (len==33) return 0;
				//get all but the last 33 bytes
				len-=33;
				if (pos !== undefined)
					block=filebuf.subarray(pos,-33);
				else 
					block=filebuf.get(len);
					//console.log("starting decrypt");
				decryptor.decipher.update(forge.util.createBuffer(block));
				//decryptor.hmac.update(arrayToString(block));
				//console.log("starting hmac calc");
				hmacchunkblock(decryptor.hmac,block);
				//console.log("done with decryption");
				return(len);

		// if no end of file, then leave at least 33 bytes after this round
		} else if (len > 97) {
			//console.log("no eof, leaving at least 33 in buf");
			len=len-33;
			len = len - len % 64
			//console.log("decrypting "+len+" bytes")			
			block=filebuf.get(len);
			//now minimum in buffer is 33
			decryptor.decipher.update(forge.util.createBuffer(block));
			//decryptor.hmac.update(arrayToString(block));
			hmacchunkblock(decryptor.hmac,block);
			return(len);
		}
		return 0;
	}
// if position is defined, we assume file is a uint8array and data starts at pos
if position is defined, we assume file is a uint8array and data starts at pos
if position is defined we assume file is a uint8array and data starts at pos
function decryptpayload(filebuf,decryptor,pos) {
		var block;
		var len=filebuf.length;
		if(filebuf.eof || pos !== undefined) {
				if (len<33) return -1;
				if (len==33) return 0;
				len-=33;
				if (pos !== undefined)
					block=filebuf.subarray(pos,-33);
				else 
					block=filebuf.get(len);
				decryptor.decipher.update(forge.util.createBuffer(block));
				hmacchunkblock(decryptor.hmac,block);
				return(len);
		} else if (len > 97) {
			len=len-33;
			len = len - len % 64
			block=filebuf.get(len);
			decryptor.decipher.update(forge.util.createBuffer(block));
			hmacchunkblock(decryptor.hmac,block);
			return(len);
		}
		return 0;
	}
function decryptpayload ( filebuf , decryptor , pos ) { var block ; var len = filebuf . length ; if ( filebuf . eof || pos !== undefined ) { if ( len < 33 ) return - 1 ; if ( len == 33 ) return 0 ; len -= 33 ; if ( pos !== undefined ) block = filebuf . subarray ( pos , - 33 ) ; else block = filebuf . get ( len ) ; decryptor . decipher . update ( forge . util . createBuffer ( block ) ) ; hmacchunkblock ( decryptor . hmac , block ) ; return ( len ) ; } else if ( len > 97 ) { len = len - 33 ; len = len - len % 64 block = filebuf . get ( len ) ; decryptor . decipher . update ( forge . util . createBuffer ( block ) ) ; hmacchunkblock ( decryptor . hmac , block ) ; return ( len ) ; } return 0 ; }
if position is defined, we assume file is a uint8array and data starts at pos
if position is defined we assume file is a uint8array and data starts at pos
// 49 bytes is the minimum payload size (16 bytes encrypted data + 1 mod byte + 32 byte hmac) // if we are at the end of file, just encrypt what we have left. // if filebuf is an uint8array, pos will/should be defined //console.log("got eof, doing rest of file, len="+len); //this should only be 33 or more. //get all but the last 33 bytes //console.log("starting decrypt"); //decryptor.hmac.update(arrayToString(block)); //console.log("starting hmac calc"); //console.log("done with decryption"); // if no end of file, then leave at least 33 bytes after this round //console.log("no eof, leaving at least 33 in buf"); //console.log("decrypting "+len+" bytes")			 //now minimum in buffer is 33 //decryptor.hmac.update(arrayToString(block));