(data,
           plaintext=True,
           decapsulate=False,
           fec=False,
           sender=None,
           gpg=None)
return msg
Decode an incoming API message

    Args:
        data        : Message data (bytes)
        plaintext   : Boolean indicating plaintext mode.
        decapsulate : Boolean indicating whether to encapsulate the data.
        fec         : Boolean indicating whether to try FEC decoding first.
        sender      : Fingerprint of a sender who must have signed the message.
        gpg         : Gpg object.

    Returns:
        ApiMsg if the message is succesfully decoded, None otherwise.
Decode an incoming API message
Decode an incoming API message
def decode(data,
           plaintext=True,
           decapsulate=False,
           fec=False,
           sender=None,
           gpg=None):
    """Decode an incoming API message

    Args:
        data        : Message data (bytes)
        plaintext   : Boolean indicating plaintext mode.
        decapsulate : Boolean indicating whether to encapsulate the data.
        fec         : Boolean indicating whether to try FEC decoding first.
        sender      : Fingerprint of a sender who must have signed the message.
        gpg         : Gpg object.

    Returns:
        ApiMsg if the message is succesfully decoded, None otherwise.

    """
    if ((not plaintext or sender) and gpg is None):
        raise ValueError("Gpg object is required for decryption/verification")

    if (fec):
        msg = ApiMsg(data, msg_format="fec_encoded")
        msg.fec_decode()
        data = msg.data['original']
        del msg  # after extracting the data, re-create a new ApiMsg below

    if (plaintext):
        if (decapsulate):
            # Encapsulated format, but no encryption
            msg = ApiMsg(data, msg_format="encapsulated")

            # Try to decapsulate it
            if (not msg.decapsulate()):
                return
        else:
            # Assume that the message is not encapsulated. This mode is
            # useful, e.g., for compatibility with transmissions triggered
            # from the browser at: https://blockstream.com/satellite-queue/.
            msg = ApiMsg(data, msg_format="original")

        # If filtering clearsigned messages, verify
        if (sender and not msg.verify(gpg, sender)):
            return

        logger.info("Message Size: {:d} bytes\tSaving in plaintext".format(
            msg.get_length(target='original')))

    else:
        # Cast data into ApiMsg object in encrypted form
        msg = ApiMsg(data, msg_format="encrypted")

        # Try to decrypt the data:
        if (not msg.decrypt(gpg, sender)):
            return

        # Try to decapsulate the application-layer structure if assuming it
        # is present (i.e., with "save-raw=False")
        if (decapsulate and not msg.decapsulate()):
            return

    return msg
def decode ( data , plaintext = True , decapsulate = False , fec = False , sender = None , gpg = None ) : if ( ( not plaintext or sender ) and gpg is None ) : raise ValueError ( "Gpg object is required for decryption/verification" ) if ( fec ) : msg = ApiMsg ( data , msg_format = "fec_encoded" ) msg . fec_decode ( ) data = msg . data [ 'original' ] del msg # after extracting the data, re-create a new ApiMsg below if ( plaintext ) : if ( decapsulate ) : # Encapsulated format, but no encryption msg = ApiMsg ( data , msg_format = "encapsulated" ) # Try to decapsulate it if ( not msg . decapsulate ( ) ) : return else : # Assume that the message is not encapsulated. This mode is # useful, e.g., for compatibility with transmissions triggered # from the browser at: https://blockstream.com/satellite-queue/. msg = ApiMsg ( data , msg_format = "original" ) # If filtering clearsigned messages, verify if ( sender and not msg . verify ( gpg , sender ) ) : return logger . info ( "Message Size: {:d} bytes\tSaving in plaintext" . format ( msg . get_length ( target = 'original' ) ) ) else : # Cast data into ApiMsg object in encrypted form msg = ApiMsg ( data , msg_format = "encrypted" ) # Try to decrypt the data: if ( not msg . decrypt ( gpg , sender ) ) : return # Try to decapsulate the application-layer structure if assuming it # is present (i.e., with "save-raw=False") if ( decapsulate and not msg . decapsulate ( ) ) : return return msg