本文整理汇总了Python中cryptography.hazmat.bindings.openssl.binding._consume_errors方法的典型用法代码示例。如果您正苦于以下问题:Python binding._consume_errors方法的具体用法?Python binding._consume_errors怎么用?Python binding._consume_errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.hazmat.bindings.openssl.binding
的用法示例。
在下文中一共展示了binding._consume_errors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_pem_public_key
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def load_pem_public_key(self, data):
mem_bio = self._bytes_to_bio(data)
evp_pkey = self._lib.PEM_read_bio_PUBKEY(
mem_bio.bio, self._ffi.NULL, self._ffi.NULL, self._ffi.NULL
)
if evp_pkey != self._ffi.NULL:
evp_pkey = self._ffi.gc(evp_pkey, self._lib.EVP_PKEY_free)
return self._evp_pkey_to_public_key(evp_pkey)
else:
# It's not a (RSA/DSA/ECDSA) subjectPublicKeyInfo, but we still
# need to check to see if it is a pure PKCS1 RSA public key (not
# embedded in a subjectPublicKeyInfo)
self._consume_errors()
res = self._lib.BIO_reset(mem_bio.bio)
self.openssl_assert(res == 1)
rsa_cdata = self._lib.PEM_read_bio_RSAPublicKey(
mem_bio.bio, self._ffi.NULL, self._ffi.NULL, self._ffi.NULL
)
if rsa_cdata != self._ffi.NULL:
rsa_cdata = self._ffi.gc(rsa_cdata, self._lib.RSA_free)
evp_pkey = self._rsa_cdata_to_evp_pkey(rsa_cdata)
return _RSAPublicKey(self, rsa_cdata, evp_pkey)
else:
self._handle_key_loading_error()
示例2: _evp_pkey_from_der_unencrypted_pkcs8
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def _evp_pkey_from_der_unencrypted_pkcs8(self, bio_data, password):
info = self._lib.d2i_PKCS8_PRIV_KEY_INFO_bio(
bio_data.bio, self._ffi.NULL
)
info = self._ffi.gc(info, self._lib.PKCS8_PRIV_KEY_INFO_free)
if info != self._ffi.NULL:
key = self._lib.EVP_PKCS82PKEY(info)
self.openssl_assert(key != self._ffi.NULL)
key = self._ffi.gc(key, self._lib.EVP_PKEY_free)
if password is not None:
raise TypeError(
"Password was given but private key is not encrypted."
)
return key
else:
self._consume_errors()
return None
示例3: load_der_public_key
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def load_der_public_key(self, data):
mem_bio = self._bytes_to_bio(data)
evp_pkey = self._lib.d2i_PUBKEY_bio(mem_bio.bio, self._ffi.NULL)
if evp_pkey != self._ffi.NULL:
evp_pkey = self._ffi.gc(evp_pkey, self._lib.EVP_PKEY_free)
return self._evp_pkey_to_public_key(evp_pkey)
else:
# It's not a (RSA/DSA/ECDSA) subjectPublicKeyInfo, but we still
# need to check to see if it is a pure PKCS1 RSA public key (not
# embedded in a subjectPublicKeyInfo)
self._consume_errors()
res = self._lib.BIO_reset(mem_bio.bio)
self.openssl_assert(res == 1)
rsa_cdata = self._lib.d2i_RSAPublicKey_bio(
mem_bio.bio, self._ffi.NULL
)
if rsa_cdata != self._ffi.NULL:
rsa_cdata = self._ffi.gc(rsa_cdata, self._lib.RSA_free)
evp_pkey = self._rsa_cdata_to_evp_pkey(rsa_cdata)
return _RSAPublicKey(self, rsa_cdata, evp_pkey)
else:
self._handle_key_loading_error()
示例4: elliptic_curve_supported
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def elliptic_curve_supported(self, curve):
try:
curve_nid = self._elliptic_curve_to_nid(curve)
except UnsupportedAlgorithm:
curve_nid = self._lib.NID_undef
group = self._lib.EC_GROUP_new_by_curve_name(curve_nid)
if group == self._ffi.NULL:
errors = self._consume_errors()
self.openssl_assert(
curve_nid == self._lib.NID_undef or
errors[0]._lib_reason_match(
self._lib.ERR_LIB_EC,
self._lib.EC_R_UNKNOWN_GROUP
)
)
return False
else:
self.openssl_assert(curve_nid != self._lib.NID_undef)
self._lib.EC_GROUP_free(group)
return True
示例5: _ec_key_set_public_key_affine_coordinates
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def _ec_key_set_public_key_affine_coordinates(self, ctx, x, y):
"""
Sets the public key point in the EC_KEY context to the affine x and y
values.
"""
if x < 0 or y < 0:
raise ValueError(
"Invalid EC key. Both x and y must be non-negative."
)
x = self._ffi.gc(self._int_to_bn(x), self._lib.BN_free)
y = self._ffi.gc(self._int_to_bn(y), self._lib.BN_free)
res = self._lib.EC_KEY_set_public_key_affine_coordinates(ctx, x, y)
if res != 1:
self._consume_errors()
raise ValueError("Invalid EC key.")
return ctx
示例6: load_der_parameters
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def load_der_parameters(self, data):
mem_bio = self._bytes_to_bio(data)
dh_cdata = self._lib.d2i_DHparams_bio(
mem_bio.bio, self._ffi.NULL
)
if dh_cdata != self._ffi.NULL:
dh_cdata = self._ffi.gc(dh_cdata, self._lib.DH_free)
return _DHParameters(self, dh_cdata)
elif self._lib.Cryptography_HAS_EVP_PKEY_DHX:
# We check to see if the is dhx.
self._consume_errors()
res = self._lib.BIO_reset(mem_bio.bio)
self.openssl_assert(res == 1)
dh_cdata = self._lib.Cryptography_d2i_DHxparams_bio(
mem_bio.bio, self._ffi.NULL
)
if dh_cdata != self._ffi.NULL:
dh_cdata = self._ffi.gc(dh_cdata, self._lib.DH_free)
return _DHParameters(self, dh_cdata)
self._handle_key_loading_error()
示例7: load_elliptic_curve_public_bytes
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def load_elliptic_curve_public_bytes(self, curve, point_bytes):
ec_cdata = self._ec_key_new_by_curve(curve)
group = self._lib.EC_KEY_get0_group(ec_cdata)
self.openssl_assert(group != self._ffi.NULL)
point = self._lib.EC_POINT_new(group)
self.openssl_assert(point != self._ffi.NULL)
point = self._ffi.gc(point, self._lib.EC_POINT_free)
with self._tmp_bn_ctx() as bn_ctx:
res = self._lib.EC_POINT_oct2point(
group, point, point_bytes, len(point_bytes), bn_ctx
)
if res != 1:
self._consume_errors()
raise ValueError("Invalid public bytes for the given curve")
res = self._lib.EC_KEY_set_public_key(ec_cdata, point)
self.openssl_assert(res == 1)
evp_pkey = self._ec_cdata_to_evp_pkey(ec_cdata)
return _EllipticCurvePublicKey(self, ec_cdata, evp_pkey)
示例8: _consume_errors
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def _consume_errors(self):
return binding._consume_errors(self._lib)
示例9: _evp_pkey_from_der_traditional_key
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def _evp_pkey_from_der_traditional_key(self, bio_data, password):
key = self._lib.d2i_PrivateKey_bio(bio_data.bio, self._ffi.NULL)
if key != self._ffi.NULL:
key = self._ffi.gc(key, self._lib.EVP_PKEY_free)
if password is not None:
raise TypeError(
"Password was given but private key is not encrypted."
)
return key
else:
self._consume_errors()
return None
示例10: load_der_x509_certificate
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def load_der_x509_certificate(self, data):
mem_bio = self._bytes_to_bio(data)
x509 = self._lib.d2i_X509_bio(mem_bio.bio, self._ffi.NULL)
if x509 == self._ffi.NULL:
self._consume_errors()
raise ValueError("Unable to load certificate")
x509 = self._ffi.gc(x509, self._lib.X509_free)
return _Certificate(self, x509)
示例11: load_pem_x509_crl
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def load_pem_x509_crl(self, data):
mem_bio = self._bytes_to_bio(data)
x509_crl = self._lib.PEM_read_bio_X509_CRL(
mem_bio.bio, self._ffi.NULL, self._ffi.NULL, self._ffi.NULL
)
if x509_crl == self._ffi.NULL:
self._consume_errors()
raise ValueError("Unable to load CRL")
x509_crl = self._ffi.gc(x509_crl, self._lib.X509_CRL_free)
return _CertificateRevocationList(self, x509_crl)
示例12: load_der_x509_crl
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def load_der_x509_crl(self, data):
mem_bio = self._bytes_to_bio(data)
x509_crl = self._lib.d2i_X509_CRL_bio(mem_bio.bio, self._ffi.NULL)
if x509_crl == self._ffi.NULL:
self._consume_errors()
raise ValueError("Unable to load CRL")
x509_crl = self._ffi.gc(x509_crl, self._lib.X509_CRL_free)
return _CertificateRevocationList(self, x509_crl)
示例13: load_pem_x509_csr
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def load_pem_x509_csr(self, data):
mem_bio = self._bytes_to_bio(data)
x509_req = self._lib.PEM_read_bio_X509_REQ(
mem_bio.bio, self._ffi.NULL, self._ffi.NULL, self._ffi.NULL
)
if x509_req == self._ffi.NULL:
self._consume_errors()
raise ValueError("Unable to load request")
x509_req = self._ffi.gc(x509_req, self._lib.X509_REQ_free)
return _CertificateSigningRequest(self, x509_req)
示例14: load_der_x509_csr
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def load_der_x509_csr(self, data):
mem_bio = self._bytes_to_bio(data)
x509_req = self._lib.d2i_X509_REQ_bio(mem_bio.bio, self._ffi.NULL)
if x509_req == self._ffi.NULL:
self._consume_errors()
raise ValueError("Unable to load request")
x509_req = self._ffi.gc(x509_req, self._lib.X509_REQ_free)
return _CertificateSigningRequest(self, x509_req)
示例15: elliptic_curve_supported
# 需要导入模块: from cryptography.hazmat.bindings.openssl import binding [as 别名]
# 或者: from cryptography.hazmat.bindings.openssl.binding import _consume_errors [as 别名]
def elliptic_curve_supported(self, curve):
if self._lib.Cryptography_HAS_EC != 1:
return False
try:
curve_nid = self._elliptic_curve_to_nid(curve)
except UnsupportedAlgorithm:
curve_nid = self._lib.NID_undef
ctx = self._lib.EC_GROUP_new_by_curve_name(curve_nid)
if ctx == self._ffi.NULL:
errors = self._consume_errors()
self.openssl_assert(
curve_nid == self._lib.NID_undef or
errors[0][1:] == (
self._lib.ERR_LIB_EC,
self._lib.EC_F_EC_GROUP_NEW_BY_CURVE_NAME,
self._lib.EC_R_UNKNOWN_GROUP
)
)
return False
else:
self.openssl_assert(curve_nid != self._lib.NID_undef)
self._lib.EC_GROUP_free(ctx)
return True