本文整理汇总了Python中sha.sha方法的典型用法代码示例。如果您正苦于以下问题:Python sha.sha方法的具体用法?Python sha.sha怎么用?Python sha.sha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sha
的用法示例。
在下文中一共展示了sha.sha方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mangleData
# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def mangleData(self, data, index):
self.sha1_offset = 208
self.md5_offset = 256
self.header_offset = 360
self.filedata_offset = 3170
data = MangleFile.mangleData(self, data, index)
if USE_HACHOIR:
#data.tofile(open('/tmp/oops', 'wb'))
hachoir_config.quiet = True
data_str = data.tostring()
parser = guessParser(StringInputStream(data_str))
if parser:
self.useHachoirParser(parser)
summary_data = data[self.header_offset:].tostring()
checksum = md5(summary_data).digest()
data[self.md5_offset:self.md5_offset+16] = array('B', checksum)
summary_data = data[self.header_offset:self.filedata_offset].tostring()
checksum = sha(summary_data).hexdigest()
data[self.sha1_offset:self.sha1_offset+40] = array('B', checksum)
return data
示例2: do_encrypt
# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def do_encrypt(result, encrypt, salt_size=None, salt=None):
if PASSLIB_AVAILABLE:
try:
crypt = getattr(passlib.hash, encrypt)
except:
raise ValueError("passlib does not support '%s' algorithm" % encrypt)
if salt_size:
result = crypt.encrypt(result, salt_size=salt_size)
elif salt:
result = crypt.encrypt(result, salt=salt)
else:
result = crypt.encrypt(result)
else:
raise ValueError("passlib must be installed to encrypt vars_prompt values")
return result
# Note, sha1 is the only hash algorithm compatible with python2.4 and with
# FIPS-140 mode (as of 11-2014)
示例3: secure_hash
# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def secure_hash(filename, hash_func=sha1):
''' Return a secure hash hex digest of local file, None if file is not present or a directory. '''
if not os.path.exists(filename) or os.path.isdir(filename):
return None
digest = hash_func()
blocksize = 64 * 1024
try:
infile = open(filename, 'rb')
block = infile.read(blocksize)
while block:
digest.update(block)
block = infile.read(blocksize)
infile.close()
except IOError as e:
raise ValueError("error while accessing the file %s, error was: %s" % (filename, e))
return digest.hexdigest()
# The checksum algorithm must match with the algorithm in ShellModule.checksum() method
示例4: __init__
# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def __init__(self, title):
self.title = title
self.filename = None
self.headcomments = ""
self.campaign = []
self.keywords = []
self.crc = None
self.sha = None
self.preexec = None
self.preexec_output = None
示例5: dump_campaign
# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def dump_campaign(test_campaign):
print "#"*(len(test_campaign.title)+6)
print "## %(title)s ##" % test_campaign
print "#"*(len(test_campaign.title)+6)
if test_campaign.sha and test_campaign.crc:
print "CRC=[%(crc)s] SHA=[%(sha)s]" % test_campaign
print "from file %(filename)s" % test_campaign
print
for ts in test_campaign:
if ts.crc:
print "+--[%s]%s(%s)--" % (ts.name,"-"*max(2,80-len(ts.name)-18),ts.crc)
else:
print "+--[%s]%s" % (ts.name,"-"*max(2,80-len(ts.name)-6))
if ts.keywords:
print " kw=%s" % ",".join(ts.keywords)
for t in ts:
print "%(num)03i %(name)s" % t
c = k = ""
if t.keywords:
k = "kw=%s" % ",".join(t.keywords)
if t.crc:
c = "[%(crc)s] " % t
if c or k:
print " %s%s" % (c,k)
#### COMPUTE CAMPAIGN DIGESTS ####
示例6: sha1
# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def sha1(x):
return sha.sha(x).hexdigest().upper()
示例7: compute_campaign_digests
# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def compute_campaign_digests(test_campaign):
dc = ""
for ts in test_campaign:
dts = ""
for t in ts:
dt = t.test.strip()
t.crc = crc32(dt)
dts += "\0"+dt
ts.crc = crc32(dts)
dc += "\0\x01"+dts
test_campaign.crc = crc32(dc)
test_campaign.sha = sha1(open(test_campaign.filename).read())
#### FILTER CAMPAIGN #####
示例8: archive
# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def archive(self):
import tarfile
arch_name=self.get_arch_name()
try:
self.base_path
except AttributeError:
self.base_path=self.path
node=self.base_path.make_node(arch_name)
try:
node.delete()
except OSError:
pass
files=self.get_files()
if self.algo.startswith('tar.'):
tar=tarfile.open(arch_name,'w:'+self.algo.replace('tar.',''))
for x in files:
self.add_tar_file(x,tar)
tar.close()
elif self.algo=='zip':
import zipfile
zip=zipfile.ZipFile(arch_name,'w',compression=zipfile.ZIP_DEFLATED)
for x in files:
archive_name=self.get_base_name()+'/'+x.path_from(self.base_path)
zip.write(x.abspath(),archive_name,zipfile.ZIP_DEFLATED)
zip.close()
else:
self.fatal('Valid algo types are tar.bz2, tar.gz, tar.xz or zip')
try:
from hashlib import sha1 as sha
except ImportError:
from sha import sha
try:
digest=" (sha=%r)"%sha(node.read()).hexdigest()
except Exception:
digest=''
Logs.info('New archive created: %s%s'%(self.arch_name,digest))
示例9: graft_path
# 需要导入模块: import sha [as 别名]
# 或者: from sha import sha [as 别名]
def graft_path(graft_points, path):
normalized_path = os.path.realpath(path)
for graft_point in graft_points:
old_prefix, new_prefix = graft_point
if normalized_path.startswith(old_prefix):
return re.sub(r'^' + old_prefix, new_prefix, normalized_path)
return normalized_path
# hashlib is only available in python 2.5 or higher, but the 'sha' module
# produces a DeprecationWarning in python 2.6 or higher. We want to support
# python 2.4 and above without any stupid warnings, so let's try using hashlib
# first, and downgrade if it fails.