本文整理汇总了Python中ctypes.c_ulonglong方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.c_ulonglong方法的具体用法?Python ctypes.c_ulonglong怎么用?Python ctypes.c_ulonglong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes.c_ulonglong方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contract_ss
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def contract_ss(civec, norb, nelec):
strs = civec._strs
ndet = len(strs)
ci1 = numpy.zeros_like(civec)
strs = numpy.asarray(strs, order='C')
civec = numpy.asarray(civec, order='C')
ci1 = numpy.asarray(ci1, order='C')
libhci.contract_ss_c(ctypes.c_int(norb),
ctypes.c_int(nelec[0]),
ctypes.c_int(nelec[1]),
strs.ctypes.data_as(ctypes.c_void_p),
civec.ctypes.data_as(ctypes.c_void_p),
ctypes.c_ulonglong(ndet),
ci1.ctypes.data_as(ctypes.c_void_p))
return ci1
示例2: memory
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def memory(self):
"""Memory information in bytes
Example:
>>> print(ctx.device(0).memory())
{'total': 4238016512L, 'used': 434831360L, 'free': 3803185152L}
Returns:
total/used/free memory in bytes
"""
class GpuMemoryInfo(Structure):
_fields_ = [
('total', c_ulonglong),
('free', c_ulonglong),
('used', c_ulonglong),
]
c_memory = GpuMemoryInfo()
_check_return(_NVML.get_function(
"nvmlDeviceGetMemoryInfo")(self.hnd, byref(c_memory)))
return {'total': c_memory.total, 'free': c_memory.free, 'used': c_memory.used}
示例3: memory_read64
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def memory_read64(self, addr, num_long_words):
"""Reads memory from the target system in units of 64-bits.
Args:
self (JLink): the ``JLink`` instance
addr (int): start address to read from
num_long_words (int): number of long words to read
Returns:
List of long words read from the target system.
Raises:
JLinkException: if memory could not be read
"""
buf_size = num_long_words
buf = (ctypes.c_ulonglong * buf_size)()
units_read = self._dll.JLINKARM_ReadMemU64(addr, buf_size, buf, 0)
if units_read < 0:
raise errors.JLinkException(units_read)
return buf[:units_read]
示例4: get_physical_ram
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def get_physical_ram():
"""Returns the amount of installed RAM in Mb, rounded to the nearest number.
"""
# https://msdn.microsoft.com/library/windows/desktop/aa366589.aspx
class MemoryStatusEx(ctypes.Structure):
_fields_ = [
('dwLength', ctypes.c_ulong),
('dwMemoryLoad', ctypes.c_ulong),
('dwTotalPhys', ctypes.c_ulonglong),
('dwAvailPhys', ctypes.c_ulonglong),
('dwTotalPageFile', ctypes.c_ulonglong),
('dwAvailPageFile', ctypes.c_ulonglong),
('dwTotalVirtual', ctypes.c_ulonglong),
('dwAvailVirtual', ctypes.c_ulonglong),
('dwAvailExtendedVirtual', ctypes.c_ulonglong),
]
stat = MemoryStatusEx()
stat.dwLength = ctypes.sizeof(MemoryStatusEx) # pylint: disable=W0201
ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(stat))
return int(round(stat.dwTotalPhys / 1024. / 1024.))
示例5: get_free_space
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def get_free_space(path):
"""Returns the number of free bytes.
On POSIX platforms, this returns the free space as visible by the current
user. On some systems, there's a percentage of the free space on the partition
that is only accessible as the root user.
"""
if sys.platform == 'win32':
free_bytes = ctypes.c_ulonglong(0)
windll.kernel32.GetDiskFreeSpaceExW(
ctypes.c_wchar_p(path), None, None, ctypes.pointer(free_bytes))
return free_bytes.value
# For OSes other than Windows.
f = fs.statvfs(path) # pylint: disable=E1101
return f.f_bfree * f.f_frsize
### Write file functions.
示例6: crypto_box
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_box(msg, nonce, pk, sk):
'''
Using a public key and a secret key encrypt the given message. A nonce
must also be passed in, never reuse the nonce
enc_msg = nacl.crypto_box('secret message', <unique nonce>, <public key string>, <secret key string>)
'''
if len(pk) != crypto_box_PUBLICKEYBYTES:
raise ValueError('Invalid public key')
if len(sk) != crypto_box_SECRETKEYBYTES:
raise ValueError('Invalid secret key')
if len(nonce) != crypto_box_NONCEBYTES:
raise ValueError('Invalid nonce')
pad = b'\x00' * crypto_box_ZEROBYTES + msg
c = ctypes.create_string_buffer(len(pad))
ret = nacl.crypto_box(c, pad, ctypes.c_ulonglong(len(pad)), nonce, pk, sk)
if ret:
raise CryptError('Unable to encrypt message')
return c.raw[crypto_box_BOXZEROBYTES:]
示例7: crypto_box_open
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_box_open(ctxt, nonce, pk, sk):
'''
Decrypts a message given the receiver's private key, and sender's public key
'''
if len(pk) != crypto_box_PUBLICKEYBYTES:
raise ValueError('Invalid public key')
if len(sk) != crypto_box_SECRETKEYBYTES:
raise ValueError('Invalid secret key')
if len(nonce) != crypto_box_NONCEBYTES:
raise ValueError('Invalid nonce')
pad = b'\x00' * crypto_box_BOXZEROBYTES + ctxt
msg = ctypes.create_string_buffer(len(pad))
ret = nacl.crypto_box_open(
msg,
pad,
ctypes.c_ulonglong(len(pad)),
nonce,
pk,
sk)
if ret:
raise CryptError('Unable to decrypt ciphertext')
return msg.raw[crypto_box_ZEROBYTES:]
示例8: crypto_box_easy
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_box_easy(msg, nonce, pk, sk):
'''
Using a public key and a secret key encrypt the given message. A nonce
must also be passed in, never reuse the nonce
enc_msg = nacl.crypto_box_easy('secret message', <unique nonce>, <public key string>, <secret key string>)
'''
if len(pk) != crypto_box_PUBLICKEYBYTES:
raise ValueError('Invalid public key')
if len(sk) != crypto_box_SECRETKEYBYTES:
raise ValueError('Invalid secret key')
if len(nonce) != crypto_box_NONCEBYTES:
raise ValueError('Invalid nonce')
c = ctypes.create_string_buffer(len(msg) + crypto_box_MACBYTES)
ret = nacl.crypto_box(c, msg, ctypes.c_ulonglong(len(msg)), nonce, pk, sk)
if ret:
raise CryptError('Unable to encrypt message')
return c.raw
示例9: crypto_box_open_easy
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_box_open_easy(ctxt, nonce, pk, sk):
'''
Decrypts a message given the receiver's private key, and sender's public key
'''
if len(pk) != crypto_box_PUBLICKEYBYTES:
raise ValueError('Invalid public key')
if len(sk) != crypto_box_SECRETKEYBYTES:
raise ValueError('Invalid secret key')
if len(nonce) != crypto_box_NONCEBYTES:
raise ValueError('Invalid nonce')
msg = ctypes.create_string_buffer(len(ctxt) - crypto_box_MACBYTES)
ret = nacl.crypto_box_open(
msg,
ctxt,
ctypes.c_ulonglong(len(ctxt)),
nonce,
pk,
sk)
if ret:
raise CryptError('Unable to decrypt ciphertext')
return msg.raw[crypto_box_ZEROBYTES:]
示例10: crypto_box_easy_afternm
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_box_easy_afternm(msg, nonce, k):
'''
Using a precalculated shared key, encrypt the given message. A nonce
must also be passed in, never reuse the nonce
enc_msg = nacl.crypto_box_easy_afternm('secret message', <unique nonce>, <shared key string>)
'''
if len(k) != crypto_box_BEFORENMBYTES:
raise ValueError('Invalid shared key')
if len(nonce) != crypto_box_NONCEBYTES:
raise ValueError('Invalid nonce')
ctxt = ctypes.create_string_buffer(len(msg) + crypto_box_MACBYTES)
ret = nacl.crypto_box_easy_afternm(ctxt, msg, ctypes.c_ulonglong(len(msg)), nonce, k)
if ret:
raise CryptError('Unable to encrypt messsage')
return ctxt.raw
示例11: crypto_box_open_easy_afternm
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_box_open_easy_afternm(ctxt, nonce, k):
'''
Decrypts a ciphertext ctxt given k
'''
if len(k) != crypto_box_BEFORENMBYTES:
raise ValueError('Invalid shared key')
if len(nonce) != crypto_box_NONCEBYTES:
raise ValueError('Invalid nonce')
msg = ctypes.create_string_buffer(len(ctxt) - crypto_box_MACBYTES)
ret = nacl.crypto_box_open_easy_afternm(
msg,
ctxt,
ctypes.c_ulonglong(len(ctxt)),
nonce,
k)
if ret:
raise CryptError('unable to decrypt message')
return msg.raw
示例12: crypto_box_seal
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_box_seal(msg, pk):
'''
Using a public key to encrypt the given message. The identity of the sender cannot be verified.
enc_msg = nacl.crypto_box_seal('secret message', <public key string>)
'''
if not HAS_SEAL:
raise ValueError('Underlying Sodium library does not support sealed boxes')
if len(pk) != crypto_box_PUBLICKEYBYTES:
raise ValueError('Invalid public key')
if not isinstance(msg, bytes):
raise TypeError('Message must be bytes')
c = ctypes.create_string_buffer(len(msg) + crypto_box_SEALBYTES)
ret = nacl.crypto_box_seal(c, msg, ctypes.c_ulonglong(len(msg)), pk)
if ret:
raise CryptError('Unable to encrypt message')
return c.raw
示例13: crypto_box_seal_open
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_box_seal_open(ctxt, pk, sk):
'''
Decrypts a message given the receiver's public and private key.
'''
if not HAS_SEAL:
raise ValueError('Underlying Sodium library does not support sealed boxes')
if len(pk) != crypto_box_PUBLICKEYBYTES:
raise ValueError('Invalid public key')
if len(sk) != crypto_box_SECRETKEYBYTES:
raise ValueError('Invalid secret key')
if not isinstance(ctxt, bytes):
raise TypeError('Message must be bytes')
c = ctypes.create_string_buffer(len(ctxt) - crypto_box_SEALBYTES)
ret = nacl.crypto_box_seal_open(c, ctxt, ctypes.c_ulonglong(len(ctxt)), pk, sk)
if ret:
raise CryptError('Unable to decrypt message')
return c.raw
# Signing functions
示例14: crypto_sign
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_sign(msg, sk):
'''
Sign the given message with the given signing key
'''
if len(sk) != crypto_sign_SECRETKEYBYTES:
raise ValueError('Invalid secret key')
sig = ctypes.create_string_buffer(len(msg) + crypto_sign_BYTES)
slen = ctypes.pointer(ctypes.c_ulonglong())
ret = nacl.crypto_sign(
sig,
slen,
msg,
ctypes.c_ulonglong(len(msg)),
sk)
if ret:
raise ValueError('Failed to sign message')
return sig.raw
示例15: crypto_sign_open
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ulonglong [as 别名]
def crypto_sign_open(sig, vk):
'''
Verifies the signed message sig using the signer's verification key
'''
if len(vk) != crypto_sign_PUBLICKEYBYTES:
raise ValueError('Invalid public key')
msg = ctypes.create_string_buffer(len(sig))
msglen = ctypes.c_ulonglong()
msglenp = ctypes.pointer(msglen)
ret = nacl.crypto_sign_open(
msg,
msglenp,
sig,
ctypes.c_ulonglong(len(sig)),
vk)
if ret:
raise ValueError('Failed to validate message')
return msg.raw[:msglen.value] # pylint: disable=invalid-slice-index