Replace Hashing.{md5,sha1} with Hashing.murmur3_128

md5 and sha1 are deprecated in Guava 22. Where possible, replace
them with the recommended alternatives.

In cases where we need to keep using sha1 for compatibility, add
a warning suppression with comment.

Change-Id: I3f80d52ea4e299c2a7c86fbda25457814bff750c
This commit is contained in:
David Pursehouse
2017-06-20 21:32:05 +09:00
committed by David Ostrovsky
parent 58087a18a0
commit f4001aa356
9 changed files with 9 additions and 8 deletions

View File

@@ -133,7 +133,7 @@ public class HostPageServlet extends HttpServlet {
String src = "gerrit_ui/gerrit_ui.nocache.js";
try (InputStream in = servletContext.getResourceAsStream("/" + src)) {
if (in != null) {
Hasher md = Hashing.md5().newHasher();
Hasher md = Hashing.murmur3_128().newHasher();
byte[] buf = new byte[1024];
int n;
while ((n = in.read(buf)) > 0) {

View File

@@ -312,7 +312,7 @@ public abstract class ResourceServlet extends HttpServlet {
this.lastModified = checkNotNull(lastModified, "lastModified");
this.contentType = checkNotNull(contentType, "contentType");
this.raw = checkNotNull(raw, "raw");
this.etag = Hashing.md5().hashBytes(raw).toString();
this.etag = Hashing.murmur3_128().hashBytes(raw).toString();
}
boolean isStale(Path p, ResourceServlet rs) throws IOException {

View File

@@ -280,7 +280,7 @@ class LibraryDownloader {
System.err.flush();
return;
}
Hasher h = Hashing.sha1().newHasher();
Hasher h = Hashing.murmur3_128().newHasher();
try (InputStream in = Files.newInputStream(dst);
OutputStream out = Funnels.asOutputStream(h)) {
ByteStreams.copy(in, out);

View File

@@ -96,6 +96,7 @@ public abstract class ExternalId implements Serializable {
* Returns the SHA1 of the external ID that is used as note ID in the refs/meta/external-ids
* notes branch.
*/
@SuppressWarnings("deprecation") // Use Hashing.sha1 for compatibility.
public ObjectId sha1() {
return ObjectId.fromRaw(Hashing.sha1().hashString(get(), UTF_8).asBytes());
}

View File

@@ -137,7 +137,7 @@ public class ChangeResource implements RestResource, HasETag {
@Override
public String getETag() {
CurrentUser user = control.getUser();
Hasher h = Hashing.md5().newHasher();
Hasher h = Hashing.murmur3_128().newHasher();
if (user.isIdentifiedUser()) {
h.putString(starredChangesUtil.getObjectId(user.getAccountId(), getId()).name(), UTF_8);
}

View File

@@ -273,7 +273,7 @@ public class FileContentUtil {
// 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();
Hasher h = Hashing.murmur3_128().newHasher();
byte[] buf = new byte[8];
NB.encodeInt64(buf, 0, TimeUtil.nowMs());

View File

@@ -63,7 +63,7 @@ public class GetRevisionActions implements ETagView<RevisionResource> {
@Override
public String getETag(RevisionResource rsrc) {
Hasher h = Hashing.md5().newHasher();
Hasher h = Hashing.murmur3_128().newHasher();
CurrentUser user = rsrc.getControl().getUser();
try {
rsrc.getChangeResource().prepareETag(h, user);

View File

@@ -745,7 +745,7 @@ public class PostReview
comment.key.patchSetId,
comment.lineNbr,
Side.fromShort(comment.side),
Hashing.sha1().hashString(comment.message, UTF_8),
Hashing.murmur3_128().hashString(comment.message, UTF_8),
comment.range);
}

View File

@@ -47,7 +47,7 @@ public class RequestId {
private final String str;
private RequestId(String resourceId) {
Hasher h = Hashing.sha1().newHasher();
Hasher h = Hashing.murmur3_128().newHasher();
h.putLong(Thread.currentThread().getId()).putUnencodedChars(MACHINE_ID);
str =
"["