use of org.whispersystems.signalservice.internal.serialize.protos.SignalServiceContentProto in project Signal-Android by WhisperSystems.
the class SignalServiceCipher method decrypt.
/**
* Decrypt a received {@link SignalServiceEnvelope}
*
* @param envelope The received SignalServiceEnvelope
*
* @return a decrypted SignalServiceContent
*/
public SignalServiceContent decrypt(SignalServiceEnvelope envelope) throws InvalidMetadataMessageException, InvalidMetadataVersionException, ProtocolInvalidKeyIdException, ProtocolLegacyMessageException, ProtocolUntrustedIdentityException, ProtocolNoSessionException, ProtocolInvalidVersionException, ProtocolInvalidMessageException, ProtocolInvalidKeyException, ProtocolDuplicateMessageException, SelfSendException, UnsupportedDataMessageException, InvalidMessageStructureException {
try {
if (envelope.hasLegacyMessage()) {
Plaintext plaintext = decrypt(envelope, envelope.getLegacyMessage());
SignalServiceProtos.DataMessage dataMessage = SignalServiceProtos.DataMessage.parseFrom(plaintext.getData());
SignalServiceContentProto contentProto = SignalServiceContentProto.newBuilder().setLocalAddress(SignalServiceAddressProtobufSerializer.toProtobuf(localAddress)).setMetadata(SignalServiceMetadataProtobufSerializer.toProtobuf(plaintext.metadata)).setLegacyDataMessage(dataMessage).build();
return SignalServiceContent.createFromProto(contentProto);
} else if (envelope.hasContent()) {
Plaintext plaintext = decrypt(envelope, envelope.getContent());
SignalServiceProtos.Content content = SignalServiceProtos.Content.parseFrom(plaintext.getData());
SignalServiceContentProto contentProto = SignalServiceContentProto.newBuilder().setLocalAddress(SignalServiceAddressProtobufSerializer.toProtobuf(localAddress)).setMetadata(SignalServiceMetadataProtobufSerializer.toProtobuf(plaintext.metadata)).setContent(content).build();
return SignalServiceContent.createFromProto(contentProto);
}
return null;
} catch (InvalidProtocolBufferException e) {
throw new InvalidMetadataMessageException(e);
}
}
Aggregations