資源簡介
已經在windows下編譯好的32位Botan-2.10.0, 可以直接使用
Botan是一個功能齊全的加解密庫,詳細用法可以查看官方網站
代碼片段和文件信息
#!/usr/bin/python
“““
Python?wrapper?of?the?botan?crypto?library
https://botan.randombit.net
(C)?201520172018?Jack?Lloyd
(C)?2015?Uri??Blumenthal?(extensions?and?patches)
Botan?is?released?under?the?Simplified?BSD?License?(see?license.txt)
This?module?uses?the?ctypes?module?and?is?usable?by?programs?running
under?at?least?CPython?2.7?CPython?3.x?and?PyPy
It?uses?botan‘s?ffi?module?which?exposes?a?C?API.?This?version?of?the
module?requires?FFI?API?version?20180713?which?was?introduced?in
Botan?2.8
“““
from?ctypes?import?CDLL?POINTER?byref?create_string_buffer?\
????c_void_p?c_size_t?c_uint8?c_uint32?c_uint64?c_int?c_char?c_char_p
from?sys?import?version_info
from?time?import?strptime?mktime
from?binascii?import?hexlify
from?datetime?import?datetime
BOTAN_FFI_VERSION?=?20180713
#
#?base?exception?for?all?exceptions?raised?from?this?module
#
class?BotanException(Exception):
????def?__init__(self?message?rc=0):
????????self.__rc?=?rc
????????if?rc?==?0:
????????????super(BotanException?self).__init__(message)
????????else:
????????????descr?=?botan.botan_error_description(rc).decode(‘ascii‘)
????????????super(BotanException?self).__init__(“%s:?%d?(%s)“?%?(message?rc?descr))
????def?error_code(self):
????????return?self.__rc
#
#?Module?initialization
#
def?load_botan_dll(expected_version):
????possible_dll_names?=?[‘libbotan-2.dylib‘?‘libbotan-2.so‘]?+?\
?????????????????????????[‘libbotan-2.so.%d‘?%?(v)?for?v?in?reversed(range(8?16))]
????for?dll_name?in?possible_dll_names:
????????try:
????????????dll?=?CDLL(dll_name)
????????????dll.botan_ffi_supports_api.argtypes?=?[c_uint32]
????????????dll.botan_ffi_supports_api.restype?=?c_int
????????????if?dll.botan_ffi_supports_api(expected_version)?==?0:
????????????????return?dll
????????except?OSError:
????????????pass
????return?None
botan?=?load_botan_dll(BOTAN_FFI_VERSION)?#?pylint:?disable=invalid-name
if?botan?is?None:
????raise?BotanException(“Could?not?find?a?usable?Botan?shared?object?library“)
#
#?ctypes?function?prototypes
#
def?errcheck_for(fn_name):
????def?errcheck(rc?_func?_args):
????????#?No?idea?what?to?do?if?return?value?isn‘t?an?int?just?return?it
????????if?not?isinstance(rc?int):
????????????return?rc
????????if?rc?>=?0:
????????????return?rc
????????if?rc?==?-10:?#?insufficient?buffer?space?pass?up?to?caller
????????????return?rc
????????raise?BotanException(‘%s?failed‘?%?(fn_name)?rc)
????return?errcheck
botan.botan_version_string.argtypes?=?[]
botan.botan_version_string.restype?=?c_char_p
botan.botan_error_description.argtypes?=?[c_int]
botan.botan_error_description.restype?=?c_char_p
#?RNG
botan.botan_rng_init.argtypes?=?[c_void_p?c_char_p]
botan.botan_rng_init.errcheck?=?errcheck_for(‘botan_rng_init‘)
botan.botan_rng_destroy.argtypes?=?[c_void_p]
botan.botan_rng_destroy.errcheck?=?errcheck_for(‘botan_rng_destroy‘)
botan.botan_rng_reseed.argtypes?=?[c_void_p?c_size_t]
botan.botan_rng_reseed.errcheck?=?errcheck_for(‘bota
- 上一篇:游戲策劃之數值策劃入門文檔
- 下一篇:getdata 2.22 及 破解 補丁
評論
共有 條評論