private String collectorsToEtag(CollectorListResponse collectors) { return Hashing.md5() .hashInt(collectors.hashCode()) // avoid negative values .toString(); } }
private String configurationToEtag(Configuration configuration) { return Hashing.md5() .hashInt(configuration.hashCode()) // avoid negative values .toString(); }
public void testHash() throws IOException { File asciiFile = getTestFile("ascii.txt"); File i18nFile = getTestFile("i18n.txt"); String init = "d41d8cd98f00b204e9800998ecf8427e"; assertEquals(init, Hashing.md5().newHasher().hash().toString()); String asciiHash = "e5df5a39f2b8cb71b24e1d8038f93131"; assertEquals(asciiHash, Files.hash(asciiFile, Hashing.md5()).toString()); String i18nHash = "7fa826962ce2079c8334cd4ebf33aea4"; assertEquals(i18nHash, Files.hash(i18nFile, Hashing.md5()).toString()); }
@Description("compute md5 hash") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice md5(@SqlType(StandardTypes.VARBINARY) Slice slice) { return Slices.wrappedBuffer(Hashing.md5().hashBytes(slice.getBytes()).asBytes()); }
public void testHash() throws IOException { ByteSource byteSource = new TestByteSource("hamburger\n".getBytes(Charsets.US_ASCII)); // Pasted this expected string from `echo hamburger | md5sum` assertEquals("cfa0c5002275c90508338a5cdb2a9781", byteSource.hash(Hashing.md5()).toString()); }
public void testHash_hashesCorrectly() throws Exception { HashCode expectedHash = Hashing.md5().hashBytes(testBytes); HashingInputStream in = new HashingInputStream(Hashing.md5(), buffer); byte[] buf = new byte[4]; int numOfByteRead = in.read(buf, 0, buf.length); assertEquals(4, numOfByteRead); assertEquals(expectedHash, in.hash()); }
public void testConcatenating_equals() { new EqualsTester() .addEqualityGroup(Hashing.concatenating(asList(Hashing.md5()))) .addEqualityGroup(Hashing.concatenating(asList(Hashing.murmur3_32()))) .addEqualityGroup( Hashing.concatenating(Hashing.md5(), Hashing.md5()), Hashing.concatenating(asList(Hashing.md5(), Hashing.md5()))) .addEqualityGroup( Hashing.concatenating(Hashing.murmur3_32(), Hashing.md5()), Hashing.concatenating(asList(Hashing.murmur3_32(), Hashing.md5()))) .addEqualityGroup( Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32()), Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32()))) .testEquals(); }
public void testConcatenatingIterable_bits() { assertEquals( Hashing.md5().bits() + Hashing.md5().bits(), Hashing.concatenating(asList(Hashing.md5(), Hashing.md5())).bits()); assertEquals( Hashing.md5().bits() + Hashing.murmur3_32().bits(), Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32())).bits()); assertEquals( Hashing.md5().bits() + Hashing.murmur3_32().bits() + Hashing.murmur3_128().bits(), Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32(), Hashing.murmur3_128())) .bits()); }
public void testConcatenatingHashFunction_makeHash() { byte[] md5Hash = Hashing.md5().hashLong(42L).asBytes(); byte[] murmur3Hash = Hashing.murmur3_32().hashLong(42L).asBytes(); byte[] combined = new byte[md5Hash.length + murmur3Hash.length]; ByteBuffer buffer = ByteBuffer.wrap(combined); buffer.put(md5Hash); buffer.put(murmur3Hash); HashCode expected = HashCode.fromBytes(combined); assertEquals( expected, Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32()).hashLong(42L)); assertEquals( expected, Hashing.concatenating(asList(Hashing.md5(), Hashing.murmur3_32())).hashLong(42L)); }
public void testConcatenatingVarArgs_bits() { assertEquals( Hashing.md5().bits() + Hashing.md5().bits(), Hashing.concatenating(Hashing.md5(), Hashing.md5()).bits()); assertEquals( Hashing.md5().bits() + Hashing.murmur3_32().bits(), Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32()).bits()); assertEquals( Hashing.md5().bits() + Hashing.murmur3_32().bits() + Hashing.murmur3_128().bits(), Hashing.concatenating(Hashing.md5(), Hashing.murmur3_32(), Hashing.murmur3_128()).bits()); }
public void testHash_hashesCorrectlyForSkipping() throws Exception { HashCode expectedHash = Hashing.md5().hashBytes(new byte[] {'m', 's'}); HashingInputStream in = new HashingInputStream(Hashing.md5(), buffer); long numOfByteSkipped = in.skip(2); assertEquals(2, numOfByteSkipped); byte[] buf = new byte[4]; int numOfByteRead = in.read(buf, 0, buf.length); assertEquals(2, numOfByteRead); assertEquals(expectedHash, in.hash()); }
public void testChecksForNull() throws Exception { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicInstanceMethods( new HashingOutputStream(Hashing.md5(), new ByteArrayOutputStream())); tester.testAllPublicStaticMethods(HashingOutputStream.class); tester.testAllPublicConstructors(HashingOutputStream.class); } }
public void testHash_hashesCorrectlyReadOutOfBound() throws Exception { HashCode expectedHash = Hashing.md5().hashBytes(testBytes); HashingInputStream in = new HashingInputStream(Hashing.md5(), buffer); byte[] buf = new byte[100]; int numOfByteRead = in.read(buf, 0, buf.length); assertEquals(-1, in.read()); // additional read assertEquals(4, numOfByteRead); assertEquals(expectedHash, in.hash()); }
public void testToString() { assertEquals("Hashing.md5()", Hashing.md5().toString()); assertEquals("Hashing.sha1()", Hashing.sha1().toString()); assertEquals("Hashing.sha256()", Hashing.sha256().toString()); assertEquals("Hashing.sha512()", Hashing.sha512().toString()); }
public void testChecksForNull() throws Exception { NullPointerTester tester = new NullPointerTester(); tester.testAllPublicInstanceMethods(new HashingInputStream(Hashing.md5(), buffer)); tester.testAllPublicStaticMethods(HashingInputStream.class); tester.testAllPublicConstructors(HashingInputStream.class); } }