2020 * can be encrypted.
2121 */
2222public class InMemoSNMessage implements SNMessage {
23+ private ASAPCryptoAlgorithms .EncryptedMessagePackage encryptedMessagePackage ;
2324 private byte [] snContent ;
24- private final CharSequence snSender ;
25+ private CharSequence snSender ;
2526 private boolean verified ;
2627 private boolean encrypted ;
2728 private Set <CharSequence > snRecipients ;
@@ -45,6 +46,12 @@ private InMemoSNMessage(byte[] message, CharSequence sender,
4546 this .creationTime = creationTime ;
4647 }
4748
49+ private InMemoSNMessage (ASAPCryptoAlgorithms .EncryptedMessagePackage encryptedMessagePackage ) {
50+ this .encryptedMessagePackage = encryptedMessagePackage ;
51+ this .snRecipients = new HashSet <>();
52+ this .snRecipients .add (encryptedMessagePackage .getRecipient ());
53+ }
54+
4855 public static byte [] serializeMessage (byte [] content , CharSequence sender , CharSequence recipient )
4956 throws IOException , ASAPException {
5057
@@ -144,23 +151,60 @@ public static byte[] serializeMessage(byte[] content, CharSequence sender, Set<C
144151 }
145152
146153 @ Override
147- public byte [] getContent () { return this .snContent ;}
154+ public byte [] getContent () throws ASAPSecurityException {
155+ if (this .encryptedMessagePackage != null ) {
156+ throw new ASAPSecurityException ("content could not be encrypted" );
157+ }
158+ return this .snContent ;
159+ }
160+
148161 @ Override
149- public CharSequence getSender () { return this .snSender ; }
162+ public CharSequence getSender () throws ASAPSecurityException {
163+ if (this .encryptedMessagePackage != null ) {
164+ throw new ASAPSecurityException ("content could not be encrypted" );
165+ }
166+
167+ return this .snSender ;
168+ }
169+
150170 @ Override
151- public Set <CharSequence > getRecipients () { return this .snRecipients ; }
171+ public Set <CharSequence > getRecipients () {
172+ return this .snRecipients ;
173+ }
174+
152175 @ Override
153- public boolean verified () { return this .verified ; }
176+ public boolean verified () throws ASAPSecurityException {
177+ if (this .encryptedMessagePackage != null ) {
178+ throw new ASAPSecurityException ("content could not be encrypted" );
179+ }
180+
181+ return this .verified ;
182+ }
183+
154184 @ Override
155- public boolean encrypted () { return this .encrypted ; }
185+ public boolean encrypted () {
186+ return this .encrypted ;
187+ }
188+
189+ public boolean couldBeDecrypted () {
190+ return this .encryptedMessagePackage != null ;
191+ }
156192
157193 @ Override
158- public Timestamp getCreationTime () {
194+ public Timestamp getCreationTime () throws ASAPSecurityException {
195+ if (this .encryptedMessagePackage != null ) {
196+ throw new ASAPSecurityException ("content could not be encrypted" );
197+ }
198+
159199 return this .creationTime ;
160200 }
161201
162202 @ Override
163203 public boolean isLaterThan (SNMessage message ) throws ASAPException , IOException {
204+ if (this .encryptedMessagePackage != null ) {
205+ throw new ASAPSecurityException ("content could not be encrypted" );
206+ }
207+
164208 Timestamp messageCreationTime = message .getCreationTime ();
165209 return messageCreationTime .after (this .getCreationTime ());
166210 }
@@ -194,7 +238,8 @@ public static InMemoSNMessage parseMessage(byte[] message, BasicKeyStore basicKe
194238
195239 // for me?
196240 if (!basicKeyStore .isOwner (encryptedMessagePackage .getRecipient ())) {
197- throw new ASAPException ("SharkNetMessage: message not for me" );
241+ return new InMemoSNMessage (encryptedMessagePackage );
242+ //throw new ASAPException("SharkNetMessage: message not for me");
198243 }
199244
200245 // replace message with decrypted message
0 commit comments