Module refinery.units.crypto.hash.checksums

Implements hash algorithms of short length, commonly used as checksums.

Expand source code Browse git
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Implements hash algorithms of short length, commonly used as checksums.
"""
import zlib
import struct

from refinery.units.crypto.hash import HashUnit


class crc32(HashUnit):
    """
    Returns the CRC32 Hash of the input data.
    """
    def _algorithm(self, data: bytes) -> bytes:
        return struct.pack('>I', zlib.crc32(data))


class adler32(HashUnit):
    """
    Returns the Adler32 Hash of the input data.
    """
    def _algorithm(self, data: bytes) -> bytes:
        return struct.pack('>I', zlib.adler32(data))

Classes

class crc32 (text=False)

Returns the CRC32 Hash of the input data.

Expand source code Browse git
class crc32(HashUnit):
    """
    Returns the CRC32 Hash of the input data.
    """
    def _algorithm(self, data: bytes) -> bytes:
        return struct.pack('>I', zlib.crc32(data))

Ancestors

Class variables

var required_dependencies
var optional_dependencies

Inherited members

class adler32 (text=False)

Returns the Adler32 Hash of the input data.

Expand source code Browse git
class adler32(HashUnit):
    """
    Returns the Adler32 Hash of the input data.
    """
    def _algorithm(self, data: bytes) -> bytes:
        return struct.pack('>I', zlib.adler32(data))

Ancestors

Class variables

var required_dependencies
var optional_dependencies

Inherited members