From d23a584527a87a4e84453e859b70877ccae76fa0 Mon Sep 17 00:00:00 2001 From: Github Action Date: Sun, 14 Apr 2024 09:38:20 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20Nicorett?= =?UTF-8?q?i/crc@2368149d71ae9580bc9df1c69866c5267e299d0b=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog/unreleased/index.html | 1 + search/search_index.json | 2 +- sitemap.xml.gz | Bin 382 -> 382 bytes 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog/unreleased/index.html b/changelog/unreleased/index.html index 8fd50b5..8ba4912 100644 --- a/changelog/unreleased/index.html +++ b/changelog/unreleased/index.html @@ -1083,6 +1083,7 @@

Unreleased

🔩 Internal

diff --git a/search/search_index.json b/search/search_index.json index 351787d..8425269 100644 --- a/search/search_index.json +++ b/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Home","text":"CRC

Calculate CRC checksums, verify CRC checksum, predefined CRC configurations, custom CRC configurations

"},{"location":"#available-crc-configurations","title":"Available CRC Configurations","text":"

The library includes a variety of common CRC configurations for convenience. To explore the full range of available CRC configurations, please checkout the configurations section of the documentation. If you need a new configuration to be readily available, consider submitting a PR or raising an issue.

"},{"location":"#custom-configurations","title":"Custom Configurations","text":"

If you want to create a custom configuration, you should have the following information available:

In case you only have a name of a specific crc configuration/algorithm and you are unsure what are the specific parameters of it, a look into this crc-catalogue might help.

Note

This library currently only supports bit widths of full bytes 8, 16, 24, 32, ...

