@Test public void multipleHashes() throws Exception { HashingSource hashingSource = HashingSource.sha256(source); source.writeUtf8("abc"); assertEquals(3L, hashingSource.read(sink, Long.MAX_VALUE)); ByteString hash_abc = hashingSource.hash(); assertEquals(SHA256_abc, hash_abc); source.writeUtf8("def"); assertEquals(3L, hashingSource.read(sink, Long.MAX_VALUE)); assertEquals(SHA256_def, hashingSource.hash()); assertEquals(SHA256_abc, hash_abc); }
@Test public void md5() throws Exception { HashingSource hashingSource = HashingSource.md5(source); source.writeUtf8("abc"); assertEquals(3L, hashingSource.read(sink, Long.MAX_VALUE)); assertEquals(MD5_abc, hashingSource.hash()); }
@Test public void sha256() throws Exception { HashingSource hashingSource = HashingSource.sha256(source); source.writeUtf8("abc"); assertEquals(3L, hashingSource.read(sink, Long.MAX_VALUE)); assertEquals(SHA256_abc, hashingSource.hash()); }
@Test public void sha1() throws Exception { HashingSource hashingSource = HashingSource.sha1(source); source.writeUtf8("abc"); assertEquals(3L, hashingSource.read(sink, Long.MAX_VALUE)); assertEquals(SHA1_abc, hashingSource.hash()); }
@Test public void hmacSha512() throws Exception { HashingSource hashingSource = HashingSource.hmacSha512(source, HMAC_KEY); source.writeUtf8("abc"); assertEquals(3L, hashingSource.read(sink, Long.MAX_VALUE)); assertEquals(HMAC_SHA512_abc, hashingSource.hash()); }
@Test public void sha512() throws Exception { HashingSource hashingSource = HashingSource.sha512(source); source.writeUtf8("abc"); assertEquals(3L, hashingSource.read(sink, Long.MAX_VALUE)); assertEquals(SHA512_abc, hashingSource.hash()); }
@Test public void hmacSha1() throws Exception { HashingSource hashingSource = HashingSource.hmacSha1(source, HMAC_KEY); source.writeUtf8("abc"); assertEquals(3L, hashingSource.read(sink, Long.MAX_VALUE)); assertEquals(HMAC_SHA1_abc, hashingSource.hash()); }
@Test public void hmacSha256() throws Exception { HashingSource hashingSource = HashingSource.hmacSha256(source, HMAC_KEY); source.writeUtf8("abc"); assertEquals(3L, hashingSource.read(sink, Long.MAX_VALUE)); assertEquals(HMAC_SHA256_abc, hashingSource.hash()); }
@Test public void readIntoSuffixOfBuffer() throws Exception { HashingSource hashingSource = HashingSource.sha256(source); source.write(r32k); sink.writeUtf8(TestUtil.repeat('z', SEGMENT_SIZE * 2 - 1)); assertEquals(r32k.size(), hashingSource.read(sink, Long.MAX_VALUE)); assertEquals(SHA256_r32k, hashingSource.hash()); }