Search in sources :

Example 26 with Hasher

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();
}
Also used : Hasher(com.google.common.hash.Hasher)

Example 27 with Hasher

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();
}
Also used : Hasher(com.google.common.hash.Hasher)

Example 28 with Hasher

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();
}
Also used : Hasher(com.google.common.hash.Hasher) CurrentUser(com.google.gerrit.server.CurrentUser)

Example 29 with Hasher

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();
}
Also used : Hasher(com.google.common.hash.Hasher) HashFunction(com.google.common.hash.HashFunction)

Example 30 with Hasher

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();
}
Also used : Hasher(com.google.common.hash.Hasher) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceUrl(com.android.ide.common.resources.ResourceUrl) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Hasher (com.google.common.hash.Hasher)59 IOException (java.io.IOException)10 Test (org.junit.Test)9 HashCode (com.google.common.hash.HashCode)8 InputStream (java.io.InputStream)5 Map (java.util.Map)5 BuildTarget (com.facebook.buck.model.BuildTarget)4 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)4 SettableFakeClock (com.facebook.buck.timing.SettableFakeClock)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 HashFunction (com.google.common.hash.HashFunction)3 OutputStream (java.io.OutputStream)3 Path (java.nio.file.Path)3 SimplePerfEvent (com.facebook.buck.event.SimplePerfEvent)2 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)2 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)2 BuildRuleType (com.facebook.buck.rules.BuildRuleType)2 Cell (com.facebook.buck.rules.Cell)2 ParamInfoException (com.facebook.buck.rules.ParamInfoException)2