docs: public SignalServiceContent decrypt(SignalServiceEnvelope envelope)
        throws InvalidMetadataMessageException, InvalidMetadataVersionException,
        ProtocolInvalidKeyIdException, ProtocolLegacyMessageException,
        ProtocolUntrustedIdentityException, ProtocolNoSessionException,
        ProtocolInvalidVersionException, ProtocolInvalidMessageException,
        ProtocolInvalidKeyException, ProtocolDuplicateMessageException,
        SelfSendException
  
    {
      try {
        if (envelope.hasLegacyMessage()) {
          Plaintext plaintext = decrypt(envelope, envelope.getLegacyMessage());
          DataMessage message = DataMessage.parseFrom(plaintext.getData());
          return new SignalServiceContent(createSignalServiceMessage(plaintext.getMetadata(), message),
                                          plaintext.getMetadata().getSender(),
                                          plaintext.getMetadata().getSenderDevice(),
                                          plaintext.getMetadata().getTimestamp(),
                                          plaintext.getMetadata().isNeedsReceipt());
        } else if (envelope.hasContent()) {
          Plaintext plaintext = decrypt(envelope, envelope.getContent());
          Content   message   = Content.parseFrom(plaintext.getData());
  
          if (message.hasDataMessage()) {
            return new SignalServiceContent(createSignalServiceMessage(plaintext.getMetadata(), message.getDataMessage()),
                                            plaintext.getMetadata().getSender(),
                                            plaintext.getMetadata().getSenderDevice(),
                                            plaintext.getMetadata().getTimestamp(),
                                            plaintext.getMetadata().isNeedsReceipt());
          } else if (message.hasSyncMessage() && localAddress.getNumber().equals(plaintext.getMetadata().getSender())) {
            return new SignalServiceContent(createSynchronizeMessage(plaintext.getMetadata(), message.getSyncMessage()),
                                            plaintext.getMetadata().getSender(),
                                            plaintext.getMetadata().getSenderDevice(),
                                            plaintext.getMetadata().getTimestamp(),
                                            plaintext.getMetadata().isNeedsReceipt());
          } else if (message.hasCallMessage()) {
            return new SignalServiceContent(createCallMessage(message.getCallMessage()),
                                            plaintext.getMetadata().getSender(),
                                            plaintext.getMetadata().getSenderDevice(),
                                            plaintext.getMetadata().getTimestamp(),
                                            plaintext.getMetadata().isNeedsReceipt());
          } else if (message.hasReceiptMessage()) {
            return new SignalServiceContent(createReceiptMessage(plaintext.getMetadata(), message.getReceiptMessage()),
                                            plaintext.getMetadata().getSender(),
                                            plaintext.getMetadata().getSenderDevice(),
                                            plaintext.getMetadata().getTimestamp(),
                                            plaintext.getMetadata().isNeedsReceipt());
          } else if (message.hasTypingMessage()) {
            return new SignalServiceContent(createTypingMessage(plaintext.getMetadata(), message.getTypingMessage()),
                                            plaintext.getMetadata().getSender(),
                                            plaintext.getMetadata().getSenderDevice(),
                                            plaintext.getMetadata().getTimestamp(),
                                            false);
          }
        }
  
        return null;
      } catch (InvalidProtocolBufferException e) {
        throw new InvalidMetadataMessageException(e);
      }
    }