Ejemplo n.º 1
0
def load_key_bio_pubkey(bio, callback=util.passphrase_callback):
    # type: (BIO.BIO, Callable) -> PKey
    """
    Load an M2Crypto.EVP.PKey from a public key as a M2Crypto.BIO object.

    @param bio: M2Crypto.BIO object containing the key in PEM format.

    @param callback: A Python callable object that is invoked
    to acquire a passphrase with which to protect the key.

    @return: M2Crypto.EVP.PKey object.
    """
    cptr = m2.pkey_read_pem_pubkey(bio._ptr(), callback)
    if cptr is None:
        raise EVPError(Err.get_error())
    return PKey(cptr, 1)
Ejemplo n.º 2
0
def load_key_bio_pubkey(bio, callback=util.passphrase_callback):
    # type: (BIO.BIO, Callable) -> PKey
    """
    Load an M2Crypto.EVP.PKey from a public key as a M2Crypto.BIO object.

    @param bio: M2Crypto.BIO object containing the key in PEM format.

    @param callback: A Python callable object that is invoked
    to acquire a passphrase with which to protect the key.

    @return: M2Crypto.EVP.PKey object.
    """
    cptr = m2.pkey_read_pem_pubkey(bio._ptr(), callback)
    if cptr is None:
        raise EVPError(Err.get_error())
    return PKey(cptr, 1)
Ejemplo n.º 3
0
def load_key_pubkey(file, callback=util.passphrase_callback):
    # type: (AnyStr, Callable) -> PKey
    """
    Load an M2Crypto.EVP.PKey from a public key as a file.

    :param file: Name of file containing the key in PEM format.

    :param callback: A Python callable object that is invoked
                     to acquire a passphrase with which to protect the
                     key.

    :return: M2Crypto.EVP.PKey object.
    """

    with BIO.openfile(file, 'r') as bio:
        cptr = m2.pkey_read_pem_pubkey(bio._ptr(), callback)
        if cptr is None:
            raise EVPError(Err.get_error())
    return PKey(cptr, 1)