当前位置: 首页>>代码示例>>Python>>正文


Python hashlib.algorithms方法代码示例

本文整理汇总了Python中hashlib.algorithms方法的典型用法代码示例。如果您正苦于以下问题:Python hashlib.algorithms方法的具体用法?Python hashlib.algorithms怎么用?Python hashlib.algorithms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hashlib的用法示例。


在下文中一共展示了hashlib.algorithms方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_hashes

# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import algorithms [as 别名]
def do_hashes(self,line):
        try:
            l = line.split(" ")
            if (l[0] == ""):
                self.help_hashes()
            else:
                id = int(l[0])
                body, sz = CTCore.get_response_and_size(id, "all")
                name = CTCore.get_name(id)

                print " Hashes of object {} ({}):".format(str(id),name) + newLine

                for alg in hashlib.algorithms:
                    hashfunc = getattr(hashlib, alg)
                    hash = hashfunc(StringIO.StringIO(body).getvalue()).hexdigest()
                    print " {0:8}  :   {1}".format(alg, hash)

                print ""

        except Exception,e:
            print str(e) 
开发者ID:omriher,项目名称:CapTipper,代码行数:23,代码来源:CTConsole.py

示例2: to_native

# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import algorithms [as 别名]
def to_native(self, value, context=None):
        value = super(HashType, self).to_native(value, context)

        if ':' not in value:
            raise ValidationError(self.messages['hash_invalid'])

        hash_type, hash_value = value.split(':', 1)

        if hash_type not in algorithms:
            raise ValidationError(self.messages['hash_invalid'])

        if len(hash_value) != hash_new(hash_type).digest_size * 2:
            raise ValidationError(self.messages['hash_length'])
        try:
            int(hash_value, 16)
        except ValueError:
            raise ConversionError(self.messages['hash_hex'])
        return value 
开发者ID:openprocurement,项目名称:openprocurement.api,代码行数:20,代码来源:models.py

示例3: test_algorithms_attribute

# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import algorithms [as 别名]
def test_algorithms_attribute(self):
        self.assertEqual(hashlib.algorithms,
            tuple([_algo for _algo in self.supported_hash_names if
                                                _algo.islower()])) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_hashlib.py

示例4: _sync_remote_entries_with_existing_fetch

# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import algorithms [as 别名]
def _sync_remote_entries_with_existing_fetch(self):
        payload_entries = self.payload_entries()
        for url, length, filename in self.fetch_entries():
            entry_path = os.path.normpath(filename.lstrip("*"))
            if entry_path in payload_entries:
                for alg in self.algorithms:
                    digest = payload_entries[entry_path].get(alg, None)
                    remote_entry = self.remote_entries.get(filename)
                    if remote_entry:
                        continue
                    self.add_remote_file(filename, url, length, alg, digest) 
开发者ID:fair-research,项目名称:bdbag,代码行数:13,代码来源:bdbagit.py

示例5: add_remote_file

# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import algorithms [as 别名]
def add_remote_file(self, filename, url, length, alg, digest):
        if alg not in self.algorithms:
            self.algorithms.append(alg)
        make_remote_file_entry(self.remote_entries, filename, url, length, alg, digest) 
开发者ID:fair-research,项目名称:bdbag,代码行数:6,代码来源:bdbagit.py

示例6: crack

# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import algorithms [as 别名]
def crack(hashstr, wordlist):
    for word in wordlist:
        for hashtype in hashlib.algorithms:
            func = getattr(hashlib, hashtype)
            if func(word).hexdigest().lower() == hashstr.lower():
                return word, hashtype
    return None, None 
开发者ID:methos2016,项目名称:recon-ng,代码行数:9,代码来源:bozocrack.py

示例7: __init__

# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import algorithms [as 别名]
def __init__(self, *args, **kwargs):
        algorithms = set()
        for algorithm in self.supported_hash_names:
            algorithms.add(algorithm.lower())
        self.constructors_to_test = {}
        for algorithm in algorithms:
            self.constructors_to_test[algorithm] = set()

        # For each algorithm, test the direct constructor and the use
        # of hashlib.new given the algorithm name.
        for algorithm, constructors in self.constructors_to_test.items():
            constructors.add(getattr(hashlib, algorithm))
            def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm):
                if data is None:
                    return hashlib.new(_alg)
                return hashlib.new(_alg, data)
            constructors.add(_test_algorithm_via_hashlib_new)

        _hashlib = self._conditional_import_module('_hashlib')
        if _hashlib:
            # These two algorithms should always be present when this module
            # is compiled.  If not, something was compiled wrong.
            assert hasattr(_hashlib, 'openssl_md5')
            assert hasattr(_hashlib, 'openssl_sha1')
            for algorithm, constructors in self.constructors_to_test.items():
                constructor = getattr(_hashlib, 'openssl_'+algorithm, None)
                if constructor:
                    constructors.add(constructor)

        _md5 = self._conditional_import_module('_md5')
        if _md5:
            self.constructors_to_test['md5'].add(_md5.new)
        _sha = self._conditional_import_module('_sha')
        if _sha:
            self.constructors_to_test['sha1'].add(_sha.new)
        _sha256 = self._conditional_import_module('_sha256')
        if _sha256:
            self.constructors_to_test['sha224'].add(_sha256.sha224)
            self.constructors_to_test['sha256'].add(_sha256.sha256)
        _sha512 = self._conditional_import_module('_sha512')
        if _sha512:
            self.constructors_to_test['sha384'].add(_sha512.sha384)
            self.constructors_to_test['sha512'].add(_sha512.sha512)

        super(HashLibTestCase, self).__init__(*args, **kwargs) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:47,代码来源:test_hashlib.py

示例8: _validate_entries

# 需要导入模块: import hashlib [as 别名]
# 或者: from hashlib import algorithms [as 别名]
def _validate_entries(self, processes, callback=None):
        """
        Verify that the actual file contents match the recorded hashes stored in the manifest files
        """
        errors = list()

        if os.name == 'posix':
            worker_init = posix_multiprocessing_worker_initializer
        else:
            worker_init = None

        args = ((self.path,
                 self.normalized_filesystem_names.get(rel_path, rel_path),
                 hashes,
                 self.algorithms) for rel_path, hashes in self.entries.items())

        try:
            if processes == 1:
                count = 0
                hash_results = []
                totalHashes = len(self.entries.items())
                for i in args:
                    hash_results.append(_calc_hashes(i))
                    count += 1
                    if callback:
                        if not callback(count, totalHashes):
                            raise BaggingInterruptedError("Bag validation interrupted!")

            else:  # pragma: no cover
                pool = None
                try:
                    pool = multiprocessing.Pool(processes if processes else None, initializer=worker_init)
                    hash_results = pool.map(_calc_hashes, args)
                finally:
                    if pool:
                        pool.terminate()
        except BaggingInterruptedError:
            raise
        # Any unhandled exceptions are probably fatal
        except:
            LOGGER.error(_("Unable to calculate file hashes for %s"), self)
            raise

        for rel_path, f_hashes, hashes in hash_results:
            for alg, computed_hash in f_hashes.items():
                stored_hash = hashes[alg]
                if stored_hash.lower() != computed_hash:
                    e = ChecksumMismatch(rel_path, alg, stored_hash.lower(), computed_hash)
                    LOGGER.warning(force_unicode(e))
                    errors.append(e)

        if errors:
            raise BagValidationError(_("Bag validation failed"), errors) 
开发者ID:fair-research,项目名称:bdbag,代码行数:55,代码来源:bdbagit.py


注:本文中的hashlib.algorithms方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。