@Override public Hasher putString(CharSequence chars, Charset charset) { for (Hasher hasher : hashers) { hasher.putString(chars, charset); } return this; }
@Override public Hasher putString(CharSequence chars, Charset charset) { for (Hasher hasher : hashers) { hasher.putString(chars, charset); } return this; }
@Override public Hasher putString(CharSequence chars, Charset charset) { for (Hasher hasher : hashers) { hasher.putString(chars, charset); } return this; }
@Override public HashCode hashString(CharSequence input, Charset charset) { return newHasher().putString(input, charset).hash(); }
@Override public HashCode hashString(CharSequence input, Charset charset) { return newHasher().putString(input, charset).hash(); }
@Override public HashCode hashString(CharSequence input, Charset charset) { return newHasher().putString(input, charset).hash(); }
public void testMultipleUpdatesDoFinal() throws Exception { Mac mac = Mac.getInstance("HmacSHA1"); mac.init(SHA1_KEY); mac.update("hello".getBytes(UTF_8)); mac.update("world".getBytes(UTF_8)); assertEquals( HashCode.fromBytes(mac.doFinal("!!!".getBytes(UTF_8))), Hashing.hmacSha1(SHA1_KEY) .newHasher() .putString("hello", UTF_8) .putString("world", UTF_8) .putString("!!!", UTF_8) .hash()); }
public void testMultipleUpdates() throws Exception { Mac mac = Mac.getInstance("HmacSHA1"); mac.init(SHA1_KEY); mac.update("hello".getBytes(UTF_8)); mac.update("world".getBytes(UTF_8)); assertEquals( HashCode.fromBytes(mac.doFinal()), Hashing.hmacSha1(SHA1_KEY) .newHasher() .putString("hello", UTF_8) .putString("world", UTF_8) .hash()); }
public void testInvalidUnicodeHasherPutString() { String str = new String( new char[] {'a', Character.MIN_HIGH_SURROGATE, Character.MIN_HIGH_SURROGATE, 'z'}); assertEquals( murmur3_32().hashBytes(str.getBytes(Charsets.UTF_8)), murmur3_32().newHasher().putString(str, Charsets.UTF_8).hash()); } }
public void testHashTwice() { Hasher hasher = Hashing.hmacMd5(MD5_KEY).newHasher(); assertEquals( "9753980fe94daa8ecaa82216519393a9", hasher.putString("The quick brown fox jumps over the lazy dog", UTF_8).hash().toString()); try { hasher.hash(); fail(); } catch (IllegalStateException expected) { } }
public void testHashTwice() { Hasher sha1 = Hashing.sha1().newHasher(); assertEquals( "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8) .hash() .toString()); try { sha1.hash(); fail(); } catch (IllegalStateException expected) { } }
public void testPutAfterHash() { Hasher hasher = Hashing.hmacMd5(MD5_KEY).newHasher(); assertEquals( "9753980fe94daa8ecaa82216519393a9", hasher.putString("The quick brown fox jumps over the lazy dog", UTF_8).hash().toString()); try { hasher.putInt(42); fail(); } catch (IllegalStateException expected) { } }
private static void assertSip(String input, long expected) { assertEquals(expected, SIP_WITH_KEY.hashString(input, UTF_8).asLong()); assertEquals(expected, SIP_WITH_KEY.newHasher().putString(input, UTF_8).hash().asLong()); assertEquals(expected, SIP_WITHOUT_KEY.hashString(input, UTF_8).asLong()); assertEquals(expected, SIP_WITHOUT_KEY.newHasher().putString(input, UTF_8).hash().asLong()); }
public void testPutAfterHash() { Hasher sha1 = Hashing.sha1().newHasher(); assertEquals( "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", sha1.putString("The quick brown fox jumps over the lazy dog", Charsets.UTF_8) .hash() .toString()); try { sha1.putInt(42); fail(); } catch (IllegalStateException expected) { } }
@Nullable private String computeCurrentEtag(final Set<ServerToSegment> segments, @Nullable byte[] queryCacheKey) { Hasher hasher = Hashing.sha1().newHasher(); boolean hasOnlyHistoricalSegments = true; for (ServerToSegment p : segments) { if (!p.getServer().pick().getServer().segmentReplicatable()) { hasOnlyHistoricalSegments = false; break; } hasher.putString(p.getServer().getSegment().getId().toString(), StandardCharsets.UTF_8); } if (hasOnlyHistoricalSegments) { hasher.putBytes(queryCacheKey == null ? strategy.computeCacheKey(query) : queryCacheKey); String currEtag = StringUtils.encodeBase64String(hasher.hash().asBytes()); responseContext.put(QueryResource.HEADER_ETAG, currEtag); return currEtag; } else { return null; } }
private void putRowKeyToHLL(List<String> row, byte[][] colHashValues, HLLCounter[] cuboidCounters, HashFunction hashFunction) { int x = 0; for (String field : row) { Hasher hc = hashFunction.newHasher(); colHashValues[x++] = hc.putString(field).hash().asBytes(); } for (int i = 0, n = allCuboidsBitSet.length; i < n; i++) { Hasher hc = hashFunction.newHasher(); for (int position = 0; position < allCuboidsBitSet[i].length; position++) { hc.putBytes(colHashValues[allCuboidsBitSet[i][position]]); //hc.putBytes(seperator); } cuboidCounters[i].add(hc.hash().asBytes()); } }
private void putRowKeyToHLLNew(List<String> row, long[] hashValuesLong, HLLCounter[] cuboidCounters, HashFunction hashFunction) { int x = 0; for (String field : row) { Hasher hc = hashFunction.newHasher(); byte[] bytes = hc.putString(x + field).hash().asBytes(); hashValuesLong[x++] = Bytes.toLong(bytes); } for (int i = 0, n = allCuboidsBitSet.length; i < n; i++) { long value = 0; for (int position = 0; position < allCuboidsBitSet[i].length; position++) { value += hashValuesLong[allCuboidsBitSet[i][position]]; } cuboidCounters[i].addHashDirectly(value); } }
private void putRowKeyToHLL(List<String> row) { byte[][] row_index = new byte[ROW_LENGTH][]; int x = 0; for (String field : row) { Hasher hc = hf.newHasher(); row_index[x++] = hc.putString(field).hash().asBytes(); } for (int i = 0, n = allCuboidsBitSet.length; i < n; i++) { Hasher hc = hf.newHasher(); for (int position = 0; position < allCuboidsBitSet[i].length; position++) { hc.putBytes(row_index[allCuboidsBitSet[i][position]]); hc.putBytes(seperator); } allCuboidsHLL[i].add(hc.hash().asBytes()); } }
@Test public void testZoneKeyData() { Hasher hasher = Hashing.murmur3_128().newHasher(); SortedSet<TimeZoneKey> timeZoneKeysSortedByKey = ImmutableSortedSet.copyOf(new Comparator<TimeZoneKey>() { @Override public int compare(TimeZoneKey left, TimeZoneKey right) { return Short.compare(left.getKey(), right.getKey()); } }, TimeZoneKey.getTimeZoneKeys()); for (TimeZoneKey timeZoneKey : timeZoneKeysSortedByKey) { hasher.putShort(timeZoneKey.getKey()); hasher.putString(timeZoneKey.getId(), StandardCharsets.UTF_8); } // Zone file should not (normally) be changed, so let's make this more difficult assertEquals(hasher.hash().asLong(), -4582158485614614451L, "zone-index.properties file contents changed!"); }
assertEquals( hashFunction.hashString(string, charset), hashFunction.newHasher().putString(string, charset).hash());