FileDocCategorySizeDatePackage
ED2KHasher.javaAPI DocAzureus 3.0.3.43369Wed Jul 19 05:11:22 BST 2006org.gudy.azureus2.core3.util

ED2KHasher

public class ED2KHasher extends Object
author
parg

Fields Summary
public static final int
BLOCK_SIZE
protected MD4Hasher
current_hasher
protected MD4Hasher
block_hasher
protected int
current_bytes
Constructors Summary
public ED2KHasher()

	
	
	
	
		
	
Methods Summary
public byte[]getDigest()

			// data that is a multiple of BLOCK_SIZE needs to have a null MD4 hash appended
		
		if ( current_bytes == BLOCK_SIZE ){
			
			if ( block_hasher == null ){
				
				block_hasher = new MD4Hasher();
			}
			
			block_hasher.update( current_hasher.getDigest());
			
			current_hasher = new MD4Hasher();
		}
			
		if ( block_hasher == null ){
				
			return( current_hasher.getDigest());
				
		}else{
			
			if ( current_bytes > 0 ){
					
				block_hasher.update( current_hasher.getDigest());
			}
				
			return( block_hasher.getDigest());
		}
	
public voidupdate(byte[] data)

		update( data, 0, data.length );
	
public voidupdate(byte[] data, int pos, int len)

		int		rem = len;
		
		while( rem > 0 ){
			
			int	space = BLOCK_SIZE - current_bytes;
			
			if ( rem <= space ){
				
				current_hasher.update( data, pos, rem );
				
				current_bytes += rem;
				
				break;
				
			}else{
				
				if ( block_hasher == null ){
					
					block_hasher = new MD4Hasher();
				}
				
				if ( space == 0 ){
			
					block_hasher.update( current_hasher.getDigest());
					
					current_hasher = new MD4Hasher();
					
					current_bytes = 0;
					
				}else{
					
					current_hasher.update( data, pos, space );
					
					pos 			+= space;
					rem				-= space;
					current_bytes	+= space;
				}
			}
		}