use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content in project libsignal-service-java by signalapp.
the class SignalServiceMessageSender method createMultiDeviceSentTranscriptContent.
private byte[] createMultiDeviceSentTranscriptContent(byte[] content, Optional<SignalServiceAddress> recipient, long timestamp) {
try {
Content.Builder container = Content.newBuilder();
SyncMessage.Builder syncMessage = createSyncMessageBuilder();
SyncMessage.Sent.Builder sentMessage = SyncMessage.Sent.newBuilder();
DataMessage dataMessage = Content.parseFrom(content).getDataMessage();
sentMessage.setTimestamp(timestamp);
sentMessage.setMessage(dataMessage);
if (recipient.isPresent()) {
sentMessage.setDestination(recipient.get().getNumber());
}
if (dataMessage.getExpireTimer() > 0) {
sentMessage.setExpirationStartTimestamp(System.currentTimeMillis());
}
return container.setSyncMessage(syncMessage.setSent(sentMessage)).build().toByteArray();
} catch (InvalidProtocolBufferException e) {
throw new AssertionError(e);
}
}
use of org.whispersystems.signalservice.internal.push.SignalServiceProtos.Content in project libsignal-service-java by signalapp.
the class SignalServiceCipher method decrypt.
/**
* Decrypt a received {@link SignalServiceEnvelope}
*
* @param envelope The received SignalServiceEnvelope
*
* @return a decrypted SignalServiceContent
* @throws InvalidVersionException
* @throws InvalidMessageException
* @throws InvalidKeyException
* @throws DuplicateMessageException
* @throws InvalidKeyIdException
* @throws UntrustedIdentityException
* @throws LegacyMessageException
* @throws NoSessionException
*/
public SignalServiceContent decrypt(SignalServiceEnvelope envelope) throws InvalidVersionException, InvalidMessageException, InvalidKeyException, DuplicateMessageException, InvalidKeyIdException, UntrustedIdentityException, LegacyMessageException, NoSessionException {
try {
SignalServiceContent content = new SignalServiceContent();
if (envelope.hasLegacyMessage()) {
DataMessage message = DataMessage.parseFrom(decrypt(envelope, envelope.getLegacyMessage()));
content = new SignalServiceContent(createSignalServiceMessage(envelope, message));
} else if (envelope.hasContent()) {
Content message = Content.parseFrom(decrypt(envelope, envelope.getContent()));
if (message.hasDataMessage()) {
content = new SignalServiceContent(createSignalServiceMessage(envelope, message.getDataMessage()));
} else if (message.hasSyncMessage() && localAddress.getNumber().equals(envelope.getSource())) {
content = new SignalServiceContent(createSynchronizeMessage(envelope, message.getSyncMessage()));
} else if (message.hasCallMessage()) {
content = new SignalServiceContent(createCallMessage(message.getCallMessage()));
} else if (message.hasReceiptMessage()) {
content = new SignalServiceContent(createReceiptMessage(envelope, message.getReceiptMessage()));
}
}
return content;
} catch (InvalidProtocolBufferException e) {
throw new InvalidMessageException(e);
}
}
Aggregations