@binding.ffi_callback("int (char *, int, int, void *)",
                      name="Cryptography_pem_password_cb")
def _pem_password_cb(buf, size, writing, userdata_handle):
    """
    A pem_password_cb function pointer that copied the password to
    OpenSSL as required and returns the number of bytes copied.

    typedef int pem_password_cb(char *buf, int size,
                                int rwflag, void *userdata);

    Useful for decrypting PKCS8 files and so on.

    The userdata pointer must point to a cffi handle of a
    _PasswordUserdata instance.
    """
    ud = _ffi.from_handle(userdata_handle)
    ud.called += 1

    if not ud.password:
        ud.exception = TypeError(
            "Password was not given but private key is encrypted."
        )
        return -1
    elif len(ud.password) < size:
        pw_buf = _ffi.buffer(buf, size)
        pw_buf[:len(ud.password)] = ud.password
        return len(ud.password)
    else:
        ud.exception = ValueError(
            "Passwords longer than {0} bytes are not supported "
            "by this backend.".format(1 - size)
        )
        return 0
dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/cryptography-1.3.1/src/cryptography/hazmat/backends/openssl/backend.py/_pem_password_cb/swapped operands of `-`