本文整理汇总了Python中cryptography.hazmat.bindings._openssl.ffi.from_handle方法的典型用法代码示例。如果您正苦于以下问题:Python ffi.from_handle方法的具体用法?Python ffi.from_handle怎么用?Python ffi.from_handle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.hazmat.bindings._openssl.ffi
的用法示例。
在下文中一共展示了ffi.from_handle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pem_password_cb
# 需要导入模块: from cryptography.hazmat.bindings._openssl import ffi [as 别名]
# 或者: from cryptography.hazmat.bindings._openssl.ffi import from_handle [as 别名]
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(size - 1)
)
return 0