Class OmemoMessageBuilder<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph>
- java.lang.Object
-
- org.jivesoftware.smackx.omemo.util.OmemoMessageBuilder<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph>
-
- Type Parameters:
T_IdKeyPair
- IdentityKeyPair classT_IdKey
- IdentityKey classT_PreKey
- PreKey classT_SigPreKey
- SignedPreKey classT_Sess
- Session classT_Addr
- Address classT_ECPub
- Elliptic Curve PublicKey classT_Bundle
- Bundle classT_Ciph
- Cipher class
public class OmemoMessageBuilder<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> extends Object
Class used to build OMEMO messages.
-
-
Constructor Summary
Constructors Constructor Description OmemoMessageBuilder(OmemoDevice userDevice, OmemoTrustCallback callback, OmemoRatchet<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> ratchet, byte[] aesKey, byte[] iv, String message)
Create an OmemoMessageBuilder.OmemoMessageBuilder(OmemoDevice userDevice, OmemoTrustCallback callback, OmemoRatchet<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> ratchet, String message)
Create an OmemoMessageBuilder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRecipient(OmemoDevice contactsDevice)
Add a new recipient device to the message.OmemoElement
finish()
Assemble an OmemoMessageElement from the current state of the builder.static byte[]
generateIv()
Generate a 12 byte initialization vector for AES encryption.static byte[]
generateKey(String keyType, int keyLength)
Generate a new AES key used to encrypt the message.
-
-
-
Constructor Detail
-
OmemoMessageBuilder
public OmemoMessageBuilder(OmemoDevice userDevice, OmemoTrustCallback callback, OmemoRatchet<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> ratchet, byte[] aesKey, byte[] iv, String message) throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidAlgorithmParameterException
Create an OmemoMessageBuilder.- Parameters:
userDevice
- our OmemoDevicecallback
- trustCallback for querying trust decisionsratchet
- our OmemoRatchetaesKey
- aes message key used for message encryptioniv
- initialization vector used for message encryptionmessage
- message we want to send- Throws:
NoSuchPaddingException
- if the requested padding mechanism is not availble.BadPaddingException
- if the input data is not padded properly.InvalidKeyException
- if the key is invalid.NoSuchAlgorithmException
- if no such algorithm is available.IllegalBlockSizeException
- if the input data length is incorrect.InvalidAlgorithmParameterException
- if the provided arguments are invalid.
-
OmemoMessageBuilder
public OmemoMessageBuilder(OmemoDevice userDevice, OmemoTrustCallback callback, OmemoRatchet<T_IdKeyPair,T_IdKey,T_PreKey,T_SigPreKey,T_Sess,T_Addr,T_ECPub,T_Bundle,T_Ciph> ratchet, String message) throws NoSuchPaddingException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, IllegalBlockSizeException, InvalidAlgorithmParameterException
Create an OmemoMessageBuilder.- Parameters:
userDevice
- our OmemoDevicecallback
- trustCallback for querying trust decisionsratchet
- our OmemoRatchetmessage
- message we want to send- Throws:
NoSuchPaddingException
- if the requested padding mechanism is not availble.BadPaddingException
- if the input data is not padded properly.InvalidKeyException
- if the key is invalid.NoSuchAlgorithmException
- if no such algorithm is available.IllegalBlockSizeException
- if the input data length is incorrect.InvalidAlgorithmParameterException
- if the provided arguments are invalid.
-
-
Method Detail
-
addRecipient
public void addRecipient(OmemoDevice contactsDevice) throws NoIdentityKeyException, CorruptedOmemoKeyException, UndecidedOmemoIdentityException, UntrustedOmemoIdentityException, IOException
Add a new recipient device to the message.- Parameters:
contactsDevice
- device of the recipient- Throws:
NoIdentityKeyException
- if we have no identityKey of that device. Can be fixed by fetching and processing the devices bundle.CorruptedOmemoKeyException
- if the identityKey of that device is corrupted.UndecidedOmemoIdentityException
- if the user hasn't yet decided whether to trust that device or not.UntrustedOmemoIdentityException
- if the user has decided not to trust that device.IOException
- if an I/O error occurred.
-
finish
public OmemoElement finish()
Assemble an OmemoMessageElement from the current state of the builder.- Returns:
- OMEMO element
-
generateKey
public static byte[] generateKey(String keyType, int keyLength) throws NoSuchAlgorithmException
Generate a new AES key used to encrypt the message.- Parameters:
keyType
- Key TypekeyLength
- Key Length in bit- Returns:
- new AES key
- Throws:
NoSuchAlgorithmException
- if no such algorithm is available.
-
generateIv
public static byte[] generateIv()
Generate a 12 byte initialization vector for AES encryption.- Returns:
- initialization vector
-
-