|
1 /* |
|
2 * otr4j, the open source java otr library. |
|
3 * |
|
4 * Distributable under LGPL license. |
|
5 * See terms of license at gnu.org. |
|
6 */ |
|
7 package net.java.otr4j.io.messages; |
|
8 |
|
9 import java.util.Arrays; |
|
10 |
|
11 import javax.crypto.interfaces.DHPublicKey; |
|
12 |
|
13 /** |
|
14 * |
|
15 * @author George Politis |
|
16 */ |
|
17 public class DataMessage extends AbstractEncodedMessage { |
|
18 |
|
19 // Fields. |
|
20 public byte[] mac; |
|
21 public byte[] oldMACKeys; |
|
22 |
|
23 public int flags; |
|
24 public int senderKeyID; |
|
25 public int recipientKeyID; |
|
26 public DHPublicKey nextDH; |
|
27 public byte[] ctr; |
|
28 public byte[] encryptedMessage; |
|
29 |
|
30 // Ctor. |
|
31 public DataMessage(int protocolVersion, int flags, int senderKeyID, |
|
32 int recipientKeyID, DHPublicKey nextDH, byte[] ctr, |
|
33 byte[] encryptedMessage, byte[] mac, byte[] oldMacKeys) { |
|
34 super(MESSAGE_DATA, protocolVersion); |
|
35 |
|
36 this.flags = flags; |
|
37 this.senderKeyID = senderKeyID; |
|
38 this.recipientKeyID = recipientKeyID; |
|
39 this.nextDH = nextDH; |
|
40 this.ctr = ctr; |
|
41 this.encryptedMessage = encryptedMessage; |
|
42 this.mac = mac; |
|
43 this.oldMACKeys = oldMacKeys; |
|
44 } |
|
45 |
|
46 public DataMessage(MysteriousT t, byte[] mac, byte[] oldMacKeys) { |
|
47 this(t.protocolVersion, t.flags, t.senderKeyID, t.recipientKeyID, |
|
48 t.nextDH, t.ctr, t.encryptedMessage, mac, oldMacKeys); |
|
49 } |
|
50 |
|
51 // Methods. |
|
52 public MysteriousT getT() { |
|
53 return new MysteriousT(protocolVersion, flags, senderKeyID, |
|
54 recipientKeyID, nextDH, ctr, encryptedMessage); |
|
55 } |
|
56 |
|
57 @Override |
|
58 public int hashCode() { |
|
59 final int prime = 31; |
|
60 int result = super.hashCode(); |
|
61 result = prime * result + Arrays.hashCode(ctr); |
|
62 result = prime * result + Arrays.hashCode(encryptedMessage); |
|
63 result = prime * result + flags; |
|
64 result = prime * result + Arrays.hashCode(mac); |
|
65 // TODO: Needs work. |
|
66 result = prime * result + ((nextDH == null) ? 0 : nextDH.hashCode()); |
|
67 result = prime * result + Arrays.hashCode(oldMACKeys); |
|
68 result = prime * result + recipientKeyID; |
|
69 result = prime * result + senderKeyID; |
|
70 return result; |
|
71 } |
|
72 |
|
73 @Override |
|
74 public boolean equals(Object obj) { |
|
75 if (this == obj) |
|
76 return true; |
|
77 if (!super.equals(obj)) |
|
78 return false; |
|
79 if (getClass() != obj.getClass()) |
|
80 return false; |
|
81 DataMessage other = (DataMessage) obj; |
|
82 if (!Arrays.equals(ctr, other.ctr)) |
|
83 return false; |
|
84 if (!Arrays.equals(encryptedMessage, other.encryptedMessage)) |
|
85 return false; |
|
86 if (flags != other.flags) |
|
87 return false; |
|
88 if (!Arrays.equals(mac, other.mac)) |
|
89 return false; |
|
90 if (nextDH == null) { |
|
91 if (other.nextDH != null) |
|
92 return false; |
|
93 } else if (!nextDH.equals(other.nextDH)) |
|
94 return false; |
|
95 if (!Arrays.equals(oldMACKeys, other.oldMACKeys)) |
|
96 return false; |
|
97 if (recipientKeyID != other.recipientKeyID) |
|
98 return false; |
|
99 if (senderKeyID != other.senderKeyID) |
|
100 return false; |
|
101 return true; |
|
102 } |
|
103 } |