org.signal.libsignal.crypto.CryptographicMac 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 CryptographicMac implements NativeHandleGuard.Owner {
private final long unsafeHandle;
public CryptographicMac(String algo, byte[] key) {
this.unsafeHandle = Native.CryptographicMac_New(algo, key);
}
@Override
protected void finalize() {
Native.CryptographicMac_Destroy(this.unsafeHandle);
}
public long unsafeNativeHandleWithoutGuard() {
return this.unsafeHandle;
}
public void update(byte[] input, int offset, int len) {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
Native.CryptographicMac_UpdateWithOffset(guard.nativeHandle(), input, offset, len);
}
}
public void update(byte[] input) {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
Native.CryptographicMac_Update(guard.nativeHandle(), input);
}
}
public byte[] finish() {
try (NativeHandleGuard guard = new NativeHandleGuard(this)) {
return Native.CryptographicMac_Finalize(guard.nativeHandle());
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy