001/** 002 * 003 * Copyright 2017 Paul Schaub 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smackx.omemo.internal; 018 019/** 020 * Class that contains information about a decrypted message (eg. which key was used, if it was a carbon...). 021 * 022 * @author Paul Schaub 023 */ 024public class OmemoMessageInformation { 025 private boolean isOmemoMessage; 026 private IdentityKeyWrapper senderIdentityKey; 027 private OmemoDevice senderDevice; 028 private CARBON carbon = CARBON.NONE; 029 030 /** 031 * Empty constructor. 032 */ 033 // TOOD Move this class into smackx.omemo and make this constructor package protected. -Flow 034 public OmemoMessageInformation() { 035 } 036 037 /** 038 * Creates a new OmemoMessageInformation object. Its assumed, that this is about an OMEMO message. 039 * 040 * @param senderIdentityKey identityKey of the sender device 041 * @param senderDevice device that sent the message 042 * @param carbon Carbon type 043 */ 044 public OmemoMessageInformation(IdentityKeyWrapper senderIdentityKey, OmemoDevice senderDevice, CARBON carbon) { 045 this.senderIdentityKey = senderIdentityKey; 046 this.senderDevice = senderDevice; 047 this.carbon = carbon; 048 this.isOmemoMessage = true; 049 } 050 051 /** 052 * Create a new OmemoMessageInformation. 053 * 054 * @param senderIdentityKey identityKey of the sender device 055 * @param senderDevice device that sent the message 056 * @param carbon Carbon type 057 * @param omemo is this an omemo message? 058 */ 059 public OmemoMessageInformation(IdentityKeyWrapper senderIdentityKey, OmemoDevice senderDevice, CARBON carbon, boolean omemo) { 060 this(senderIdentityKey, senderDevice, carbon); 061 this.isOmemoMessage = omemo; 062 } 063 064 /** 065 * Return the sender devices identityKey. 066 * 067 * @return identityKey 068 */ 069 public IdentityKeyWrapper getSenderIdentityKey() { 070 return senderIdentityKey; 071 } 072 073 /** 074 * Set the sender devices identityKey. 075 * 076 * @param senderIdentityKey identityKey 077 */ 078 public void setSenderIdentityKey(IdentityKeyWrapper senderIdentityKey) { 079 this.senderIdentityKey = senderIdentityKey; 080 } 081 082 /** 083 * Return the sender device. 084 * 085 * @return sender device 086 */ 087 public OmemoDevice getSenderDevice() { 088 return senderDevice; 089 } 090 091 /** 092 * Return true, if this is (was) an OMEMO message. 093 * @return true if omemo 094 */ 095 public boolean isOmemoMessage() { 096 return this.isOmemoMessage; 097 } 098 099 /** 100 * Set the sender device. 101 * 102 * @param senderDevice sender device 103 */ 104 public void setSenderDevice(OmemoDevice senderDevice) { 105 this.senderDevice = senderDevice; 106 } 107 108 /** 109 * Return the carbon type. 110 * 111 * @return carbon type 112 */ 113 public CARBON getCarbon() { 114 return carbon; 115 } 116 117 /** 118 * Set the carbon type. 119 * 120 * @param carbon carbon type 121 */ 122 public void setCarbon(CARBON carbon) { 123 this.carbon = carbon; 124 } 125 126 /** 127 * Types of Carbon Messages. 128 */ 129 public enum CARBON { 130 NONE, //No carbon 131 SENT, //Sent carbon 132 RECV //Received Carbon 133 } 134 135 @Override 136 public String toString() { 137 return (senderDevice != null ? senderDevice.toString() : "") + " " + carbon; 138 } 139} 140 141