com.google.ipc.invalidation.common.ObjectIdDigestUtils.Sha1DigestFunction Java Examples

The following examples show how to use com.google.ipc.invalidation.common.ObjectIdDigestUtils.Sha1DigestFunction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TiclStateManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns a {@link AndroidTiclStateWithDigest} containing {@code ticlState} and its computed
 * digest.
 */
private static AndroidTiclStateWithDigest createDigestedState(
    AndroidInvalidationClientImpl ticl) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  ApplicationClientIdP ticlAppId = ticl.getApplicationClientIdP();
  Metadata metaData = Metadata.newBuilder()
       .setClientConfig(ticl.getConfig())
       .setClientName(ticlAppId.getClientName())
       .setClientType(ticlAppId.getClientType())
       .setTiclId(ticl.getSchedulingId())
       .build();
  AndroidTiclState state = AndroidTiclState.newBuilder()
      .setMetadata(metaData)
      .setTiclState(ticl.marshal())
      .setVersion(ProtocolIntents.ANDROID_PROTOCOL_VERSION_VALUE).build();
  digester.update(state.toByteArray());
  AndroidTiclStateWithDigest verifiedState = AndroidTiclStateWithDigest.newBuilder()
      .setState(state)
      .setDigest(ByteString.copyFrom(digester.getDigest()))
      .build();
  return verifiedState;
}
 
Example #2
Source File: TiclStateManager.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Returns a {@link AndroidTiclStateWithDigest} containing {@code ticlState} and its computed
 * digest.
 */
private static AndroidTiclStateWithDigest createDigestedState(
    AndroidInvalidationClientImpl ticl) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  ApplicationClientIdP ticlAppId = ticl.getApplicationClientIdP();
  Metadata metaData = Metadata.newBuilder()
       .setClientConfig(ticl.getConfig())
       .setClientName(ticlAppId.getClientName())
       .setClientType(ticlAppId.getClientType())
       .setTiclId(ticl.getSchedulingId())
       .build();
  AndroidTiclState state = AndroidTiclState.newBuilder()
      .setMetadata(metaData)
      .setTiclState(ticl.marshal())
      .setVersion(ProtocolIntents.ANDROID_PROTOCOL_VERSION_VALUE).build();
  digester.update(state.toByteArray());
  AndroidTiclStateWithDigest verifiedState = AndroidTiclStateWithDigest.newBuilder()
      .setState(state)
      .setDigest(ByteString.copyFrom(digester.getDigest()))
      .build();
  return verifiedState;
}
 
Example #3
Source File: TiclStateManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link AndroidTiclStateWithDigest} containing {@code ticlState} and its computed
 * digest.
 */
private static AndroidTiclStateWithDigest createDigestedState(
    AndroidInvalidationClientImpl ticl) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  ApplicationClientIdP ticlAppId = ticl.getApplicationClientIdP();
  Metadata metadata = Metadata.create(ticlAppId.getClientType(), ticlAppId.getClientName(),
      ticl.getSchedulingId(), ticl.getConfig());
  AndroidTiclState state = AndroidTiclState.create(ProtocolIntents.ANDROID_PROTOCOL_VERSION_VALUE,
      ticl.marshal(), metadata,
      ((AndroidInternalScheduler) ticl.getResources().getInternalScheduler()).marshal());
  digester.update(state.toByteArray());
  AndroidTiclStateWithDigest verifiedState =
      AndroidTiclStateWithDigest.create(state, new Bytes(digester.getDigest()));
  return verifiedState;
}
 
Example #4
Source File: TiclStateManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  digester.update(state.getState().toByteArray());
  byte[] computedDigest = digester.getDigest();
  if (!TypedUtil.<Bytes>equals(new Bytes(computedDigest), state.getDigest())) {
    logger.warning("Android TICL state digest mismatch; computed %s for %s",
        computedDigest, state);
    return false;
  }
  return true;
}
 
Example #5
Source File: TiclStateManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  digester.update(state.getState().toByteArray());
  ByteString computedDigest = ByteString.copyFrom(digester.getDigest());
  if (!computedDigest.equals(state.getDigest())) {
    logger.warning("Android Ticl state digest mismatch; computed %s for %s",
        computedDigest, state);
    return false;
  }
  return true;
}
 
Example #6
Source File: TiclStateManager.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Returns whether the digest in {@code state} is correct. */
private static boolean isDigestValid(AndroidTiclStateWithDigest state, Logger logger) {
  Sha1DigestFunction digester = new Sha1DigestFunction();
  digester.update(state.getState().toByteArray());
  ByteString computedDigest = ByteString.copyFrom(digester.getDigest());
  if (!computedDigest.equals(state.getDigest())) {
    logger.warning("Android Ticl state digest mismatch; computed %s for %s",
        computedDigest, state);
    return false;
  }
  return true;
}