package Tracker;

import java.nio.ByteBuffer;

/**
 * 
 * @author Pawel
 *
 */

/**
 InfoHash is needed for identifying a torrent, its length is 20 bytes.
 */

public class InfoHash 
{
	private ByteBuffer infoHashBuffer = ByteBuffer.allocate(20);
	
	// Constructor
	
	public InfoHash (byte[] infoHashBytes) {

		if ((infoHashBytes == null) || (infoHashBytes.length != 20)) 
		{
			System.out.println("Provided bytes are not correct!");
		}

		this.infoHashBuffer.put (infoHashBytes);
		this.infoHashBuffer.rewind();

	}
}

@@ -43,69 +43,109 @@
 er;%0A
-%0A/**%0A * %0A * @author Pawel%0A *%0A */%0A%0A/**%0A InfoHash is needed for
+import java.security.MessageDigest;%0Aimport java.security.NoSuchAlgorithmException;%0A%0A/**%0A * Byte array
  ide
@@ -157,42 +157,40 @@
 ing 
-a 
 torrent
-, its length is 20 bytes.
+ file%0A * @author Pawel%0A *
 %0A */
@@ -222,14 +222,13 @@
 %7B%0A%09p
-rivate
+ublic
  Byt
@@ -243,22 +243,16 @@
 infoHash
-Buffer
  = ByteB
@@ -279,273 +279,390 @@
 %09%0A%09/
-/ Constructor%0A%09%0A%09public InfoHash (byte%5B%5D infoHashBytes) %7B%0A%0A%09%09if ((infoHashBytes == null) %7C%7C (i
+**%0A%09 * Generates InfoHash for given torrent%0A%09 * @param KEY_INFO info bytes from torrent info%0A%09 * @throws NoSuchAlgorithmException%0A%09 */%0A%09%0A%09public I
 nfoHash
+ (
 Byte
-s.length != 20))
+Buffer KEY_INFO) throws NoSuchAlgorithmException
  %0A
-%09
 %09%7B%0A%09%09
-%09System.out.println(%22Provided bytes are not correct!%22);%0A%09%09%7D%0A%0A%09%09this.infoHashBuffer.put (infoHashBytes);%0A%09%09this.infoHashBuffer.rewind();%0A
+MessageDigest digest = MessageDigest.getInstance(%22SHA-1%22);%0A%09%09digest.update(KEY_INFO.array());%0A%09%09byte%5B%5D hash = digest.digest();%0A%09%09this.infoHash = ByteBuffer.wrap(hash); 
 %0A%09%7D%0A

Update InfoHash.java