org.signal.libsignal.crypto.CryptographicHash Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signal-client-java Show documentation
Show all versions of signal-client-java Show documentation
Signal Protocol cryptography library for Java
The newest version!
//
// Copyright 2021 Signal Messenger, LLC.
// SPDX-License-Identifier: AGPL-3.0-only
//
package org.signal.libsignal.crypto;
import org.signal.client.internal.Native;
import org.signal.client.internal.NativeHandleGuard;
public class CryptographicHash implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public CryptographicHash(String algo) {
this.unsafeHandle = Native.CryptographicHash_New(algo);
}
public long unsafeNativeHandleWithoutGuard() {
return unsafeHandle;
}
@Override
protected void finalize() {
Native.CryptographicHash_Destroy(this.unsafeHandle);
}
public void update(byte[] input, int offset, int len) {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
Native.CryptographicHash_UpdateWithOffset(guard.nativeHandle(), input, offset, len);
}
}
public void update(byte[] input) {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
Native.CryptographicHash_Update(guard.nativeHandle(), input);
}
}
public byte[] finish() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.CryptographicHash_Finalize(guard.nativeHandle());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy