本文整理匯總了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