org.signal.libsignal.protocol.kem.KEMSecretKey Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of libsignal-client Show documentation
Show all versions of libsignal-client Show documentation
Signal Protocol cryptography library for Java
//
// Copyright 2023 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
package org.signal.libsignal.protocol.kem;
import static org.signal.libsignal.internal.FilterExceptions.filterExceptions;
import org.signal.libsignal.internal.Native;
import org.signal.libsignal.internal.NativeHandleGuard;
import org.signal.libsignal.protocol.InvalidKeyException;
public class KEMSecretKey implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public KEMSecretKey(byte[] privateKey) throws InvalidKeyException {
this.unsafeHandle =
filterExceptions(
InvalidKeyException.class, () -> Native.KyberSecretKey_Deserialize(privateKey));
}
public KEMSecretKey(long nativeHandle) {
if (nativeHandle == 0) {
throw new NullPointerException();
}
this.unsafeHandle = nativeHandle;
}
@Override
@SuppressWarnings("deprecation")
protected void finalize() {
Native.KyberSecretKey_Destroy(this.unsafeHandle);
}
public byte[] serialize() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return filterExceptions(() -> Native.KyberSecretKey_Serialize(guard.nativeHandle()));
}
}
public long unsafeNativeHandleWithoutGuard() {
return this.unsafeHandle;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy