(data,
             filename=None,
             plaintext=True,
             encapsulate=False,
             sign=False,
             fec=False,
             gpg=None,
             recipient=None,
             trust=False,
             sign_key=None,
             fec_overhead=0.1)
return msg
Generate an API message

    Args:
        data         : Message data (bytes)
        filename     : Underlying file name if the message consists of a file.
        plaintext    : Boolean indicating plaintext mode.
        encapsulate  : Boolean indicating whether to encapsulate the data.
        sign         : Boolean indicating whether the message should be signed.
        fec          : Boolean indicating whether to enable FEC encoding.
        gpg          : Gpg object.
        recipient    : Public key fingerprint of the desired recipient.
        trust        : Skip key validation on encryption (trust the recipient).
        sign_key     : Fingerprint to use for signing.
        fec_overhead : Target FEC overhead.

    Returns:
        Message as an ApiMsg object.
Generate an API message
Generate an API message
def generate(data,
             filename=None,
             plaintext=True,
             encapsulate=False,
             sign=False,
             fec=False,
             gpg=None,
             recipient=None,
             trust=False,
             sign_key=None,
             fec_overhead=0.1):
    """Generate an API message

    Args:
        data         : Message data (bytes)
        filename     : Underlying file name if the message consists of a file.
        plaintext    : Boolean indicating plaintext mode.
        encapsulate  : Boolean indicating whether to encapsulate the data.
        sign         : Boolean indicating whether the message should be signed.
        fec          : Boolean indicating whether to enable FEC encoding.
        gpg          : Gpg object.
        recipient    : Public key fingerprint of the desired recipient.
        trust        : Skip key validation on encryption (trust the recipient).
        sign_key     : Fingerprint to use for signing.
        fec_overhead : Target FEC overhead.

    Returns:
        Message as an ApiMsg object.

    """
    if ((not plaintext or sign) and gpg is None):
        raise ValueError("Gpg object is required for encryption or signing")

    msg = ApiMsg(data, filename=filename)

    # If transmitting a plaintext message, it could still be clearsigned.
    if (plaintext and sign):
        if (sign_key):
            # Make sure the key exists
            gpg.get_priv_key(sign_key)
            sign_key = sign_key
        else:
            sign_key = gpg.get_default_priv_key()["fingerprint"]

        msg.clearsign(gpg, sign_key)

    # Pack data into structure (header + data), if enabled
    if (encapsulate):
        msg.encapsulate()

    # Encrypt, unless configured otherwise
    if (not plaintext):
        # Default to the first public key in the keyring if the recipient is
        # not defined.
        if (recipient is None):
            recipient = gpg.get_default_public_key()["fingerprint"]
            assert(recipient != defs.blocksat_pubkey), \
                "Defaul public key is not the user's public key"
        else:
            # Make sure the key exists
            gpg.get_public_key(recipient)
            recipient = recipient

        # Digital signature. If configured to sign the message without a
        # specified key, use the default key.
        if (sign):
            if (sign_key):
                # Make sure the key exists
                gpg.get_priv_key(sign_key)
                sign_cfg = sign_key
            else:
                sign_cfg = gpg.get_default_priv_key()["fingerprint"]
        else:
            sign_cfg = False

        msg.encrypt(gpg, recipient, sign_cfg, trust)

    # Forward error correction encoding
    if (fec):
        msg.fec_encode(fec_overhead)

    return msg
def generate ( data , filename = None , plaintext = True , encapsulate = False , sign = False , fec = False , gpg = None , recipient = None , trust = False , sign_key = None , fec_overhead = 0.1 ) : if ( ( not plaintext or sign ) and gpg is None ) : raise ValueError ( "Gpg object is required for encryption or signing" ) msg = ApiMsg ( data , filename = filename ) # If transmitting a plaintext message, it could still be clearsigned. if ( plaintext and sign ) : if ( sign_key ) : # Make sure the key exists gpg . get_priv_key ( sign_key ) sign_key = sign_key else : sign_key = gpg . get_default_priv_key ( ) [ "fingerprint" ] msg . clearsign ( gpg , sign_key ) # Pack data into structure (header + data), if enabled if ( encapsulate ) : msg . encapsulate ( ) # Encrypt, unless configured otherwise if ( not plaintext ) : # Default to the first public key in the keyring if the recipient is # not defined. if ( recipient is None ) : recipient = gpg . get_default_public_key ( ) [ "fingerprint" ] assert ( recipient != defs . blocksat_pubkey ) , "Defaul public key is not the user's public key" else : # Make sure the key exists gpg . get_public_key ( recipient ) recipient = recipient # Digital signature. If configured to sign the message without a # specified key, use the default key. if ( sign ) : if ( sign_key ) : # Make sure the key exists gpg . get_priv_key ( sign_key ) sign_cfg = sign_key else : sign_cfg = gpg . get_default_priv_key ( ) [ "fingerprint" ] else : sign_cfg = False msg . encrypt ( gpg , recipient , sign_cfg , trust ) # Forward error correction encoding if ( fec ) : msg . fec_encode ( fec_overhead ) return msg