Calculator
InputType = Union[int, bytes, bytearray, memoryview, BinaryIO, Iterable[Union[bytes, bytearray, memoryview]]]
module-attribute
Type alias for acceptable input types for Calculator.
__init__(configuration, optimized=False)
Creates a new Calculator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
configuration |
Configuration
|
for the crc algorithm. |
required |
optimized |
bool
|
whether a register optimized for speed shall be used. |
False
|
initializing an optimized calculator might take some extra time, calculation itself will be faster though.
checksum(data)
Calculates the checksum for the given data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
InputType
|
which will be used as input for the checksum. |
required |
Returns:
Type | Description |
---|---|
int
|
Checksum for the given input data. |
verify(data, expected)
Verifies that the checksum for the given data is the expected one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
InputType
|
which will be used as input for the checksum. |
required |
expected |
int
|
checksum. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the expected checksum matches the actual checksum for the given data, False otherwise. |