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


Python ffi.buffer方法代碼示例

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


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

示例1: _bn_to_int

# 需要導入模塊: from cryptography.hazmat.bindings._openssl import ffi [as 別名]
# 或者: from cryptography.hazmat.bindings._openssl.ffi import buffer [as 別名]
def _bn_to_int(self, bn):
        assert bn != self._ffi.NULL
        if six.PY3:
            # Python 3 has constant time from_bytes, so use that.
            bn_num_bytes = self._lib.BN_num_bytes(bn)
            bin_ptr = self._ffi.new("unsigned char[]", bn_num_bytes)
            bin_len = self._lib.BN_bn2bin(bn, bin_ptr)
            # A zero length means the BN has value 0
            self.openssl_assert(bin_len >= 0)
            return int.from_bytes(self._ffi.buffer(bin_ptr)[:bin_len], "big")
        else:
            # Under Python 2 the best we can do is hex()
            hex_cdata = self._lib.BN_bn2hex(bn)
            self.openssl_assert(hex_cdata != self._ffi.NULL)
            hex_str = self._ffi.string(hex_cdata)
            self._lib.OPENSSL_free(hex_cdata)
            return int(hex_str, 16) 
開發者ID:DirceuSilvaLabs,項目名稱:noc-orchestrator,代碼行數:19,代碼來源:backend.py

示例2: derive_pbkdf2_hmac

# 需要導入模塊: from cryptography.hazmat.bindings._openssl import ffi [as 別名]
# 或者: from cryptography.hazmat.bindings._openssl.ffi import buffer [as 別名]
def derive_pbkdf2_hmac(self, algorithm, length, salt, iterations,
                           key_material):
        buf = self._ffi.new("unsigned char[]", length)
        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)
        return self._ffi.buffer(buf)[:] 
開發者ID:lordmuffin,項目名稱:aws-cfn-plex,代碼行數:20,代碼來源:backend.py

示例3: _bn_to_int

# 需要導入模塊: from cryptography.hazmat.bindings._openssl import ffi [as 別名]
# 或者: from cryptography.hazmat.bindings._openssl.ffi import buffer [as 別名]
def _bn_to_int(self, bn):
        assert bn != self._ffi.NULL

        if six.PY3:
            # Python 3 has constant time from_bytes, so use that.
            bn_num_bytes = self._lib.BN_num_bytes(bn)
            bin_ptr = self._ffi.new("unsigned char[]", bn_num_bytes)
            bin_len = self._lib.BN_bn2bin(bn, bin_ptr)
            # A zero length means the BN has value 0
            self.openssl_assert(bin_len >= 0)
            return int.from_bytes(self._ffi.buffer(bin_ptr)[:bin_len], "big")
        else:
            # Under Python 2 the best we can do is hex()
            hex_cdata = self._lib.BN_bn2hex(bn)
            self.openssl_assert(hex_cdata != self._ffi.NULL)
            hex_str = self._ffi.string(hex_cdata)
            self._lib.OPENSSL_free(hex_cdata)
            return int(hex_str, 16) 
開發者ID:lordmuffin,項目名稱:aws-cfn-plex,代碼行數:20,代碼來源:backend.py

示例4: _pem_password_cb

# 需要導入模塊: from cryptography.hazmat.bindings._openssl import ffi [as 別名]
# 或者: from cryptography.hazmat.bindings._openssl.ffi import buffer [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 
開發者ID:DirceuSilvaLabs,項目名稱:noc-orchestrator,代碼行數:33,代碼來源:backend.py

示例5: derive_pbkdf2_hmac

# 需要導入模塊: from cryptography.hazmat.bindings._openssl import ffi [as 別名]
# 或者: from cryptography.hazmat.bindings._openssl.ffi import buffer [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)[:] 
開發者ID:DirceuSilvaLabs,項目名稱:noc-orchestrator,代碼行數:39,代碼來源:backend.py

示例6: _read_mem_bio

# 需要導入模塊: from cryptography.hazmat.bindings._openssl import ffi [as 別名]
# 或者: from cryptography.hazmat.bindings._openssl.ffi import buffer [as 別名]
def _read_mem_bio(self, bio):
        """
        Reads a memory BIO. This only works on memory BIOs.
        """
        buf = self._ffi.new("char **")
        buf_len = self._lib.BIO_get_mem_data(bio, buf)
        self.openssl_assert(buf_len > 0)
        self.openssl_assert(buf[0] != self._ffi.NULL)
        bio_data = self._ffi.buffer(buf[0], buf_len)[:]
        return bio_data 
開發者ID:DirceuSilvaLabs,項目名稱:noc-orchestrator,代碼行數:12,代碼來源:backend.py

示例7: x509_name_bytes

# 需要導入模塊: from cryptography.hazmat.bindings._openssl import ffi [as 別名]
# 或者: from cryptography.hazmat.bindings._openssl.ffi import buffer [as 別名]
def x509_name_bytes(self, name):
        x509_name = _encode_name_gc(self, name)
        pp = self._ffi.new("unsigned char **")
        res = self._lib.i2d_X509_NAME(x509_name, pp)
        self.openssl_assert(pp[0] != self._ffi.NULL)
        pp = self._ffi.gc(
            pp, lambda pointer: self._lib.OPENSSL_free(pointer[0])
        )
        self.openssl_assert(res > 0)
        return self._ffi.buffer(pp[0], res)[:] 
開發者ID:lordmuffin,項目名稱:aws-cfn-plex,代碼行數:12,代碼來源:backend.py


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