private byte[] createSentTranscriptMessage(byte[] content, May <SignalServiceAddress> recipient, ulong timestamp) { { try { Content.Builder container = Content.CreateBuilder(); SyncMessage.Builder syncMessage = SyncMessage.CreateBuilder(); SyncMessage.Types.Sent.Builder sentMessage = SyncMessage.Types.Sent.CreateBuilder(); sentMessage.SetTimestamp(timestamp); sentMessage.SetMessage(DataMessage.ParseFrom(content)); if (recipient.HasValue) { sentMessage.SetDestination(recipient.ForceGetValue().getNumber()); } return(container.SetSyncMessage(syncMessage.SetSent(sentMessage)).Build().ToByteArray());; } catch (InvalidProtocolBufferException e) { throw new Exception(e.Message); } } }
/** * Decrypt a received {@link org.whispersystems.textsecure.api.messages.TextSecureEnvelope} * * @param envelope The received TextSecureEnvelope * @return a decrypted TextSecureMessage * @throws InvalidVersionException * @throws InvalidMessageException * @throws InvalidKeyException * @throws DuplicateMessageException * @throws InvalidKeyIdException * @throws UntrustedIdentityException * @throws LegacyMessageException * @throws NoSessionException */ public TextSecureContent decrypt(TextSecureEnvelope envelope) { try { TextSecureContent content = new TextSecureContent(); if (envelope.hasLegacyMessage()) { DataMessage message = DataMessage.ParseFrom(decrypt(envelope, envelope.getLegacyMessage())); content = new TextSecureContent(createTextSecureMessage(envelope, message)); } else if (envelope.hasContent()) { Content message = Content.ParseFrom(decrypt(envelope, envelope.getContent())); if (message.HasDataMessage) { content = new TextSecureContent(createTextSecureMessage(envelope, message.DataMessage)); } else if (message.HasSyncMessage && localAddress.getNumber().Equals(envelope.getSource())) { content = new TextSecureContent(createSynchronizeMessage(envelope, message.SyncMessage)); } } return(content); } catch (InvalidProtocolBufferException e) { throw new InvalidMessageException(e); } }
private byte[] createMultiDeviceSentTranscriptContent(byte[] content, May <SignalServiceAddress> recipient, ulong timestamp) { try { Content.Builder container = Content.CreateBuilder(); SyncMessage.Builder syncMessage = SyncMessage.CreateBuilder(); SyncMessage.Types.Sent.Builder sentMessage = SyncMessage.Types.Sent.CreateBuilder(); DataMessage dataMessage = DataMessage.ParseFrom(content); sentMessage.SetTimestamp(timestamp); sentMessage.SetMessage(dataMessage); if (recipient.HasValue) { sentMessage.SetDestination(recipient.ForceGetValue().getNumber()); } if (dataMessage.ExpireTimer > 0) { sentMessage.SetExpirationStartTimestamp((ulong)Util.CurrentTimeMillis()); } return(container.SetSyncMessage(syncMessage.SetSent(sentMessage)).Build().ToByteArray()); } catch (InvalidProtocolBufferException e) { throw new Exception(e.Message); } }