public final class Ffi extends Object
| Constructor and Description |
|---|
Ffi(FfiWrapper instance,
Specifications abeSpecifications) |
| Modifier and Type | Method and Description |
|---|---|
int |
createDecryptionCache(byte[] userDecryptionKeyBytes)
Create a decryption cache that can be used with
decryptHeaderUsingCache(int, byte[]) Use of the cache
speeds up the decryption of the header. |
int |
createDecryptionCache(PrivateKey userDecryptionKey)
Create an decryption cache that can be used with
decryptHeaderUsingCache(int, byte[]) Use of the cache
speeds up decryption of the header WARN: the cache MUST be destroyed after use with
destroyDecryptionCache(int) |
int |
createEncryptionCache(Policy policy,
byte[] publicKeyBytes)
Create an encryption cache that can be used with
encryptHeaderUsingCache(int, Attr[]) Use of the cache
speeds up the encryption of the header. |
int |
createEncryptionCache(PublicKey publicKey)
Create an encryption cache that can be used with
encryptHeaderUsingCache(int, Attr[]) se of the cache
speeds up the encryption of the header. |
byte[] |
decryptBlock(byte[] symmetricKey,
byte[] encryptedBytes)
Symmetrically decrypt a block of encrypted data.
|
byte[] |
decryptBlock(byte[] symmetricKey,
byte[] uid,
int blockNumber,
byte[] encryptedBytes)
Symmetrically decrypt a block of encrypted data.
|
DecryptedHeader |
decryptHeader(byte[] userDecryptionKeyBytes,
byte[] encryptedHeaderBytes,
int uidLen,
int additionalDataLen)
Decrypt a hybrid header, recovering the symmetric key, and optionally, the resource UID and additional data
|
DecryptedHeader |
decryptHeader(PrivateKey userDecryptionKey,
byte[] encryptedHeaderBytes)
Decrypt a hybrid header, recovering the symmetric key
|
DecryptedHeader |
decryptHeader(PrivateKey userDecryptionKey,
byte[] encryptedHeaderBytes,
int uidLen,
int additionalDataLen)
Decrypt a hybrid header, recovering the symmetric key, and optionally, the resource UID and additional data
|
DecryptedHeader |
decryptHeaderUsingCache(int cacheHandle,
byte[] encryptedHeaderBytes)
Decrypt a hybrid header using a cache, recovering the symmetric key
|
DecryptedHeader |
decryptHeaderUsingCache(int cacheHandle,
byte[] encryptedHeaderBytes,
int uidLen,
int additionalDataLen)
Decrypt a hybrid header using a cache, recovering the symmetric key, and optionally, the resource UID and
additional data
|
void |
destroyDecryptionCache(int cacheHandle)
Destroy the cache created with
createDecryptionCache(byte[]) |
void |
destroyEncryptionCache(int cacheHandle)
Destroy the cache created with
createEncryptionCache(Policy, byte[]) |
byte[] |
encryptBlock(byte[] symmetricKey,
byte[] clearText)
Symmetrically encrypt a block of clear text data.
|
byte[] |
encryptBlock(byte[] symmetricKey,
byte[] uid,
int blockNumber,
byte[] clearText)
Symmetrically encrypt a block of clear text data.
|
EncryptedHeader |
encryptHeader(Policy policy,
byte[] publicKeyBytes,
Attr[] attributes,
Optional<byte[]> uid,
Optional<byte[]> additionalData)
Generate an hybrid encryption header.
|
EncryptedHeader |
encryptHeader(PublicKey publicKey,
Attr[] attributes)
Generate an hybrid encryption header.
|
EncryptedHeader |
encryptHeader(PublicKey publicKey,
Attr[] attributes,
Optional<byte[]> uid,
Optional<byte[]> additionalData)
Generate an hybrid encryption header.
|
EncryptedHeader |
encryptHeaderUsingCache(int cacheHandle,
Attr[] attributes)
Generate an hybrid encryption header using a pre-cached Public Key and Policy.
|
EncryptedHeader |
encryptHeaderUsingCache(int cacheHandle,
Attr[] attributes,
Optional<byte[]> uid,
Optional<byte[]> additionalData)
Generate an hybrid encryption header using a pre-cached Public Key and Policy.
|
MasterKeys |
generateMasterKeys(Policy policy)
Generate the master private and public keys using the ABE policy
|
byte[] |
generateUserPrivateKey(byte[] masterPrivateKey,
AccessPolicy accessPolicy,
Policy policy)
Generate the user private key
|
String |
get_last_error()
Return the last error in a String that does not exceed 1023 bytes
|
String |
get_last_error(int max_len)
Return the last error in a String that does not exceed `max_len` bytes
|
Policy |
rotateAttributes(Attr[] attributes,
Policy policy)
Rotate attributes, changing their underlying value with that of an unused slot
|
void |
set_error(String error_msg)
Set the last error on the native lib
|
int |
symmetricEncryptionOverhead()
The overhead in bytes (over the clear text) generated by the symmetric encryption scheme (AES 256 GCM)
|
void |
unwrap(int result)
If the result of the last FFI call is in Error, recover the last error from the native code and throw an
exception wrapping it.
|
public Ffi(FfiWrapper instance, Specifications abeSpecifications)
public String get_last_error() throws FfiException
FfiException - in case of native library errorpublic String get_last_error(int max_len) throws FfiException
max_len - the maximum number of bytes to returnFfiException - in case of native library errorpublic void set_error(String error_msg) throws FfiException
error_msg - the last error to set on the native libFfiException - n case of native library errorpublic int createEncryptionCache(PublicKey publicKey) throws FfiException, CosmianException
encryptHeaderUsingCache(int, Attr[]) se of the cache
speeds up the encryption of the header. WARN: the cache MUST be destroyed after use with
destroyEncryptionCache(int)publicKey - the public key to cacheFfiException - on Rust lib errorsCosmianException - in case of other errorspublic int createEncryptionCache(Policy policy, byte[] publicKeyBytes) throws FfiException, CosmianException
encryptHeaderUsingCache(int, Attr[]) Use of the cache
speeds up the encryption of the header. WARN: the cache MUST be destroyed after use with
destroyEncryptionCache(int)policy - the Policy to cachepublicKeyBytes - the public key bytes to cacheFfiException - on Rust lib errorsCosmianException - in case of other errorspublic void destroyEncryptionCache(int cacheHandle)
throws FfiException,
CosmianException
createEncryptionCache(Policy, byte[])cacheHandle - the pointer to the cache to destroyFfiException - on Rust lib errorsCosmianException - in case of other errorspublic EncryptedHeader encryptHeaderUsingCache(int cacheHandle, Attr[] attributes) throws FfiException, CosmianException
cacheHandle - the pointer to the intattributes - the policy attributes used to encrypt the generated symmetric keyFfiException - in case of native library errorCosmianException - in case the Policy and key bytes cannot be recovered from the PublicKeypublic EncryptedHeader encryptHeaderUsingCache(int cacheHandle, Attr[] attributes, Optional<byte[]> uid, Optional<byte[]> additionalData) throws FfiException, CosmianException
cacheHandle - the pointer to the intattributes - the policy attributes used to encrypt the generated symmetric keyuid - the optional resource uidadditionalData - optional additional dataFfiException - in case of native library errorCosmianException - in case the Policy and key bytes cannot be recovered from the PublicKeypublic EncryptedHeader encryptHeader(PublicKey publicKey, Attr[] attributes) throws FfiException, CosmianException
publicKey - the ABE public key also holds the Policyattributes - the policy attributes used to encrypt the generated symmetric keyFfiException - in case of native library errorCosmianException - in case the Policy and key bytes cannot be recovered from the PublicKeypublic EncryptedHeader encryptHeader(PublicKey publicKey, Attr[] attributes, Optional<byte[]> uid, Optional<byte[]> additionalData) throws FfiException, CosmianException
publicKey - the ABE public key also holds the Policyattributes - the policy attributes used to encrypt the generated symmetric keyuid - the optional resource uidadditionalData - optional additional dataFfiException - in case of native library errorCosmianException - in case the Policy and key bytes cannot be recovered from the PublicKeypublic EncryptedHeader encryptHeader(Policy policy, byte[] publicKeyBytes, Attr[] attributes, Optional<byte[]> uid, Optional<byte[]> additionalData) throws FfiException
policy - the policy to usepublicKeyBytes - the ABE public key bytesattributes - the policy attributes used to encrypt the generated symmetric keyuid - the optional resource uidadditionalData - optional additional dataFfiException - in case of native library errorpublic int createDecryptionCache(PrivateKey userDecryptionKey) throws FfiException, CosmianException
decryptHeaderUsingCache(int, byte[]) Use of the cache
speeds up decryption of the header WARN: the cache MUST be destroyed after use with
destroyDecryptionCache(int)userDecryptionKey - the public key to cacheFfiException - on Rust lib errorsCosmianException - in case of other errorspublic int createDecryptionCache(byte[] userDecryptionKeyBytes)
throws FfiException,
CosmianException
decryptHeaderUsingCache(int, byte[]) Use of the cache
speeds up the decryption of the header. WARN: the cache MUST be destroyed after use with
destroyDecryptionCache(int)userDecryptionKeyBytes - the public key bytes to cacheFfiException - on Rust lib errorsCosmianException - in case of other errorspublic void destroyDecryptionCache(int cacheHandle)
throws FfiException,
CosmianException
createDecryptionCache(byte[])cacheHandle - the pointer to the cache to destroyFfiException - on Rust lib errorsCosmianException - in case of other errorspublic DecryptedHeader decryptHeaderUsingCache(int cacheHandle, byte[] encryptedHeaderBytes) throws FfiException, CosmianException
cacheHandle - the cache to the user decryption keyencryptedHeaderBytes - the encrypted headerFfiException - in case of native library errorCosmianException - in case the key bytes cannot be recovered from the PrivateKeypublic DecryptedHeader decryptHeaderUsingCache(int cacheHandle, byte[] encryptedHeaderBytes, int uidLen, int additionalDataLen) throws FfiException
cacheHandle - the cache to the user decryption keyencryptedHeaderBytes - the encrypted headeruidLen - the maximum bytes length of the expected UIDadditionalDataLen - the maximum bytes length of the expected additional dataFfiException - in case of native library errorpublic DecryptedHeader decryptHeader(PrivateKey userDecryptionKey, byte[] encryptedHeaderBytes) throws FfiException, CosmianException
userDecryptionKey - the ABE user decryption keyencryptedHeaderBytes - the encrypted headerFfiException - in case of native library errorCosmianException - in case the key bytes cannot be recovered from the PrivateKeypublic DecryptedHeader decryptHeader(PrivateKey userDecryptionKey, byte[] encryptedHeaderBytes, int uidLen, int additionalDataLen) throws FfiException, CosmianException
userDecryptionKey - the ABE user decryption keyencryptedHeaderBytes - the encrypted headeruidLen - the maximum bytes length of the expected UIDadditionalDataLen - the maximum bytes length of the expected additional dataFfiException - in case of native library errorCosmianException - in case the key bytes cannot be recovered from the PrivateKeypublic DecryptedHeader decryptHeader(byte[] userDecryptionKeyBytes, byte[] encryptedHeaderBytes, int uidLen, int additionalDataLen) throws FfiException
userDecryptionKeyBytes - the ABE user decryption key bytesencryptedHeaderBytes - the encrypted headeruidLen - the maximum bytes length of the expected UIDadditionalDataLen - the maximum bytes length of the expected additional dataFfiException - in case of native library errorpublic int symmetricEncryptionOverhead()
public byte[] encryptBlock(byte[] symmetricKey,
byte[] clearText)
throws FfiException
symmetricKey - The key to use to symmetrically encrypt the blockclearText - the clear text to encryptFfiException - in case of native library errorpublic byte[] encryptBlock(byte[] symmetricKey,
byte[] uid,
int blockNumber,
byte[] clearText)
throws FfiException
symmetricKey - The key to use to symmetrically encrypt the blockuid - The resource UIDblockNumber - the block number when the resource is split in multiple blocksclearText - the clear text to encryptFfiException - in case of native library errorpublic byte[] decryptBlock(byte[] symmetricKey,
byte[] encryptedBytes)
throws FfiException
symmetricKey - the symmetric key to useencryptedBytes - the encrypted block bytesFfiException - in case of native library errorpublic byte[] decryptBlock(byte[] symmetricKey,
byte[] uid,
int blockNumber,
byte[] encryptedBytes)
throws FfiException
symmetricKey - the symmetric key to useuid - the resource UIDblockNumber - the block number of the resourceencryptedBytes - the encrypted block bytesFfiException - in case of native library errorpublic MasterKeys generateMasterKeys(Policy policy) throws FfiException
policy - the policy to useFfiException - in case of native library errorpublic byte[] generateUserPrivateKey(byte[] masterPrivateKey,
AccessPolicy accessPolicy,
Policy policy)
throws FfiException
masterPrivateKey - the master private key in bytesaccessPolicy - the access policy of the user private keypolicy - the ABE policyFfiException - in case of native library errorpublic Policy rotateAttributes(Attr[] attributes, Policy policy) throws FfiException, com.fasterxml.jackson.core.exc.StreamReadException, com.fasterxml.jackson.databind.DatabindException, IOException
attributes: - a list of attributes to rotatepolicy: - the current policy returns the new PolicyFfiException - in case of native library errorIOException - standard IO exceptionscom.fasterxml.jackson.databind.DatabindException - standard databind exceptionscom.fasterxml.jackson.core.exc.StreamReadException - stream read exceptionspublic void unwrap(int result)
throws FfiException
result - the result of the FFI callFfiException - in case of native library errorCopyright © 2022. All rights reserved.