All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.whispersystems.libsignal.protocol.DecryptionErrorMessage Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
/**
 * Copyright (C) 2014-2016 Open Whisper Systems
 *
 * Licensed according to the LICENSE file in this repository.
 */
package org.whispersystems.libsignal.protocol;

import org.signal.client.internal.Native;

import org.whispersystems.libsignal.InvalidMessageException;
import org.whispersystems.libsignal.ecc.ECPublicKey;
import org.whispersystems.libsignal.util.guava.Optional;

public final class DecryptionErrorMessage {

  final long handle;

  @Override
  protected void finalize() {
     Native.DecryptionErrorMessage_Destroy(this.handle);
  }

  DecryptionErrorMessage(long handle) {
    this.handle = handle;
  }

  public DecryptionErrorMessage(byte[] serialized) throws InvalidMessageException {
    handle = Native.DecryptionErrorMessage_Deserialize(serialized);
  }

  public static DecryptionErrorMessage forOriginalMessage(byte[] originalBytes, int messageType, long timestamp, int originalSenderDeviceId) {
    return new DecryptionErrorMessage(
      Native.DecryptionErrorMessage_ForOriginalMessage(originalBytes, messageType, timestamp, originalSenderDeviceId));
  }

  public byte[] serialize() {
    return Native.DecryptionErrorMessage_GetSerialized(this.handle);
  }

  public Optional getRatchetKey() {
    long keyHandle = Native.DecryptionErrorMessage_GetRatchetKey(this.handle);
    if (keyHandle == 0) {
      return Optional.absent();
    } else {
      return Optional.of(new ECPublicKey(keyHandle));
    }
  }

  public long getTimestamp() {
    return Native.DecryptionErrorMessage_GetTimestamp(this.handle);
  }

  public int getDeviceId() {
    return Native.DecryptionErrorMessage_GetDeviceId(this.handle);
  }

  /// For testing only
  public static DecryptionErrorMessage extractFromSerializedContent(byte[] serializedContentBytes) throws InvalidMessageException {
    return new DecryptionErrorMessage(
      Native.DecryptionErrorMessage_ExtractFromSerializedContent(serializedContentBytes));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy