Code example for MessageDigest

Methods: clonedigest

0
	/** 
	 * @tests java.security.DigestInputStream#on(boolean) 
	 */ 
    public void test_onZ() throws Exception { 
        // Test for method void java.security.DigestInputStream.on(boolean) 
        MessageDigest originalDigest = (MessageDigest) (digest.clone());
        MessageDigest noChangeDigest = (MessageDigest) (digest.clone());
        DigestInputStream dis = new DigestInputStream(inStream, noChangeDigest);
        // turn off processing 
        dis.on(false);
        // read some data 
        int c = dis.read();
        assertEquals('T', c);
 
        // make sure the digest for the part where it was off has not 
        // changed 
        assertTrue("MessageDigest changed even though processing was off",
                MessageDigest.isEqual(noChangeDigest.digest(), originalDigest
                        .digest()));
        MessageDigest changeDigest = (MessageDigest) (digest.clone());
        dis = new DigestInputStream(inStream, digest);
 
        // turn on processing 
        dis.on(true);
        c = dis.read();
        assertEquals('h', c);
 
        // make sure the digest has changed 
        assertTrue("MessageDigest did not change with processing on",
                !MessageDigest.isEqual(digest.digest(), changeDigest.digest()));
    } 
 
	/** 
	 * @tests java.security.DigestInputStream#read() 
	 */