Module refinery.units.crypto.hash
Implements various hashing algorithms.
Expand source code Browse git
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Implements various hashing algorithms.
"""
from refinery.units import Arg, Unit, abc
class HashUnit(Unit, abstract=True):
@abc.abstractmethod
def _algorithm(self, data: bytes) -> bytes:
raise NotImplementedError
def __init__(
self,
reps: Arg.Number('-r', help='Optionally specify a number of times to apply the hash to its own output.') = 1,
text: Arg.Switch('-t', help='Output a hexadecimal representation of the hash.') = False,
**kwargs
):
super().__init__(text=text, reps=reps, **kwargs)
def process(self, data: bytes) -> bytes:
reps = self.args.reps
digest = data
for _ in range(reps):
digest = self._algorithm(digest)
if self.args.text:
digest = digest.hex().encode(self.codec)
return digest
Sub-modules
refinery.units.crypto.hash.checksums
-
Implements hash algorithms of short length, commonly used as checksums.
refinery.units.crypto.hash.cryptographic
-
Implements various cryptographic hashing algorithms.
refinery.units.crypto.hash.imphash
refinery.units.crypto.hash.maru
refinery.units.crypto.hash.murmur
refinery.units.crypto.hash.password_hashes
-
Implements password hashing algorithms.
refinery.units.crypto.hash.xxhash
Classes
class HashUnit (reps=1, text=False, **kwargs)
-
Expand source code Browse git
class HashUnit(Unit, abstract=True): @abc.abstractmethod def _algorithm(self, data: bytes) -> bytes: raise NotImplementedError def __init__( self, reps: Arg.Number('-r', help='Optionally specify a number of times to apply the hash to its own output.') = 1, text: Arg.Switch('-t', help='Output a hexadecimal representation of the hash.') = False, **kwargs ): super().__init__(text=text, reps=reps, **kwargs) def process(self, data: bytes) -> bytes: reps = self.args.reps digest = data for _ in range(reps): digest = self._algorithm(digest) if self.args.text: digest = digest.hex().encode(self.codec) return digest
Ancestors
Subclasses
- adler32
- crc32
- blk224
- blk256
- blk384
- blk512
- keccak256
- md2
- md4
- md5
- refinery.units.crypto.hash.cryptographic.ripemd128
- ripemd160
- sha1
- sha224
- sha256
- sha384
- sha3_224
- sha3_256
- sha3_384
- sha3_512
- sha512
- imphash
- maru
- MurMurHash
- ntlm
- xxh
Class variables
var required_dependencies
var optional_dependencies
Inherited members