當前位置: 首頁>>代碼示例>>Python>>正文


Python utils._check_bytes方法代碼示例

本文整理匯總了Python中cryptography.utils._check_bytes方法的典型用法代碼示例。如果您正苦於以下問題:Python utils._check_bytes方法的具體用法?Python utils._check_bytes怎麽用?Python utils._check_bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cryptography.utils的用法示例。


在下文中一共展示了utils._check_bytes方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def __init__(self, key, tag_length=16):
        utils._check_bytes("key", key)
        if len(key) not in (16, 24, 32):
            raise ValueError("AESCCM key must be 128, 192, or 256 bits.")

        self._key = key
        if not isinstance(tag_length, int):
            raise TypeError("tag_length must be an integer")

        if tag_length not in (4, 6, 8, 12, 14, 16):
            raise ValueError("Invalid tag_length")

        self._tag_length = tag_length

        if not backend.aead_cipher_supported(self):
            raise exceptions.UnsupportedAlgorithm(
                "AESCCM is not supported by this version of OpenSSL",
                exceptions._Reasons.UNSUPPORTED_CIPHER
            ) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:21,代碼來源:aead.py

示例2: _encrypt_from_parts

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def _encrypt_from_parts(self, data, current_time, iv):
        utils._check_bytes("data", data)

        padder = padding.PKCS7(algorithms.AES.block_size).padder()
        padded_data = padder.update(data) + padder.finalize()
        encryptor = Cipher(
            algorithms.AES(self._encryption_key), modes.CBC(iv), self._backend
        ).encryptor()
        ciphertext = encryptor.update(padded_data) + encryptor.finalize()

        basic_parts = (
            b"\x80" + struct.pack(">Q", current_time) + iv + ciphertext
        )

        h = HMAC(self._signing_key, hashes.SHA256(), backend=self._backend)
        h.update(basic_parts)
        hmac = h.finalize()
        return base64.urlsafe_b64encode(basic_parts + hmac) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:20,代碼來源:fernet.py

示例3: __init__

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def __init__(self, algorithm, length, salt, info, backend):
        if not isinstance(backend, HMACBackend):
            raise UnsupportedAlgorithm(
                "Backend object does not implement HMACBackend.",
                _Reasons.BACKEND_MISSING_INTERFACE
            )

        self._algorithm = algorithm

        if salt is None:
            salt = b"\x00" * self._algorithm.digest_size
        else:
            utils._check_bytes("salt", salt)

        self._salt = salt

        self._backend = backend

        self._hkdf_expand = HKDFExpand(self._algorithm, length, info, backend) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:21,代碼來源:hkdf.py

示例4: __init__

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def __init__(self, algorithm, length, salt, otherinfo, backend):

        _common_args_checks(algorithm, length, otherinfo)
        self._algorithm = algorithm
        self._length = length
        self._otherinfo = otherinfo
        if self._otherinfo is None:
            self._otherinfo = b""

        if salt is None:
            salt = b"\x00" * algorithm.block_size
        else:
            utils._check_bytes("salt", salt)

        self._salt = salt

        if not isinstance(backend, HMACBackend):
            raise UnsupportedAlgorithm(
                "Backend object does not implement HMACBackend.",
                _Reasons.BACKEND_MISSING_INTERFACE
            )
        self._backend = backend
        self._used = False 
開發者ID:tp4a,項目名稱:teleport,代碼行數:25,代碼來源:concatkdf.py

示例5: __init__

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def __init__(self, algorithm, length, sharedinfo, backend):

        max_len = algorithm.digest_size * (2 ** 32 - 1)
        if length > max_len:
            raise ValueError(
                "Can not derive keys larger than {} bits.".format(max_len))
        if sharedinfo is not None:
            utils._check_bytes("sharedinfo", sharedinfo)

        self._algorithm = algorithm
        self._length = length
        self._sharedinfo = sharedinfo

        if not isinstance(backend, HashBackend):
            raise UnsupportedAlgorithm(
                "Backend object does not implement HashBackend.",
                _Reasons.BACKEND_MISSING_INTERFACE
            )
        self._backend = backend
        self._used = False 
開發者ID:tp4a,項目名稱:teleport,代碼行數:22,代碼來源:x963kdf.py

示例6: __init__

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def __init__(self, algorithm, length, salt, iterations, backend):
        if not isinstance(backend, PBKDF2HMACBackend):
            raise UnsupportedAlgorithm(
                "Backend object does not implement PBKDF2HMACBackend.",
                _Reasons.BACKEND_MISSING_INTERFACE
            )

        if not backend.pbkdf2_hmac_supported(algorithm):
            raise UnsupportedAlgorithm(
                "{} is not supported for PBKDF2 by this backend.".format(
                    algorithm.name),
                _Reasons.UNSUPPORTED_HASH
            )
        self._used = False
        self._algorithm = algorithm
        self._length = length
        utils._check_bytes("salt", salt)
        self._salt = salt
        self._iterations = iterations
        self._backend = backend 
