/// <summary> /// Decrypt a received <see cref="SignalServiceEnvelope"/> /// </summary> /// <param name="envelope">The received SignalServiceEnvelope</param> /// <returns>a decrypted SignalServiceContent</returns> public SignalServiceContent Decrypt(SignalServiceEnvelope envelope) { try { SignalServiceContent content = new SignalServiceContent(); if (envelope.HasLegacyMessage()) { DataMessage message = DataMessage.Parser.ParseFrom(Decrypt(envelope, envelope.GetLegacyMessage())); content = new SignalServiceContent() { Message = CreateSignalServiceMessage(envelope, message) }; } else if (envelope.HasContent()) { Content message = Content.Parser.ParseFrom(Decrypt(envelope, envelope.GetContent())); if (message.DataMessageOneofCase == Content.DataMessageOneofOneofCase.DataMessage) { content = new SignalServiceContent() { Message = CreateSignalServiceMessage(envelope, message.DataMessage) }; } else if (message.SyncMessageOneofCase == Content.SyncMessageOneofOneofCase.SyncMessage && LocalAddress.E164number == envelope.GetSource()) { content = new SignalServiceContent() { SynchronizeMessage = CreateSynchronizeMessage(envelope, message.SyncMessage) }; } else if (message.CallMessageOneofCase == Content.CallMessageOneofOneofCase.CallMessage) { content = new SignalServiceContent() { CallMessage = CreateCallMessage(message.CallMessage) }; } else if (message.ReceiptMessageOneofCase == Content.ReceiptMessageOneofOneofCase.ReceiptMessage) { content = new SignalServiceContent() { ReadMessage = CreateReceiptMessage(envelope, message.ReceiptMessage) }; } } return(content); } catch (InvalidProtocolBufferException e) { throw new InvalidMessageException(e); } }
/// <summary> /// Decrypt a received <see cref="SignalServiceEnvelope"/> /// </summary> /// <param name="envelope">The received SignalServiceEnvelope</param> /// <returns>a decrypted SignalServiceContent</returns> public SignalServiceContent?Decrypt(SignalServiceEnvelope envelope) { try { if (envelope.HasLegacyMessage()) { Plaintext plaintext = Decrypt(envelope, envelope.GetLegacyMessage()); DataMessage dataMessage = DataMessage.Parser.ParseFrom(plaintext.data); SignalServiceContentProto contentProto = new SignalServiceContentProto() { LocalAddress = SignalServiceAddressProtobufSerializer.ToProtobuf(localAddress), Metadata = SignalServiceMetadataProtobufSerializer.ToProtobuf(plaintext.Metadata), LegacyDataMessage = dataMessage }; return(SignalServiceContent.CreateFromProto(contentProto)); } else if (envelope.HasContent()) { Plaintext plaintext = Decrypt(envelope, envelope.Envelope.Content.ToByteArray()); Content content = Content.Parser.ParseFrom(plaintext.data); SignalServiceContentProto contentProto = new SignalServiceContentProto() { LocalAddress = SignalServiceAddressProtobufSerializer.ToProtobuf(localAddress), Metadata = SignalServiceMetadataProtobufSerializer.ToProtobuf(plaintext.Metadata), Content = content }; return(SignalServiceContent.CreateFromProto(contentProto)); } return(null); } catch (InvalidProtocolBufferException e) { throw new InvalidMetadataMessageException(e); } }
/// <summary> /// Decrypt a received <see cref="SignalServiceEnvelope"/> /// </summary> /// <param name="envelope">The received SignalServiceEnvelope</param> /// <returns>a decrypted SignalServiceContent</returns> public SignalServiceContent?Decrypt(SignalServiceEnvelope envelope) { try { if (envelope.HasLegacyMessage()) { Plaintext plaintext = Decrypt(envelope, envelope.GetLegacyMessage()); DataMessage message = DataMessage.Parser.ParseFrom(plaintext.Data); return(new SignalServiceContent(plaintext.Metadata.Sender, plaintext.Metadata.SenderDevice, plaintext.Metadata.Timestamp, plaintext.Metadata.NeedsReceipt) { Message = CreateSignalServiceMessage(plaintext.Metadata, message) }); } else if (envelope.HasContent()) { Plaintext plaintext = Decrypt(envelope, envelope.Envelope.Content.ToByteArray()); Content message = Content.Parser.ParseFrom(plaintext.Data); if (message.DataMessageOneofCase == Content.DataMessageOneofOneofCase.DataMessage) { return(new SignalServiceContent(plaintext.Metadata.Sender, plaintext.Metadata.SenderDevice, plaintext.Metadata.Timestamp, plaintext.Metadata.NeedsReceipt) { Message = CreateSignalServiceMessage(plaintext.Metadata, message.DataMessage) }); } else if (message.SyncMessageOneofCase == Content.SyncMessageOneofOneofCase.SyncMessage) { return(new SignalServiceContent(plaintext.Metadata.Sender, plaintext.Metadata.SenderDevice, plaintext.Metadata.Timestamp, plaintext.Metadata.NeedsReceipt) { SynchronizeMessage = CreateSynchronizeMessage(plaintext.Metadata, message.SyncMessage) }); } else if (message.CallMessageOneofCase == Content.CallMessageOneofOneofCase.CallMessage) { return(new SignalServiceContent(plaintext.Metadata.Sender, plaintext.Metadata.SenderDevice, plaintext.Metadata.Timestamp, plaintext.Metadata.NeedsReceipt) { CallMessage = CreateCallMessage(message.CallMessage) }); } else if (message.ReceiptMessageOneofCase == Content.ReceiptMessageOneofOneofCase.ReceiptMessage) { return(new SignalServiceContent(plaintext.Metadata.Sender, plaintext.Metadata.SenderDevice, plaintext.Metadata.Timestamp, plaintext.Metadata.NeedsReceipt) { ReadMessage = CreateReceiptMessage(plaintext.Metadata, message.ReceiptMessage) }); } } return(null); } catch (InvalidProtocolBufferException e) { throw new InvalidMetadataMessageException(e); } }