use of com.google.common.hash.Hasher in project gerrit by GerritCodeReview.
the class FileContentUtil method randSuffix.
private static String randSuffix() {
// Produce a random suffix that is difficult (or nearly impossible)
// for an attacker to guess in advance. This reduces the risk that
// an attacker could upload a *.class file and have us send a ZIP
// that can be invoked through an applet tag in the victim's browser.
//
Hasher h = Hashing.md5().newHasher();
byte[] buf = new byte[8];
NB.encodeInt64(buf, 0, TimeUtil.nowMs());
h.putBytes(buf);
rng.nextBytes(buf);
h.putBytes(buf);
return h.hash().toString();
}
use of com.google.common.hash.Hasher in project gitiles by GerritCodeReview.
the class DocServlet method etag.
private String etag(MarkdownFile srcmd, @Nullable MarkdownFile navmd) {
byte[] b = new byte[Constants.OBJECT_ID_LENGTH];
Hasher h = Hashing.sha1().newHasher();
h.putInt(ETAG_GEN);
renderer.getTemplateHash(SOY_FILE).writeBytesTo(b, 0, b.length);
h.putBytes(b);
if (navmd != null) {
navmd.id.copyRawTo(b, 0);
h.putBytes(b);
}
srcmd.id.copyRawTo(b, 0);
h.putBytes(b);
return h.hash().toString();
}
use of com.google.common.hash.Hasher in project gerrit by GerritCodeReview.
the class ChangeResource method getETag.
@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);
}
prepareETag(h, user);
return h.hash().toString();
}
use of com.google.common.hash.Hasher in project android by JetBrains.
the class TagSnapshot method getSignature.
/** Creates a signature/fingerprint of this tag snapshot (which encapsulates the tag name and attributes */
public long getSignature() {
HashFunction hashFunction = Hashing.goodFastHash(64);
Hasher hasher = hashFunction.newHasher();
hasher.putString(tagName, UTF_8);
for (AttributeSnapshot attribute : attributes) {
if (attribute.prefix != null) {
hasher.putString(attribute.prefix, UTF_8);
}
hasher.putString(attribute.name, UTF_8);
if (attribute.value != null) {
hasher.putString(attribute.value, UTF_8);
}
// Note that we're not bothering with namespaces here; the prefix will identify it uniquely
}
return hasher.hash().asLong();
}
use of com.google.common.hash.Hasher in project android by JetBrains.
the class GradleInstantRunContext method getManifestResourcesHash.
@VisibleForTesting
static HashCode getManifestResourcesHash(@NotNull AndroidFacet facet) {
Document manifest = MergedManifest.get(facet).getDocument();
if (manifest == null || manifest.getDocumentElement() == null) {
return HashCode.fromInt(0);
}
final Hasher hasher = Hashing.goodFastHash(32).newHasher();
SortedSet<ResourceUrl> appResourceReferences = getAppResourceReferences(manifest.getDocumentElement());
AppResourceRepository appResources = AppResourceRepository.getAppResources(facet, true);
// read action needed when reading the values for app resources
ApplicationManager.getApplication().runReadAction(() -> {
hashResources(appResourceReferences, appResources, hasher);
});
return hasher.hash();
}
Aggregations