開發者ID:tp4a,項目名稱:teleport,代碼行數:22,代碼來源:pbkdf2.py

示例7: __init__

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def __init__(self, initialization_vector, tag=None, min_tag_length=16):
        # len(initialization_vector) must in [1, 2 ** 64), but it's impossible
        # to actually construct a bytes object that large, so we don't check
        # for it
        utils._check_byteslike("initialization_vector", initialization_vector)
        if len(initialization_vector) == 0:
            raise ValueError("initialization_vector must be at least 1 byte")
        self._initialization_vector = initialization_vector
        if tag is not None:
            utils._check_bytes("tag", tag)
            if min_tag_length < 4:
                raise ValueError("min_tag_length must be >= 4")
            if len(tag) < min_tag_length:
                raise ValueError(
                    "Authentication tag must be {} bytes or longer.".format(
                        min_tag_length)
                )
        self._tag = tag
        self._min_tag_length = min_tag_length 
開發者ID:tp4a,項目名稱:teleport,代碼行數:21,代碼來源:modes.py

示例8: __init__

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def __init__(self, salt, length, n, r, p, backend):
        if not isinstance(backend, ScryptBackend):
            raise UnsupportedAlgorithm(
                "Backend object does not implement ScryptBackend.",
                _Reasons.BACKEND_MISSING_INTERFACE
            )

        self._length = length
        utils._check_bytes("salt", salt)
        if n < 2 or (n & (n - 1)) != 0:
            raise ValueError("n must be greater than 1 and be a power of 2.")

        if r < 1:
            raise ValueError("r must be greater than or equal to 1.")

        if p < 1:
            raise ValueError("p must be greater than or equal to 1.")

        self._used = False
        self._salt = salt
        self._n = n
        self._r = r
        self._p = p
        self._backend = backend 
開發者ID:tp4a,項目名稱:teleport,代碼行數:26,代碼來源:scrypt.py

示例9: _verify_key_size

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def _verify_key_size(algorithm, key):
    # Verify that the key is instance of bytes
    utils._check_bytes("key", key)

    # Verify that the key size matches the expected key size
    if len(key) * 8 not in algorithm.key_sizes:
        raise ValueError("Invalid key size ({0}) for {1}.".format(
            len(key) * 8, algorithm.name
        ))
    return key 
開發者ID:tp4a,項目名稱:teleport,代碼行數:12,代碼來源:algorithms.py

示例10: _check_params

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def _check_params(self, nonce, data, associated_data):
        utils._check_bytes("nonce", nonce)
        utils._check_bytes("data", data)
        utils._check_bytes("associated_data", associated_data)
        if len(nonce) != 12:
            raise ValueError("Nonce must be 12 bytes") 
開發者ID:tp4a,項目名稱:teleport,代碼行數:8,代碼來源:aead.py

示例11: _get_unverified_token_data

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def _get_unverified_token_data(token):
        utils._check_bytes("token", token)
        try:
            data = base64.urlsafe_b64decode(token)
        except (TypeError, binascii.Error):
            raise InvalidToken

        if not data or six.indexbytes(data, 0) != 0x80:
            raise InvalidToken

        try:
            timestamp, = struct.unpack(">Q", data[1:9])
        except struct.error:
            raise InvalidToken
        return timestamp, data 
開發者ID:tp4a,項目名稱:teleport,代碼行數:17,代碼來源:fernet.py

示例12: verifier

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def verifier(self, signature, padding, algorithm):
        _warn_sign_verify_deprecated()
        utils._check_bytes("signature", signature)

        _check_not_prehashed(algorithm)
        return _RSAVerificationContext(
            self._backend, self, signature, padding, algorithm
        ) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:10,代碼來源:rsa.py

示例13: verifier

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def verifier(self, signature, signature_algorithm):
        _warn_sign_verify_deprecated()
        utils._check_bytes("signature", signature)

        _check_not_prehashed(signature_algorithm)
        return _DSAVerificationContext(
            self._backend, self, signature, signature_algorithm
        ) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:10,代碼來源:dsa.py

示例14: ed448_load_public_bytes

# 需要導入模塊: from cryptography import utils [as 別名]
# 或者: from cryptography.utils import _check_bytes [as 別名]
def ed448_load_public_bytes(self, data):
        utils._check_bytes("data", data)
        if len(data) != _ED448_KEY_SIZE:
            raise ValueError("An Ed448 public key is 57 bytes long")

        evp_pkey = self._lib.EVP_PKEY_new_raw_public_key(
            self._lib.NID_ED448, self._ffi.NULL, data, len(data)
        )
        self.openssl_assert(evp_pkey != self._ffi.NULL)
        evp_pkey = self._ffi.gc(evp_pkey, self._lib.EVP_PKEY_free)

        return _Ed448PublicKey(self, evp_pkey) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:14,代碼來源:backend.py


注:本文中的cryptography.utils._check_bytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。