List of usage examples for com.google.common.hash Hasher putString
@Override Hasher putString(CharSequence charSequence, Charset charset);
From source file:io.github.maxymania.powercache.proxy.MethodCall.java
@Override public int hashCode() { //int hash = 7; //hash = 79 * hash + Objects.hashCode(this.name); //hash = 79 * hash + Arrays.deepHashCode(this.data); //return hash; Hasher h = Hashing.adler32().newHasher(); h.putString(name, Util.UTF); h.putObject(data, Util.funnel); return h.hash().asInt(); }
From source file:org.apache.servicecomb.demo.edge.service.encrypt.filter.EdgeSignatureRequestFilter.java
@Override public Response afterReceiveRequest(Invocation invocation, HttpServletRequestEx requestEx) { EncryptContext encryptContext = (EncryptContext) invocation.getHandlerContext() .get(EdgeConst.ENCRYPT_CONTEXT); if (encryptContext == null) { return null; }//from ww w .ja v a 2 s.com Hcr hcr = encryptContext.getHcr(); // signature for query and form List<String> names = Collections.list(requestEx.getParameterNames()); names.sort(Comparator.naturalOrder()); Hasher hasher = Hashing.sha256().newHasher(); hasher.putString(hcr.getSignatureKey(), StandardCharsets.UTF_8); for (String name : names) { hasher.putString(name, StandardCharsets.UTF_8); hasher.putString(requestEx.getParameter(name), StandardCharsets.UTF_8); } LOGGER.info("afterReceiveRequest signature: {}", hasher.hash().toString()); return null; }
From source file:org.fim.model.FileHash.java
@Override public void hashObject(Hasher hasher) { hasher.putString("FileHash", Charsets.UTF_8).putChar(HASH_FIELD_SEPARATOR) .putString(smallBlockHash, Charsets.UTF_8).putChar(HASH_FIELD_SEPARATOR) .putString(mediumBlockHash, Charsets.UTF_8).putChar(HASH_FIELD_SEPARATOR) .putString(fullHash, Charsets.UTF_8); }
From source file:org.apache.servicecomb.it.edge.encrypt.filter.EdgeSignatureResponseFilter.java
@Override public void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) { if (invocation == null) { return;//ww w.j av a2s.c o m } EncryptContext encryptContext = (EncryptContext) invocation.getHandlerContext() .get(EdgeConst.ENCRYPT_CONTEXT); if (encryptContext == null) { return; } Hcr hcr = encryptContext.getHcr(); // bad practice: it's better to set signature in response header Buffer bodyBuffer = responseEx.getBodyBuffer(); String body = bodyBuffer.toString(); if (body.endsWith("}")) { Hasher hasher = Hashing.sha256().newHasher(); hasher.putString(hcr.getSignatureKey(), StandardCharsets.UTF_8); hasher.putString(body, StandardCharsets.UTF_8); String signature = hasher.hash().toString(); LOGGER.info("beforeSendResponse signature: {}", signature); body = body.substring(0, body.length() - 1) + ",\"signature\":\"" + signature + "\"}"; responseEx.setBodyBuffer(Buffer.buffer(body)); } }
From source file:com.mapr.synth.NestedRandom.java
private void hash(Hasher hasher) { if (content != null) { hasher.putString(content, Charsets.UTF_8); } else {// w w w . ja v a2s.co m hasher.putInt(seed); } if (parent != null) { parent.hash(hasher); } }
From source file:com.facebook.buck.parser.DefaultParserTargetGroupFactory.java
@Override public TargetGroup createTargetNode(Cell cell, Path buildFile, BuildTarget target, Map<String, Object> rawNode, Function<PerfEventId, SimplePerfEvent.Scope> perfEventScope) { Preconditions.checkArgument(!target.isFlavored()); UnflavoredBuildTarget unflavoredBuildTarget = target.withoutCell().getUnflavoredBuildTarget(); UnflavoredBuildTarget unflavoredBuildTargetFromRawData = RawNodeParsePipeline .parseBuildTargetFromRawRule(cell.getRoot(), rawNode, buildFile); if (!unflavoredBuildTarget.equals(unflavoredBuildTargetFromRawData)) { throw new IllegalStateException( String.format("Inconsistent internal state, target from data: %s, expected: %s, raw data: %s", unflavoredBuildTargetFromRawData, unflavoredBuildTarget, Joiner.on(',').withKeyValueSeparator("->").join(rawNode))); }/* w w w . ja v a 2s. co m*/ BuildRuleType buildRuleType = parseBuildRuleTypeFromRawRule(cell, rawNode); // Because of the way that the parser works, we know this can never return null. Description<?> description = cell.getDescription(buildRuleType); Cell targetCell = cell.getCell(target); TargetGroupDescription.Arg constructorArg = (TargetGroupDescription.Arg) description .createUnpopulatedConstructorArg(); try { ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder(); ImmutableSet.Builder<VisibilityPattern> visibilityPatterns = ImmutableSet.builder(); try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("MarshalledConstructorArg"))) { marshaller.populate(targetCell.getCellPathResolver(), targetCell.getFilesystem(), target, constructorArg, declaredDeps, visibilityPatterns, rawNode); } try (SimplePerfEvent.Scope scope = perfEventScope.apply(PerfEventId.of("CreatedTargetNode"))) { Hasher hasher = Hashing.sha1().newHasher(); hasher.putString(BuckVersion.getVersion(), UTF_8); JsonObjectHashing.hashJsonObject(hasher, rawNode); TargetGroup node = new TargetGroup(constructorArg.targets, constructorArg.restrictOutboundVisibility, target); return node; } } catch (ParamInfoException e) { throw new HumanReadableException("%s: %s", target, e.getMessage()); } }
From source file:com.facebook.buck.rules.macros.AbstractStringWithMacrosConverter.java
/** * Expand the input given for the this macro to some string, which is intended to be written to a * file./*from www . ja v a 2 s . c o m*/ */ private Arg expand(MacroContainer macroContainer, ActionGraphBuilder ruleResolver) throws MacroException { Arg arg = expand(macroContainer.getMacro(), ruleResolver); // If specified, wrap this macro's output in a `WriteToFileArg`. if (macroContainer.isOutputToFile()) { // "prefix" should give a stable name, so that the same delegate with the same input can // output the same file. We won't optimise for this case, since it's actually unlikely to // happen within a single run, but using a random name would cause 'buck-out' to expand in an // uncontrolled manner. Hasher hasher = Hashing.sha256().newHasher(); hasher.putString(macroContainer.getMacro().getClass().getName(), UTF_8); hasher.putInt(macroContainer.getMacro().hashCode()); String prefix = hasher.hash().toString(); arg = new WriteToFileArg(getBuildTarget(), prefix, arg); } return arg; }
From source file:com.facebook.buck.util.hash.AppendingHasher.java
@Override public Hasher putString(CharSequence charSequence, Charset charset) { for (Hasher hasher : hashers) { hasher.putString(charSequence, charset); }/* ww w . j ava 2 s . c om*/ return this; }
From source file:com.spotify.heroic.metric.Event.java
@Override public void hash(final Hasher hasher) { hasher.putInt(MetricType.EVENT.ordinal()); for (final String k : KEY_ORDER.sortedCopy(payload.keySet())) { hasher.putString(k, Charsets.UTF_8).putString(payload.get(k), Charsets.UTF_8); }/* w w w.j a va 2 s . com*/ }
From source file:com.google.gerrit.server.change.ChangeResource.java
@Override public String getETag() { CurrentUser user = control.getUser(); Hasher h = Hashing.md5().newHasher(); if (user.isIdentifiedUser()) { h.putString(starredChangesUtil.getObjectId(user.getAccountId(), getId()).name(), UTF_8); }//from w ww .ja v a 2 s . c o m prepareETag(h, user); return h.hash().toString(); }