"},{"location":"#requirements","title":"Requirements","text":""},{"location":"#installation","title":"Installation","text":"
pip install crc\n
"},{"location":"#examples","title":"Examples","text":""},{"location":"#create-a-calculator","title":"Create a Calculator","text":"Pre defined configurationCustom configuration
from crc import Calculator, Crc8\n\ncalculator = Calculator(Crc8.CCITT)\n
from crc import Calculator, Configuration\n\nconfig = Configuration(\n    width=8,\n    poly=0x07,\n    init_value=0x00,\n    final_xor_value=0x00,\n    reverse_input=False,\n    reverse_output=False,\n)\n\ncalculator = Calculator(config)\n
"},{"location":"#calculate-a-checksum","title":"Calculate a checksum","text":"StandardOptimized for speed
from crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT)\n\nassert expected == calculator.checksum(data)\n
from crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert expected == calculator.checksum(data)\n
"},{"location":"#verify-a-checksum","title":"Verify a checksum","text":"StandardOptimized for speed
from crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT)\n\nassert calculator.verify(data, expected)\n
from crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.verify(data, expected)\n
"},{"location":"#supported-data-types","title":"Supported data types","text":"intbytesbytearrayFileByteIoIterable of bytesByte convertibles
from crc import Calculator, Crc8\n\nexpected = 0x20\ndata = 97\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\nexpected = 0xF4\ndata = b\"123456789\"\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\nexpected = 0xF4\ndata = bytearray(b\"123456789\")\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\nexpected = 0xF4\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nwith open(\"afile.txt\", \"rb\") as f:\n    assert calculator.checksum(f) == expected\n
import io\n\nfrom crc import Calculator, Crc8\n\nexpected = 0xF4\ndata = io.ByteIo(b\"123456789\")\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\nexpected = 0xF4\ncalculator = Calculator(Crc8.CCITT, optimized=True)\ndata = (data for data in [b\"12\", b\"34\", b\"56\", b\"78\", b\"9\"])\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\n\nclass ByteConvertible:\n    def __init__(self, data):\n        self._data = data\n\n    def __bytes__(self):\n        return self._data.encode(\"utf-8\")\n\n\nexpected = 0xF4\ncalculator = Calculator(Crc8.CCITT, optimized=True)\ndata = ByteConvertible(\"123456789\")\n\nassert calculator.checksum(bytes(data)) == expected\n
"},{"location":"#calculate-a-checksum-with-raw-registers","title":"Calculate a checksum with raw registers","text":"RegisterTableBasedRegister
from crc import Crc8, Register\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\nregister = Register(Crc8.CCITT)\n\nregister.init()\nregister.update(data)\nassert expected == register.digest()\n
from crc import Crc8, TableBasedRegister\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\nregister = TableBasedRegister(Crc8.CCITT)\n\nregister.init()\nregister.update(data)\nassert expected == register.digest()\n
"},{"location":"#references-resources","title":"References & Resources","text":""},{"location":"cli/","title":"CLI Tools","text":"

The crc library comes with a small command line tool which can generate crc lookup tables if needed.

usage: crc table [-h] <width> <polynomial>\n\npositional arguments:\n  <width>       width of the crc algorithm, common width's are 8, 16, 32, 64\n  <polynomial>  hex value of the polynomial used for calculating the crc table\n\noptional arguments:\n  -h, --help    show this help message and exit\n

Example Usage:

user@host ~$ crc table 8 0x7D\n
"},{"location":"configurations/","title":"Configurations","text":""},{"location":"configurations/#crc8","title":"Crc8","text":"CCITTSAEJ1850SAEJ1850_ZEROAUTOSARBLUETOOTHMAXIM_DOW "},{"location":"configurations/#crc16","title":"Crc16","text":"CCITTGSMPROFIBUSMODBUSIBM_3740 "},{"location":"configurations/#crc32","title":"Crc32","text":"CRC32AUTOSARBZIP2POSIX "},{"location":"configurations/#crc64","title":"Crc64","text":"CRC64 "},{"location":"contributors/","title":"Contributors","text":"

Thank you to all contributors for your help in improving this project. \ud83d\ude80

"},{"location":"api/abstract_register/","title":"AbstractRegister","text":"

Abstract base class / Interface a crc register needs to implement.

Workflow
  1. The Crc-Register needs to be initialized. 1 time (init)
  2. Data is feed into the crc register. 1..n times (update)
  3. Final result is calculated. 1 time (digest)
"},{"location":"api/abstract_register/#crc.AbstractRegister.digest","title":"digest() abstractmethod","text":"

Final crc checksum will be calculated.

Returns:

Type Description int

Final crc result/value (applies pending operations like final xor).

"},{"location":"api/abstract_register/#crc.AbstractRegister.init","title":"init() abstractmethod","text":"

Initializes the crc register.

"},{"location":"api/abstract_register/#crc.AbstractRegister.reverse","title":"reverse() abstractmethod","text":"

Calculates the reversed value of the crc register.

Returns:

Type Description int

The reversed value of the crc register.

"},{"location":"api/abstract_register/#crc.AbstractRegister.update","title":"update(data) abstractmethod","text":"

Feeds data into the register.

Parameters:

Name Type Description Default data bytes

which will be feed into the register.

required

Returns:

Type Description int

Register content after the update.

"},{"location":"api/basic_register/","title":"BasicRegister","text":"

Bases: AbstractRegister

Implements the common crc algorithm, assuming a user of this base class will provide an overwrite for the _process_byte method.

"},{"location":"api/basic_register/#crc.BasicRegister.__getitem__","title":"__getitem__(index)","text":"

Gets a single byte of the register.

Parameters:

Name Type Description Default index int

byte which shall be returned.

required

Returns:

Type Description int

The byte at the specified index.

Raises:

Type Description IndexError

Invalid index for this register.

"},{"location":"api/basic_register/#crc.BasicRegister.__init__","title":"__init__(configuration)","text":"

Create a new BasicRegister.

Parameters:

Name Type Description Default configuration Configuration

Used to configure the crc algorithm.

required"},{"location":"api/basic_register/#crc.BasicRegister.__len__","title":"__len__()","text":"

Returns:

Type Description int

The width of the register.

"},{"location":"api/basic_register/#crc.BasicRegister.digest","title":"digest()","text":"

See AbstractRegister.digest

"},{"location":"api/basic_register/#crc.BasicRegister.init","title":"init()","text":"

See AbstractRegister.init

"},{"location":"api/basic_register/#crc.BasicRegister.reverse","title":"reverse()","text":"

See AbstractRegister.digest

"},{"location":"api/basic_register/#crc.BasicRegister.update","title":"update(data)","text":"

See AbstractRegister.update

"},{"location":"api/calculator/","title":"Calculator","text":""},{"location":"api/calculator/#crc.InputType","title":"InputType = Union[int, bytes, bytearray, memoryview, BinaryIO, Iterable[Union[bytes, bytearray, memoryview]]] module-attribute","text":"

Type alias for acceptable input types for Calculator.

"},{"location":"api/calculator/#crc.Calculator.__init__","title":"__init__(configuration, optimized=False)","text":"

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.

"},{"location":"api/calculator/#crc.Calculator.checksum","title":"checksum(data)","text":"

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.

"},{"location":"api/calculator/#crc.Calculator.verify","title":"verify(data, expected)","text":"

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.

"},{"location":"api/configuration/","title":"Configuration","text":"

A Configuration provides all settings necessary to determine the concrete implementation of a specific crc algorithm/register.

Example

Create a custom configuration

from crc import Configuration\n\nsaej1850 = Configuration(\n    width=8,\n    polynomial=0x1D,\n    init_value=0xFF,\n    final_xor_value=0xFF,\n    reverse_input=False,\n    reverse_output=False\n)\n
"},{"location":"api/configuration/#crc.Configuration.width","title":"width: int instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.polynomial","title":"polynomial: int instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.init_value","title":"init_value: int = 0 class-attribute instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.final_xor_value","title":"final_xor_value: int = 0 class-attribute instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.reverse_input","title":"reverse_input: bool = False class-attribute instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.reverse_output","title":"reverse_output: bool = False class-attribute instance-attribute","text":""},{"location":"api/crc16/","title":"Crc16","text":""},{"location":"api/crc16/#available-configurations","title":"Available Configurations","text":"

Bases: Enum

"},{"location":"api/crc16/#crc.Crc16.CCITT","title":"CCITT = Configuration(width=16, polynomial=4129, init_value=0, final_xor_value=0, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc16/#crc.Crc16.GSM","title":"GSM = Configuration(width=16, polynomial=4129, init_value=0, final_xor_value=65535, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc16/#crc.Crc16.PROFIBUS","title":"PROFIBUS = Configuration(width=16, polynomial=7631, init_value=65535, final_xor_value=65535, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc32/","title":"Crc32","text":""},{"location":"api/crc32/#available-configurations","title":"Available Configurations","text":"

Bases: Enum

"},{"location":"api/crc32/#crc.Crc32.CRC32","title":"CRC32 = Configuration(width=32, polynomial=79764919, init_value=4294967295, final_xor_value=4294967295, reverse_input=True, reverse_output=True) class-attribute instance-attribute","text":""},{"location":"api/crc32/#crc.Crc32.AUTOSAR","title":"AUTOSAR = Configuration(width=32, polynomial=4104977171, init_value=4294967295, final_xor_value=4294967295, reverse_input=True, reverse_output=True) class-attribute instance-attribute","text":""},{"location":"api/crc32/#crc.Crc32.BZIP2","title":"BZIP2 = Configuration(width=32, polynomial=79764919, init_value=4294967295, final_xor_value=4294967295, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc32/#crc.Crc32.POSIX","title":"POSIX = Configuration(width=32, polynomial=79764919, init_value=0, final_xor_value=4294967295, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc64/","title":"Crc64","text":""},{"location":"api/crc64/#available-configurations","title":"Available Configurations","text":"

Bases: Enum

"},{"location":"api/crc64/#crc.Crc64.CRC64","title":"CRC64 = Configuration(width=64, polynomial=4823603603198064275, init_value=0, final_xor_value=0, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc8/","title":"Crc8","text":""},{"location":"api/crc8/#available-configurations","title":"Available Configurations","text":"

Bases: Enum

"},{"location":"api/crc8/#crc.Crc8.CCITT","title":"CCITT = Configuration(width=8, polynomial=7, init_value=0, final_xor_value=0, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc8/#crc.Crc8.AUTOSAR","title":"AUTOSAR = Configuration(width=8, polynomial=47, init_value=255, final_xor_value=255, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc8/#crc.Crc8.BLUETOOTH","title":"BLUETOOTH = Configuration(width=8, polynomial=167, init_value=0, final_xor_value=0, reverse_input=True, reverse_output=True) class-attribute instance-attribute","text":""},{"location":"api/crc8/#crc.Crc8.SAEJ1850","title":"SAEJ1850 = Configuration(width=8, polynomial=29, init_value=255, final_xor_value=255, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc8/#crc.Crc8.MAXIM_DOW","title":"MAXIM_DOW = Configuration(width=8, polynomial=49, init_value=0, final_xor_value=0, reverse_input=True, reverse_output=True) class-attribute instance-attribute","text":""},{"location":"api/register/","title":"Register","text":"

Bases: BasicRegister

Simple crc register, which will process one bit at the time.

Note

If performance is an important issue for the crc calculation use a table based register.

"},{"location":"api/table_based_register/","title":"TableBasedRegister","text":"

Bases: BasicRegister

Lookup table based crc register.

Info

This register type will be much faster than a simple bit by bit based crc register like Register.

"},{"location":"api/table_based_register/#crc.TableBasedRegister.__init__","title":"__init__(configuration)","text":"

Creates a new table based crc register.

Parameters:

Name Type Description Default configuration Configuration

used for the crc algorithm.

required Attention

Creating a table based register initially might take some extra time, due to the fact that some lookup tables need to be calculated/initialized.

"},{"location":"changelog/changes_2.0.0/","title":"2.0.0 - 2022-11-27","text":""},{"location":"changelog/changes_2.0.0/#breaking-api-changes","title":"\ud83d\udea8 Breaking API Changes","text":"

** Renamed **

Classes:

Functions & Methods:

Arguments:

** Removed **

"},{"location":"changelog/changes_2.0.0/#removed","title":"\ud83d\uddd1 Removed","text":""},{"location":"changelog/changes_2.0.0/#added","title":"\u2728 Added","text":""},{"location":"changelog/changes_2.0.0/#refactorings","title":"\ud83d\udd27 Refactorings","text":""},{"location":"changelog/changes_3.0.0/","title":"3.0.0 - 2022-12-04","text":""},{"location":"changelog/changes_3.0.0/#breaking-api-changes","title":"\ud83d\udea8 Breaking API Changes","text":"

** Renamed **

Functions & Methods:

"},{"location":"changelog/changes_3.0.0/#fixes","title":"\ud83d\udc1b Fixes","text":""},{"location":"changelog/changes_3.0.0/#added","title":"\u2728 Added","text":"

(int, ByteString, BinaryIO, Iterable[ByteString])

"},{"location":"changelog/changes_3.0.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_3.0.1/","title":"3.0.1 - 2022-12-18","text":""},{"location":"changelog/changes_3.0.1/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_3.0.1/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_4.0.0/","title":"4.0.0 - 2022-12-18","text":""},{"location":"changelog/changes_4.0.0/#breaking-changes","title":"\ud83d\udea8 Breaking Changes","text":""},{"location":"changelog/changes_4.0.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_4.0.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_4.1.0/","title":"4.1.0 - 2022-12-18","text":""},{"location":"changelog/changes_4.1.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_4.1.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_4.2.0/","title":"4.2.0 - 2023-04-16","text":""},{"location":"changelog/changes_4.2.0/#features","title":"\u2728 Features","text":""},{"location":"changelog/changes_4.2.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_4.2.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_4.3.0/","title":"4.3.0 - 2023-06-25","text":""},{"location":"changelog/changes_4.3.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_4.3.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_5.0.0/","title":"5.0.0 - 2023-10-08","text":"

\ud83d\ude80 This release is powered by Gert van Dijk, thank you for your contribution!

"},{"location":"changelog/changes_5.0.0/#breaking-changes","title":"\ud83d\udea8 Breaking Changes","text":""},{"location":"changelog/changes_5.0.0/#added","title":"\u2728 Added","text":""},{"location":"changelog/changes_5.0.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_5.0.0/#internal-development","title":"\ud83d\udd29 Internal / Development","text":""},{"location":"changelog/changes_6.0.0/","title":"6.0.0 - 2023-12-02","text":""},{"location":"changelog/changes_6.0.0/#breaking-changes","title":"\ud83d\udea8\ufe0f Breaking Changes","text":""},{"location":"changelog/changes_6.0.0/#bug-fix","title":"\ud83d\udc1e Bug Fix","text":""},{"location":"changelog/changes_6.0.0/#internal-development","title":"\ud83d\udd29 Internal / Development","text":""},{"location":"changelog/changes_6.1.0/","title":"6.1.0 - 2023-12-30","text":"

\ud83d\ude80 This release is powered by Riccardo Malavolti, thank you for your contribution!

"},{"location":"changelog/changes_6.1.0/#features","title":"\u2728 Features","text":""},{"location":"changelog/changes_6.1.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_6.1.1/","title":"6.1.1 - 2024-02-10","text":"

\ud83d\ude80 This release is powered by Ramya-Ab, thank you for your contribution!

"},{"location":"changelog/changes_6.1.1/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_6.1.1/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_6.1.2/","title":"6.1.2 - 2024-04-14","text":""},{"location":"changelog/changes_6.1.2/#bug-fixes","title":"\ud83d\udc1e Bug Fixes","text":""},{"location":"changelog/changes_6.1.2/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_6.1.2/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/unreleased/","title":"Unreleased","text":""},{"location":"changelog/unreleased/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"development/release/","title":"Release","text":""},{"location":"development/release/#create-a-release-using-the-github-release-workflow","title":"Create a release using the GitHub release workflow","text":"
  1. Rename unreleased.md to changes_{X.Y.Z}.md
  2. Update heading in changes_{X.Y.Z}.md to reflect the release version
  3. Add the current date behind the release number
    # X.Y.Z - YYYY-MM-DD\n
  4. Prepare the release
    invoke release.prepare X.Y.Z\n
  5. Run the CI/CD pipeline to publish the release: Execute the release.workflow task and follow potential instructions.
    invoke release.workflow X.Y.Z\n
"},{"location":"development/setup/","title":"Setup","text":""},{"location":"development/setup/#requirements-tldr","title":"Requirements TL;DR","text":""},{"location":"development/setup/#1-install-poetry","title":"1. Install Poetry","text":"

Follow the poetry installation instructions.

"},{"location":"development/setup/#2-install-gh","title":"2. Install gh","text":"

Follow the gh installation instructions.

"},{"location":"development/setup/#3-checkout-the-project","title":"3. Checkout the project","text":"GitHub CLISSHHTTPS
gh repo clone Nicoretti/crc\n
git clone git@github.com:Nicoretti/crc.git\n
git clone https://github.com/Nicoretti/crc.git\n
"},{"location":"development/setup/#4-switch-into-the-directory","title":"4. Switch into the directory","text":"
cd crc\n
"},{"location":"development/setup/#5-the-poetry-environment","title":"5. The Poetry environment","text":"

Make sure the poetry environment is setup properly and all dependencies are installed.

  1. Activate the Poetry shell

    poetry shell\n
  2. Install the project dependencies

    poetry install\n
"},{"location":"development/setup/#run-the-init-task","title":"Run the init task","text":"

In order to bootstrap the remaining parts of the workspace setup, just execute the following command:

invoke init\n

Note

Follow potential instructions.

"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Home","text":"CRC

Calculate CRC checksums, verify CRC checksum, predefined CRC configurations, custom CRC configurations

"},{"location":"#available-crc-configurations","title":"Available CRC Configurations","text":"

The library includes a variety of common CRC configurations for convenience. To explore the full range of available CRC configurations, please checkout the configurations section of the documentation. If you need a new configuration to be readily available, consider submitting a PR or raising an issue.

"},{"location":"#custom-configurations","title":"Custom Configurations","text":"

If you want to create a custom configuration, you should have the following information available:

In case you only have a name of a specific crc configuration/algorithm and you are unsure what are the specific parameters of it, a look into this crc-catalogue might help.

Note

This library currently only supports bit widths of full bytes 8, 16, 24, 32, ...

"},{"location":"#requirements","title":"Requirements","text":""},{"location":"#installation","title":"Installation","text":"
pip install crc\n
"},{"location":"#examples","title":"Examples","text":""},{"location":"#create-a-calculator","title":"Create a Calculator","text":"Pre defined configurationCustom configuration
from crc import Calculator, Crc8\n\ncalculator = Calculator(Crc8.CCITT)\n
from crc import Calculator, Configuration\n\nconfig = Configuration(\n    width=8,\n    poly=0x07,\n    init_value=0x00,\n    final_xor_value=0x00,\n    reverse_input=False,\n    reverse_output=False,\n)\n\ncalculator = Calculator(config)\n
"},{"location":"#calculate-a-checksum","title":"Calculate a checksum","text":"StandardOptimized for speed
from crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT)\n\nassert expected == calculator.checksum(data)\n
from crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert expected == calculator.checksum(data)\n
"},{"location":"#verify-a-checksum","title":"Verify a checksum","text":"StandardOptimized for speed
from crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT)\n\nassert calculator.verify(data, expected)\n
from crc import Calculator, Crc8\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.verify(data, expected)\n
"},{"location":"#supported-data-types","title":"Supported data types","text":"intbytesbytearrayFileByteIoIterable of bytesByte convertibles
from crc import Calculator, Crc8\n\nexpected = 0x20\ndata = 97\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\nexpected = 0xF4\ndata = b\"123456789\"\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\nexpected = 0xF4\ndata = bytearray(b\"123456789\")\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\nexpected = 0xF4\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nwith open(\"afile.txt\", \"rb\") as f:\n    assert calculator.checksum(f) == expected\n
import io\n\nfrom crc import Calculator, Crc8\n\nexpected = 0xF4\ndata = io.ByteIo(b\"123456789\")\ncalculator = Calculator(Crc8.CCITT, optimized=True)\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\nexpected = 0xF4\ncalculator = Calculator(Crc8.CCITT, optimized=True)\ndata = (data for data in [b\"12\", b\"34\", b\"56\", b\"78\", b\"9\"])\n\nassert calculator.checksum(data) == expected\n
from crc import Calculator, Crc8\n\n\nclass ByteConvertible:\n    def __init__(self, data):\n        self._data = data\n\n    def __bytes__(self):\n        return self._data.encode(\"utf-8\")\n\n\nexpected = 0xF4\ncalculator = Calculator(Crc8.CCITT, optimized=True)\ndata = ByteConvertible(\"123456789\")\n\nassert calculator.checksum(bytes(data)) == expected\n
"},{"location":"#calculate-a-checksum-with-raw-registers","title":"Calculate a checksum with raw registers","text":"RegisterTableBasedRegister
from crc import Crc8, Register\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\nregister = Register(Crc8.CCITT)\n\nregister.init()\nregister.update(data)\nassert expected == register.digest()\n
from crc import Crc8, TableBasedRegister\n\nexpected = 0xBC\ndata = bytes([0, 1, 2, 3, 4, 5])\nregister = TableBasedRegister(Crc8.CCITT)\n\nregister.init()\nregister.update(data)\nassert expected == register.digest()\n
"},{"location":"#references-resources","title":"References & Resources","text":""},{"location":"cli/","title":"CLI Tools","text":"

The crc library comes with a small command line tool which can generate crc lookup tables if needed.

usage: crc table [-h] <width> <polynomial>\n\npositional arguments:\n  <width>       width of the crc algorithm, common width's are 8, 16, 32, 64\n  <polynomial>  hex value of the polynomial used for calculating the crc table\n\noptional arguments:\n  -h, --help    show this help message and exit\n

Example Usage:

user@host ~$ crc table 8 0x7D\n
"},{"location":"configurations/","title":"Configurations","text":""},{"location":"configurations/#crc8","title":"Crc8","text":"CCITTSAEJ1850SAEJ1850_ZEROAUTOSARBLUETOOTHMAXIM_DOW "},{"location":"configurations/#crc16","title":"Crc16","text":"CCITTGSMPROFIBUSMODBUSIBM_3740 "},{"location":"configurations/#crc32","title":"Crc32","text":"CRC32AUTOSARBZIP2POSIX "},{"location":"configurations/#crc64","title":"Crc64","text":"CRC64 "},{"location":"contributors/","title":"Contributors","text":"

Thank you to all contributors for your help in improving this project. \ud83d\ude80

"},{"location":"api/abstract_register/","title":"AbstractRegister","text":"

Abstract base class / Interface a crc register needs to implement.

Workflow
  1. The Crc-Register needs to be initialized. 1 time (init)
  2. Data is feed into the crc register. 1..n times (update)
  3. Final result is calculated. 1 time (digest)
"},{"location":"api/abstract_register/#crc.AbstractRegister.digest","title":"digest() abstractmethod","text":"

Final crc checksum will be calculated.

Returns:

Type Description int

Final crc result/value (applies pending operations like final xor).

"},{"location":"api/abstract_register/#crc.AbstractRegister.init","title":"init() abstractmethod","text":"

Initializes the crc register.

"},{"location":"api/abstract_register/#crc.AbstractRegister.reverse","title":"reverse() abstractmethod","text":"

Calculates the reversed value of the crc register.

Returns:

Type Description int

The reversed value of the crc register.

"},{"location":"api/abstract_register/#crc.AbstractRegister.update","title":"update(data) abstractmethod","text":"

Feeds data into the register.

Parameters:

Name Type Description Default data bytes

which will be feed into the register.

required

Returns:

Type Description int

Register content after the update.

"},{"location":"api/basic_register/","title":"BasicRegister","text":"

Bases: AbstractRegister

Implements the common crc algorithm, assuming a user of this base class will provide an overwrite for the _process_byte method.

"},{"location":"api/basic_register/#crc.BasicRegister.__getitem__","title":"__getitem__(index)","text":"

Gets a single byte of the register.

Parameters:

Name Type Description Default index int

byte which shall be returned.

required

Returns:

Type Description int

The byte at the specified index.

Raises:

Type Description IndexError

Invalid index for this register.

"},{"location":"api/basic_register/#crc.BasicRegister.__init__","title":"__init__(configuration)","text":"

Create a new BasicRegister.

Parameters:

Name Type Description Default configuration Configuration

Used to configure the crc algorithm.

required"},{"location":"api/basic_register/#crc.BasicRegister.__len__","title":"__len__()","text":"

Returns:

Type Description int

The width of the register.

"},{"location":"api/basic_register/#crc.BasicRegister.digest","title":"digest()","text":"

See AbstractRegister.digest

"},{"location":"api/basic_register/#crc.BasicRegister.init","title":"init()","text":"

See AbstractRegister.init

"},{"location":"api/basic_register/#crc.BasicRegister.reverse","title":"reverse()","text":"

See AbstractRegister.digest

"},{"location":"api/basic_register/#crc.BasicRegister.update","title":"update(data)","text":"

See AbstractRegister.update

"},{"location":"api/calculator/","title":"Calculator","text":""},{"location":"api/calculator/#crc.InputType","title":"InputType = Union[int, bytes, bytearray, memoryview, BinaryIO, Iterable[Union[bytes, bytearray, memoryview]]] module-attribute","text":"

Type alias for acceptable input types for Calculator.

"},{"location":"api/calculator/#crc.Calculator.__init__","title":"__init__(configuration, optimized=False)","text":"

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.

"},{"location":"api/calculator/#crc.Calculator.checksum","title":"checksum(data)","text":"

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.

"},{"location":"api/calculator/#crc.Calculator.verify","title":"verify(data, expected)","text":"

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.

"},{"location":"api/configuration/","title":"Configuration","text":"

A Configuration provides all settings necessary to determine the concrete implementation of a specific crc algorithm/register.

Example

Create a custom configuration

from crc import Configuration\n\nsaej1850 = Configuration(\n    width=8,\n    polynomial=0x1D,\n    init_value=0xFF,\n    final_xor_value=0xFF,\n    reverse_input=False,\n    reverse_output=False\n)\n
"},{"location":"api/configuration/#crc.Configuration.width","title":"width: int instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.polynomial","title":"polynomial: int instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.init_value","title":"init_value: int = 0 class-attribute instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.final_xor_value","title":"final_xor_value: int = 0 class-attribute instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.reverse_input","title":"reverse_input: bool = False class-attribute instance-attribute","text":""},{"location":"api/configuration/#crc.Configuration.reverse_output","title":"reverse_output: bool = False class-attribute instance-attribute","text":""},{"location":"api/crc16/","title":"Crc16","text":""},{"location":"api/crc16/#available-configurations","title":"Available Configurations","text":"

Bases: Enum

"},{"location":"api/crc16/#crc.Crc16.CCITT","title":"CCITT = Configuration(width=16, polynomial=4129, init_value=0, final_xor_value=0, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc16/#crc.Crc16.GSM","title":"GSM = Configuration(width=16, polynomial=4129, init_value=0, final_xor_value=65535, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc16/#crc.Crc16.PROFIBUS","title":"PROFIBUS = Configuration(width=16, polynomial=7631, init_value=65535, final_xor_value=65535, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc32/","title":"Crc32","text":""},{"location":"api/crc32/#available-configurations","title":"Available Configurations","text":"

Bases: Enum

"},{"location":"api/crc32/#crc.Crc32.CRC32","title":"CRC32 = Configuration(width=32, polynomial=79764919, init_value=4294967295, final_xor_value=4294967295, reverse_input=True, reverse_output=True) class-attribute instance-attribute","text":""},{"location":"api/crc32/#crc.Crc32.AUTOSAR","title":"AUTOSAR = Configuration(width=32, polynomial=4104977171, init_value=4294967295, final_xor_value=4294967295, reverse_input=True, reverse_output=True) class-attribute instance-attribute","text":""},{"location":"api/crc32/#crc.Crc32.BZIP2","title":"BZIP2 = Configuration(width=32, polynomial=79764919, init_value=4294967295, final_xor_value=4294967295, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc32/#crc.Crc32.POSIX","title":"POSIX = Configuration(width=32, polynomial=79764919, init_value=0, final_xor_value=4294967295, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc64/","title":"Crc64","text":""},{"location":"api/crc64/#available-configurations","title":"Available Configurations","text":"

Bases: Enum

"},{"location":"api/crc64/#crc.Crc64.CRC64","title":"CRC64 = Configuration(width=64, polynomial=4823603603198064275, init_value=0, final_xor_value=0, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc8/","title":"Crc8","text":""},{"location":"api/crc8/#available-configurations","title":"Available Configurations","text":"

Bases: Enum

"},{"location":"api/crc8/#crc.Crc8.CCITT","title":"CCITT = Configuration(width=8, polynomial=7, init_value=0, final_xor_value=0, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc8/#crc.Crc8.AUTOSAR","title":"AUTOSAR = Configuration(width=8, polynomial=47, init_value=255, final_xor_value=255, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc8/#crc.Crc8.BLUETOOTH","title":"BLUETOOTH = Configuration(width=8, polynomial=167, init_value=0, final_xor_value=0, reverse_input=True, reverse_output=True) class-attribute instance-attribute","text":""},{"location":"api/crc8/#crc.Crc8.SAEJ1850","title":"SAEJ1850 = Configuration(width=8, polynomial=29, init_value=255, final_xor_value=255, reverse_input=False, reverse_output=False) class-attribute instance-attribute","text":""},{"location":"api/crc8/#crc.Crc8.MAXIM_DOW","title":"MAXIM_DOW = Configuration(width=8, polynomial=49, init_value=0, final_xor_value=0, reverse_input=True, reverse_output=True) class-attribute instance-attribute","text":""},{"location":"api/register/","title":"Register","text":"

Bases: BasicRegister

Simple crc register, which will process one bit at the time.

Note

If performance is an important issue for the crc calculation use a table based register.

"},{"location":"api/table_based_register/","title":"TableBasedRegister","text":"

Bases: BasicRegister

Lookup table based crc register.

Info

This register type will be much faster than a simple bit by bit based crc register like Register.

"},{"location":"api/table_based_register/#crc.TableBasedRegister.__init__","title":"__init__(configuration)","text":"

Creates a new table based crc register.

Parameters:

Name Type Description Default configuration Configuration

used for the crc algorithm.

required Attention

Creating a table based register initially might take some extra time, due to the fact that some lookup tables need to be calculated/initialized.

"},{"location":"changelog/changes_2.0.0/","title":"2.0.0 - 2022-11-27","text":""},{"location":"changelog/changes_2.0.0/#breaking-api-changes","title":"\ud83d\udea8 Breaking API Changes","text":"

** Renamed **

Classes:

Functions & Methods:

Arguments:

** Removed **

"},{"location":"changelog/changes_2.0.0/#removed","title":"\ud83d\uddd1 Removed","text":""},{"location":"changelog/changes_2.0.0/#added","title":"\u2728 Added","text":""},{"location":"changelog/changes_2.0.0/#refactorings","title":"\ud83d\udd27 Refactorings","text":""},{"location":"changelog/changes_3.0.0/","title":"3.0.0 - 2022-12-04","text":""},{"location":"changelog/changes_3.0.0/#breaking-api-changes","title":"\ud83d\udea8 Breaking API Changes","text":"

** Renamed **

Functions & Methods:

"},{"location":"changelog/changes_3.0.0/#fixes","title":"\ud83d\udc1b Fixes","text":""},{"location":"changelog/changes_3.0.0/#added","title":"\u2728 Added","text":"

(int, ByteString, BinaryIO, Iterable[ByteString])

"},{"location":"changelog/changes_3.0.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_3.0.1/","title":"3.0.1 - 2022-12-18","text":""},{"location":"changelog/changes_3.0.1/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_3.0.1/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_4.0.0/","title":"4.0.0 - 2022-12-18","text":""},{"location":"changelog/changes_4.0.0/#breaking-changes","title":"\ud83d\udea8 Breaking Changes","text":""},{"location":"changelog/changes_4.0.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_4.0.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_4.1.0/","title":"4.1.0 - 2022-12-18","text":""},{"location":"changelog/changes_4.1.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_4.1.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_4.2.0/","title":"4.2.0 - 2023-04-16","text":""},{"location":"changelog/changes_4.2.0/#features","title":"\u2728 Features","text":""},{"location":"changelog/changes_4.2.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_4.2.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_4.3.0/","title":"4.3.0 - 2023-06-25","text":""},{"location":"changelog/changes_4.3.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_4.3.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_5.0.0/","title":"5.0.0 - 2023-10-08","text":"

\ud83d\ude80 This release is powered by Gert van Dijk, thank you for your contribution!

"},{"location":"changelog/changes_5.0.0/#breaking-changes","title":"\ud83d\udea8 Breaking Changes","text":""},{"location":"changelog/changes_5.0.0/#added","title":"\u2728 Added","text":""},{"location":"changelog/changes_5.0.0/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_5.0.0/#internal-development","title":"\ud83d\udd29 Internal / Development","text":""},{"location":"changelog/changes_6.0.0/","title":"6.0.0 - 2023-12-02","text":""},{"location":"changelog/changes_6.0.0/#breaking-changes","title":"\ud83d\udea8\ufe0f Breaking Changes","text":""},{"location":"changelog/changes_6.0.0/#bug-fix","title":"\ud83d\udc1e Bug Fix","text":""},{"location":"changelog/changes_6.0.0/#internal-development","title":"\ud83d\udd29 Internal / Development","text":""},{"location":"changelog/changes_6.1.0/","title":"6.1.0 - 2023-12-30","text":"

\ud83d\ude80 This release is powered by Riccardo Malavolti, thank you for your contribution!

"},{"location":"changelog/changes_6.1.0/#features","title":"\u2728 Features","text":""},{"location":"changelog/changes_6.1.0/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_6.1.1/","title":"6.1.1 - 2024-02-10","text":"

\ud83d\ude80 This release is powered by Ramya-Ab, thank you for your contribution!

"},{"location":"changelog/changes_6.1.1/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_6.1.1/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/changes_6.1.2/","title":"6.1.2 - 2024-04-14","text":""},{"location":"changelog/changes_6.1.2/#bug-fixes","title":"\ud83d\udc1e Bug Fixes","text":""},{"location":"changelog/changes_6.1.2/#documentation","title":"\ud83d\udcda Documentation","text":""},{"location":"changelog/changes_6.1.2/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"changelog/unreleased/","title":"Unreleased","text":""},{"location":"changelog/unreleased/#internal","title":"\ud83d\udd29 Internal","text":""},{"location":"development/release/","title":"Release","text":""},{"location":"development/release/#create-a-release-using-the-github-release-workflow","title":"Create a release using the GitHub release workflow","text":"
  1. Rename unreleased.md to changes_{X.Y.Z}.md
  2. Update heading in changes_{X.Y.Z}.md to reflect the release version
  3. Add the current date behind the release number
    # X.Y.Z - YYYY-MM-DD\n
  4. Prepare the release
    invoke release.prepare X.Y.Z\n
  5. Run the CI/CD pipeline to publish the release: Execute the release.workflow task and follow potential instructions.
    invoke release.workflow X.Y.Z\n
"},{"location":"development/setup/","title":"Setup","text":""},{"location":"development/setup/#requirements-tldr","title":"Requirements TL;DR","text":""},{"location":"development/setup/#1-install-poetry","title":"1. Install Poetry","text":"

Follow the poetry installation instructions.

"},{"location":"development/setup/#2-install-gh","title":"2. Install gh","text":"

Follow the gh installation instructions.

"},{"location":"development/setup/#3-checkout-the-project","title":"3. Checkout the project","text":"GitHub CLISSHHTTPS
gh repo clone Nicoretti/crc\n
git clone git@github.com:Nicoretti/crc.git\n
git clone https://github.com/Nicoretti/crc.git\n
"},{"location":"development/setup/#4-switch-into-the-directory","title":"4. Switch into the directory","text":"
cd crc\n
"},{"location":"development/setup/#5-the-poetry-environment","title":"5. The Poetry environment","text":"

Make sure the poetry environment is setup properly and all dependencies are installed.

  1. Activate the Poetry shell

    poetry shell\n
  2. Install the project dependencies

    poetry install\n
"},{"location":"development/setup/#run-the-init-task","title":"Run the init task","text":"

In order to bootstrap the remaining parts of the workspace setup, just execute the following command:

invoke init\n

Note

Follow potential instructions.

"}]} \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index d2e40e84d9495f4e2b48bc4732ad76ff5a69c69a..1b7a4169c5e1884cccc56d892605cbf1db839f13 100644 GIT binary patch delta 15 Wcmeyz^pA;6zMF%Cd&x$&3Pu1b8w8*L delta 15 Wcmeyz^pA;6zMF&N_ri^A6^sBctObn#