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

org.signal.libsignal.zkgroup.profiles.ProfileKey Maven / Gradle / Ivy

There is a newer version: 0.62.0
Show newest version
//
// Copyright 2020-2021 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//

package org.signal.libsignal.zkgroup.profiles;

import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;

import org.signal.libsignal.internal.Native;
import org.signal.libsignal.protocol.ServiceId.Aci;
import org.signal.libsignal.zkgroup.InvalidInputException;
import org.signal.libsignal.zkgroup.internal.ByteArray;

public final class ProfileKey extends ByteArray {

  public ProfileKey(byte[] contents) throws InvalidInputException {
    super(contents);
    filterExceptions(
        InvalidInputException.class,
        () ->
            filterExceptions(
                InvalidInputException.class, () -> Native.ProfileKey_CheckValidContents(contents)));
  }

  public ProfileKeyCommitment getCommitment(Aci userId) {
    byte[] newContents =
        Native.ProfileKey_GetCommitment(contents, userId.toServiceIdFixedWidthBinary());

    try {
      return new ProfileKeyCommitment(newContents);
    } catch (InvalidInputException e) {
      throw new AssertionError(e);
    }
  }

  public ProfileKeyVersion getProfileKeyVersion(Aci userId) {
    byte[] newContents =
        Native.ProfileKey_GetProfileKeyVersion(contents, userId.toServiceIdFixedWidthBinary());

    try {
      return new ProfileKeyVersion(newContents);
    } catch (InvalidInputException e) {
      throw new AssertionError(e);
    }
  }

  public byte[] deriveAccessKey() {
    return Native.ProfileKey_DeriveAccessKey(contents);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy