本文整理匯總了Python中cryptography.exceptions._Reasons.UNSUPPORTED_HASH屬性的典型用法代碼示例。如果您正苦於以下問題:Python _Reasons.UNSUPPORTED_HASH屬性的具體用法?Python _Reasons.UNSUPPORTED_HASH怎麽用?Python _Reasons.UNSUPPORTED_HASH使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cryptography.exceptions._Reasons
的用法示例。
在下文中一共展示了_Reasons.UNSUPPORTED_HASH屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def __init__(self, backend, algorithm, ctx=None):
self._algorithm = algorithm
self._backend = backend
if ctx is None:
ctx = self._backend._lib.Cryptography_EVP_MD_CTX_new()
ctx = self._backend._ffi.gc(
ctx, self._backend._lib.Cryptography_EVP_MD_CTX_free
)
evp_md = self._backend._lib.EVP_get_digestbyname(
algorithm.name.encode("ascii"))
if evp_md == self._backend._ffi.NULL:
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
res = self._backend._lib.EVP_DigestInit_ex(ctx, evp_md,
self._backend._ffi.NULL)
self._backend.openssl_assert(res != 0)
self._ctx = ctx
示例2: __init__
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def __init__(self, backend, algorithm, ctx=None):
self._algorithm = algorithm
self._backend = backend
if ctx is None:
try:
methods = self._backend._hash_mapping[self.algorithm.name]
except KeyError:
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
ctx = self._backend._ffi.new(methods.ctx)
res = methods.hash_init(ctx)
assert res == 1
self._ctx = ctx
示例3: __init__
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def __init__(self, backend, algorithm, ctx=None):
self._algorithm = algorithm
self._backend = backend
if ctx is None:
ctx = self._backend._lib.Cryptography_EVP_MD_CTX_new()
ctx = self._backend._ffi.gc(
ctx, self._backend._lib.Cryptography_EVP_MD_CTX_free
)
name = self._backend._build_openssl_digest_name(algorithm)
evp_md = self._backend._lib.EVP_get_digestbyname(name)
if evp_md == self._backend._ffi.NULL:
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
name),
_Reasons.UNSUPPORTED_HASH
)
res = self._backend._lib.EVP_DigestInit_ex(ctx, evp_md,
self._backend._ffi.NULL)
self._backend.openssl_assert(res != 0)
self._ctx = ctx
示例4: __init__
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def __init__(self, backend, algorithm, ctx=None):
self._algorithm = algorithm
self._backend = backend
if ctx is None:
ctx = self._backend._lib.EVP_MD_CTX_create()
ctx = self._backend._ffi.gc(ctx,
self._backend._lib.EVP_MD_CTX_destroy)
evp_md = self._backend._lib.EVP_get_digestbyname(
algorithm.name.encode("ascii"))
if evp_md == self._backend._ffi.NULL:
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
res = self._backend._lib.EVP_DigestInit_ex(ctx, evp_md,
self._backend._ffi.NULL)
assert res != 0
self._ctx = ctx
示例5: __init__
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def __init__(self, backend, algorithm, ctx=None):
self._algorithm = algorithm
self._backend = backend
if ctx is None:
ctx = self._backend._lib.EVP_MD_CTX_create()
ctx = self._backend._ffi.gc(ctx,
self._backend._lib.EVP_MD_CTX_destroy)
evp_md = self._backend._lib.EVP_get_digestbyname(
algorithm.name.encode("ascii"))
if evp_md == self._backend._ffi.NULL:
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
res = self._backend._lib.EVP_DigestInit_ex(ctx, evp_md,
self._backend._ffi.NULL)
self._backend.openssl_assert(res != 0)
self._ctx = ctx
示例6: __init__
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def __init__(self, backend, algorithm, ctx=None):
self._algorithm = algorithm
self._backend = backend
if ctx is None:
try:
ckm = self._backend._hash_mapping[self.algorithm.name]
except KeyError:
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
mech = self._backend._ffi.new("CK_MECHANISM *")
mech.mechanism = ckm
ctx = self._backend._session_pool.acquire_and_init(
backend, self._backend._lib.C_DigestInit, mech
)
self._ctx = ctx
示例7: __init__
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def __init__(self, backend, algorithm, ctx=None):
self._algorithm = algorithm
self._backend = backend
if ctx is None:
try:
ctx = self._backend._lib.ring_digest_context_new(
self._backend._hash_mapping[self.algorithm.name]()
)
ctx = self._backend._ffi.gc(
ctx, self._backend._lib.ring_digest_context_delete
)
except KeyError:
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
self._ctx = ctx
示例8: derive_pbkdf2_hmac
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,
key_material):
buf = self._ffi.new("char[]", length)
if self._lib.Cryptography_HAS_PBKDF2_HMAC:
evp_md = self._lib.EVP_get_digestbyname(
algorithm.name.encode("ascii"))
self.openssl_assert(evp_md != self._ffi.NULL)
res = self._lib.PKCS5_PBKDF2_HMAC(
key_material,
len(key_material),
salt,
len(salt),
iterations,
evp_md,
length,
buf
)
self.openssl_assert(res == 1)
else:
if not isinstance(algorithm, hashes.SHA1):
raise UnsupportedAlgorithm(
"This version of OpenSSL only supports PBKDF2HMAC with "
"SHA1.",
_Reasons.UNSUPPORTED_HASH
)
res = self._lib.PKCS5_PBKDF2_HMAC_SHA1(
key_material,
len(key_material),
salt,
len(salt),
iterations,
length,
buf
)
self.openssl_assert(res == 1)
return self._ffi.buffer(buf)[:]
示例9: create_hash_ctx
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def create_hash_ctx(self, algorithm):
for b in self._filtered_backends(HashBackend):
try:
return b.create_hash_ctx(algorithm)
except UnsupportedAlgorithm:
pass
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
示例10: create_hmac_ctx
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def create_hmac_ctx(self, key, algorithm):
for b in self._filtered_backends(HMACBackend):
try:
return b.create_hmac_ctx(key, algorithm)
except UnsupportedAlgorithm:
pass
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)
示例11: derive_pbkdf2_hmac
# 需要導入模塊: from cryptography.exceptions import _Reasons [as 別名]
# 或者: from cryptography.exceptions._Reasons import UNSUPPORTED_HASH [as 別名]
def derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,
key_material):
for b in self._filtered_backends(PBKDF2HMACBackend):
try:
return b.derive_pbkdf2_hmac(
algorithm, length, salt, iterations, key_material
)
except UnsupportedAlgorithm:
pass
raise UnsupportedAlgorithm(
"{0} is not a supported hash on this backend.".format(
algorithm.name),
_Reasons.UNSUPPORTED_HASH
)