package com.google.ipc.invalidation.common;
-import com.google.common.base.Preconditions;
import com.google.ipc.invalidation.util.Bytes;
-import com.google.protos.ipc.invalidation.ClientProtocol.ObjectIdP;
+import com.google.ipc.invalidation.util.Preconditions;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
* Digest-related utilities for object ids.
*
*/
-
public class ObjectIdDigestUtils {
/**
* Implementation of {@link DigestFunction} using SHA-1.
*/
-
- public static class Sha1DigestFunction implements DigestFunction {
+ public static class Sha1DigestFunction
+ implements DigestFunction {
/** Digest implementation. */
private MessageDigest sha1;
* <p>
* REQUIRES: {@code objectIdDigests} iterate in sorted order.
*/
-
public static Bytes getDigest(Iterable<Bytes> objectIdDigests, DigestFunction digestFn) {
digestFn.reset();
for (Bytes objectIdDigest : objectIdDigests) {
return new Bytes(digestFn.getDigest());
}
- /** Returns the digest of {@code objectId} using {@code digestFn}. */
-
- public static Bytes getDigest(ObjectIdP objectId, DigestFunction digestFn) {
+ /**
+ * Returns the digest for the object id with source {@code objectSource} and name
+ * {@code objectName} using {@code digestFn}.
+ */
+ public static Bytes getDigest(int objectSource, byte[] objectName, DigestFunction digestFn) {
digestFn.reset();
ByteBuffer buffer = ByteBuffer.allocate(Integer.SIZE / 8).order(ByteOrder.LITTLE_ENDIAN);
- buffer.putInt(objectId.getSource());
+ buffer.putInt(objectSource);
// Little endian number for type followed by bytes.
digestFn.update(buffer.array());
- digestFn.update(objectId.getName().toByteArray());
+ digestFn.update(objectName);
return new Bytes(digestFn.getDigest());
}
}