Search in sources :

Example 1 with EncryptionResult

use of org.pgpainless.encryption_signing.EncryptionResult in project Smack by igniterealtime.

the class OXInstantMessagingManager method sendOxMessage.

/**
 * Send an OX message to a {@link OpenPgpContact}. The message will be encrypted to all active keys of the contact,
 * as well as all of our active keys. The message is also signed with our key.
 *
 * @param contact contact capable of OpenPGP for XMPP: Instant Messaging.
 * @param body message body.
 *
 * @return {@link EncryptionResult} containing metadata about the messages encryption + signatures.
 *
 * @throws InterruptedException if the thread is interrupted
 * @throws IOException IO is dangerous
 * @throws SmackException.NotConnectedException if we are not connected
 * @throws SmackException.NotLoggedInException if we are not logged in
 * @throws PGPException PGP is brittle
 */
public EncryptionResult sendOxMessage(OpenPgpContact contact, CharSequence body) throws InterruptedException, IOException, SmackException.NotConnectedException, SmackException.NotLoggedInException, PGPException {
    MessageBuilder messageBuilder = connection().getStanzaFactory().buildMessageStanza().to(contact.getJid());
    Message.Body mBody = new Message.Body(null, body.toString());
    EncryptionResult metadata = addOxMessage(messageBuilder, contact, Collections.<ExtensionElement>singletonList(mBody));
    Message message = messageBuilder.build();
    ChatManager.getInstanceFor(connection()).chatWith(contact.getJid().asEntityBareJidIfPossible()).send(message);
    return metadata;
}
Also used : MessageBuilder(org.jivesoftware.smack.packet.MessageBuilder) OpenPgpMessage(org.jivesoftware.smackx.ox.OpenPgpMessage) Message(org.jivesoftware.smack.packet.Message) EncryptionResult(org.pgpainless.encryption_signing.EncryptionResult)

Aggregations

Message (org.jivesoftware.smack.packet.Message)1 MessageBuilder (org.jivesoftware.smack.packet.MessageBuilder)1 OpenPgpMessage (org.jivesoftware.smackx.ox.OpenPgpMessage)1 EncryptionResult (org.pgpainless.encryption_signing.EncryptionResult)1