/// <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); } }