├── .eslintignore ├── .gitignore ├── tests ├── dependencies │ ├── esbuild │ │ ├── .gitignore │ │ ├── package.json │ │ ├── index-import.js │ │ ├── test │ │ ├── index-require.js │ │ └── package-lock.json │ ├── rollup │ │ ├── .gitignore │ │ ├── test │ │ ├── index.js │ │ ├── rollup.config.js │ │ ├── package.json │ │ └── package-lock.json │ ├── webpack-5-cjs │ │ ├── .gitignore │ │ ├── with-buffer.js │ │ ├── with-array.js │ │ ├── package.json │ │ ├── webpack.config.js │ │ └── test │ ├── node-cjs │ │ ├── test │ │ ├── package.json │ │ ├── main.js │ │ ├── package-lock.json │ │ ├── individual.js │ │ └── calculators.js │ ├── node-esm │ │ ├── test │ │ ├── package.json │ │ ├── default.js │ │ ├── package-lock.json │ │ ├── individual.js │ │ └── calculators.js │ ├── typescript-4.5.4-cjs │ │ ├── test │ │ ├── package.json │ │ ├── tsconfig.json │ │ ├── default.ts │ │ ├── individual.ts │ │ ├── calculators.ts │ │ └── package-lock.json │ ├── typescript-4.5.4-esm │ │ ├── test │ │ ├── package.json │ │ ├── tsconfig.json │ │ ├── default.ts │ │ ├── individual.ts │ │ ├── calculators.ts │ │ └── package-lock.json │ └── test ├── .gitignore ├── .mocharc-multicoin-address-validator.js ├── .eslintrc.js ├── pycrc │ ├── .gitignore │ ├── doc │ │ └── Makefile │ ├── COPYING │ ├── test │ │ ├── check_files.sh │ │ ├── performance.sh │ │ └── main.c │ ├── README.md │ ├── crc_algorithms.py │ ├── pycrc.py │ ├── crc_lexer.py │ ├── crc_models.py │ └── crc_parser.py ├── crc8.test.ts ├── crc24.test.ts ├── crc32.test.ts ├── crcjam.test.ts ├── crc16ccitt.test.ts ├── crc81wire.test.ts ├── crc16kermit.test.ts ├── crc16modbus.test.ts ├── crc16xmodem.test.ts ├── crc32mpeg2.test.ts ├── crc1.test.ts ├── crc8dvbs2.test.ts ├── tsconfig.json ├── crc16.test.ts └── test_helpers.ts ├── dist ├── cjs-default-unwrap │ ├── package.json │ ├── crc1.js │ ├── crc16.js │ ├── crc24.js │ ├── crc32.js │ ├── crc8.js │ ├── crcjam.js │ ├── crc16ccitt.js │ ├── crc32mpeg2.js │ ├── crc81wire.js │ ├── crc16kermit.js │ ├── crc16modbus.js │ ├── crc16xmodem.js │ ├── calculators │ │ ├── crc1.js │ │ ├── crc8.js │ │ ├── crc16.js │ │ ├── crc24.js │ │ ├── crc32.js │ │ ├── crcjam.js │ │ ├── crc81wire.js │ │ ├── crc16ccitt.js │ │ ├── crc16kermit.js │ │ ├── crc16modbus.js │ │ ├── crc16xmodem.js │ │ └── crc32mpeg2.js │ └── index.js ├── .gitignore └── package.json ├── src ├── crc1.ts ├── crc8.ts ├── crc16.ts ├── crc24.ts ├── crc32.ts ├── crcjam.ts ├── crc16ccitt.ts ├── crc8dvbs2.ts ├── crc16kermit.ts ├── crc16xmodem.ts ├── crc32mpeg2.ts ├── crc81wire.ts ├── crc16modbus.ts ├── create_buffer.ts ├── calculators │ ├── crc1.ts │ ├── crc16xmodem.ts │ ├── crc8.ts │ ├── crc81wire.ts │ ├── crc8dvbs2.ts │ ├── crc16.ts │ ├── crc16ccitt.ts │ ├── crc16kermit.ts │ ├── crc16modbus.ts │ ├── crc24.ts │ ├── crcjam.ts │ ├── crc32mpeg2.ts │ └── crc32.ts ├── types.ts ├── define_crc.ts └── index.ts ├── scripts ├── test-crc ├── benchmark ├── test ├── benchmarks │ ├── crc32-100b.js │ ├── crc32-1kb.js │ ├── crc32-1mb.js │ ├── crc32-5kb.js │ ├── crc32-100kb.js │ └── benchmark.js ├── build └── test-multicoin-address-validator ├── tsconfig-declarations.json ├── tsconfig-mjs.json ├── tsconfig-cjs.json ├── tsconfig-tests.json ├── .mocharc.js ├── .vscode └── settings.json ├── .prettierrc.js ├── tsconfig.json ├── .eslintrc.js ├── LICENSE ├── package.json └── README.md /.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.tsbuildinfo 3 | -------------------------------------------------------------------------------- /tests/dependencies/esbuild/.gitignore: -------------------------------------------------------------------------------- 1 | output 2 | -------------------------------------------------------------------------------- /tests/dependencies/rollup/.gitignore: -------------------------------------------------------------------------------- 1 | output 2 | -------------------------------------------------------------------------------- /tests/.gitignore: -------------------------------------------------------------------------------- 1 | multicoin-address-validator 2 | .build -------------------------------------------------------------------------------- /tests/dependencies/webpack-5-cjs/.gitignore: -------------------------------------------------------------------------------- 1 | output 2 | -------------------------------------------------------------------------------- /tests/.mocharc-multicoin-address-validator.js: -------------------------------------------------------------------------------- 1 | module.exports = {}; 2 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } 4 | -------------------------------------------------------------------------------- /tests/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { 3 | mocha: true, 4 | }, 5 | }; 6 | -------------------------------------------------------------------------------- /dist/.gitignore: -------------------------------------------------------------------------------- 1 | cjs 2 | mjs 3 | *.d.ts 4 | LICENSE 5 | README.md 6 | *.tgz 7 | package-lock.json 8 | -------------------------------------------------------------------------------- /tests/dependencies/node-cjs/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | node main.js 4 | node individual.js 5 | node calculators.js 6 | -------------------------------------------------------------------------------- /tests/dependencies/node-esm/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | node default.js 4 | node individual.js 5 | node calculators.js 6 | -------------------------------------------------------------------------------- /tests/pycrc/.gitignore: -------------------------------------------------------------------------------- 1 | .svn 2 | .*.swp 3 | *.pyc 4 | *.pyo 5 | __pycache__ 6 | doc/pycrc.1 7 | doc/pycrc.html 8 | test/pycrc_files.tar.gz 9 | -------------------------------------------------------------------------------- /tests/dependencies/rollup/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | if npm exec -c 'rollup -c' | grep -q 'Unresolved dependencies'; then 4 | exit 1 5 | fi 6 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc1.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc1').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc16.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc16').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc24.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc24').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc32.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc32').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc8.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc8').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /src/crc1.ts: -------------------------------------------------------------------------------- 1 | import crc1 from './calculators/crc1.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('crc1', crc1); 5 | -------------------------------------------------------------------------------- /src/crc8.ts: -------------------------------------------------------------------------------- 1 | import crc8 from './calculators/crc8.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('crc-8', crc8); 5 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crcjam.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crcjam').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /src/crc16.ts: -------------------------------------------------------------------------------- 1 | import crc16 from './calculators/crc16.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('crc-16', crc16); 5 | -------------------------------------------------------------------------------- /src/crc24.ts: -------------------------------------------------------------------------------- 1 | import crc24 from './calculators/crc24.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('crc-24', crc24); 5 | -------------------------------------------------------------------------------- /src/crc32.ts: -------------------------------------------------------------------------------- 1 | import crc32 from './calculators/crc32.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('crc-32', crc32); 5 | -------------------------------------------------------------------------------- /src/crcjam.ts: -------------------------------------------------------------------------------- 1 | import crcjam from './calculators/crcjam.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('jam', crcjam); 5 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc16ccitt.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc16ccitt').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc32mpeg2.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc32mpeg2').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc81wire.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc81wire').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc16kermit.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc16kermit').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc16modbus.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc16modbus').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/crc16xmodem.js: -------------------------------------------------------------------------------- 1 | const results = require('../cjs/crc16xmodem').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /scripts/test-crc: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | npm exec tsc -- -p tsconfig-tests.json 4 | 5 | TS_NODE_PROJECT=./tests/tsconfig.json \ 6 | $(npm bin)/mocha tests/*.test.ts 7 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-cjs/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | npm exec tsc 4 | node .build/individual.js 5 | node .build/calculators.js 6 | node .build/default.js 7 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-esm/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | npm exec tsc 4 | node .build/individual.js 5 | node .build/calculators.js 6 | node .build/default.js 7 | -------------------------------------------------------------------------------- /tsconfig-declarations.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "emitDeclarationOnly": true, 5 | "outDir": "dist" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc1.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc1').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc8.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc8').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /src/crc16ccitt.ts: -------------------------------------------------------------------------------- 1 | import crc16ccitt from './calculators/crc16ccitt.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('ccitt', crc16ccitt); 5 | -------------------------------------------------------------------------------- /src/crc8dvbs2.ts: -------------------------------------------------------------------------------- 1 | import crc8dvbs2 from './calculators/crc8dvbs2.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('crc-8-dvbs2', crc8dvbs2); 5 | -------------------------------------------------------------------------------- /tests/crc8.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc8 from './.build/crc8'; 3 | 4 | describe('CRC8', () => { 5 | crcSuiteFor({ crc: crc8 }); 6 | }); 7 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc16.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc16').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc24.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc24').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc32.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc32').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crcjam.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crcjam').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /src/crc16kermit.ts: -------------------------------------------------------------------------------- 1 | import crc16kermit from './calculators/crc16kermit.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('kermit', crc16kermit); 5 | -------------------------------------------------------------------------------- /src/crc16xmodem.ts: -------------------------------------------------------------------------------- 1 | import crc16xmodem from './calculators/crc16xmodem.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('xmodem', crc16xmodem); 5 | -------------------------------------------------------------------------------- /src/crc32mpeg2.ts: -------------------------------------------------------------------------------- 1 | import crc32mpeg2 from './calculators/crc32mpeg2.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('crc-32-mpeg', crc32mpeg2); 5 | -------------------------------------------------------------------------------- /src/crc81wire.ts: -------------------------------------------------------------------------------- 1 | import crc81wire from './calculators/crc81wire.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('dallas-1-wire', crc81wire); 5 | -------------------------------------------------------------------------------- /tests/crc24.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc24 from './.build/crc24'; 3 | 4 | describe('CRC24', () => { 5 | crcSuiteFor({ crc: crc24 }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests/crc32.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc32 from './.build/crc32'; 3 | 4 | describe('CRC32', () => { 5 | crcSuiteFor({ crc: crc32 }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests/dependencies/node-cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "license": "ISC", 5 | "scripts": { 6 | "test": "./test" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /tsconfig-mjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "es6", 5 | "target": "es6", 6 | "outDir": "dist/mjs" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc81wire.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc81wire').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /src/crc16modbus.ts: -------------------------------------------------------------------------------- 1 | import crc16modbus from './calculators/crc16modbus.js'; 2 | import defineCrc from './define_crc.js'; 3 | 4 | export default defineCrc('crc-16-modbus', crc16modbus); 5 | -------------------------------------------------------------------------------- /tests/crcjam.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crcjam from './.build/crcjam'; 3 | 4 | describe('CRCJAM', () => { 5 | crcSuiteFor({ crc: crcjam }); 6 | }); 7 | -------------------------------------------------------------------------------- /tsconfig-cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "outDir": "dist/cjs", 6 | "target": "es2015" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc16ccitt.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc16ccitt').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc16kermit.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc16kermit').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc16modbus.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc16modbus').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc16xmodem.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc16xmodem').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/calculators/crc32mpeg2.js: -------------------------------------------------------------------------------- 1 | const results = require('../../cjs/calculators/crc32mpeg2').default; 2 | module.exports = results; 3 | module.exports.default = results; 4 | -------------------------------------------------------------------------------- /tsconfig-tests.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "outDir": "./tests/.build", 6 | "target": "es2015" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /scripts/benchmark: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd ./scripts/benchmarks 4 | 5 | node ./crc32-100b.js 6 | node ./crc32-1kb.js 7 | node ./crc32-5kb.js 8 | node ./crc32-100kb.js 9 | node ./crc32-1mb.js 10 | -------------------------------------------------------------------------------- /tests/crc16ccitt.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc16ccitt from './.build/crc16ccitt'; 3 | 4 | describe('CRC16CCITT', () => { 5 | crcSuiteFor({ crc: crc16ccitt }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests/crc81wire.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc81wire from './.build/crc81wire'; 3 | 4 | describe('CRC8 1 Wire', () => { 5 | crcSuiteFor({ crc: crc81wire }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests/crc16kermit.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc16kermit from './.build/crc16kermit'; 3 | 4 | describe('CRC16KERMIT', () => { 5 | crcSuiteFor({ crc: crc16kermit }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests/crc16modbus.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc16modbus from './.build/crc16modbus'; 3 | 4 | describe('CRC16Modbus', () => { 5 | crcSuiteFor({ crc: crc16modbus }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests/crc16xmodem.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc16xmodem from './.build/crc16xmodem'; 3 | 4 | describe('CRC16XModem', () => { 5 | crcSuiteFor({ crc: crc16xmodem }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests/crc32mpeg2.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc32mpeg2 from './.build/crc32mpeg2'; 3 | 4 | describe('CRC32 MPEG-2', () => { 5 | crcSuiteFor({ crc: crc32mpeg2 }); 6 | }); 7 | -------------------------------------------------------------------------------- /.mocharc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parallel: true, 3 | recursive: true, 4 | reporter: 'spec', 5 | require: 'ts-node/register', 6 | slow: '100', 7 | timeout: '2000', 8 | ui: 'bdd', 9 | }; 10 | -------------------------------------------------------------------------------- /scripts/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | npm run build 4 | 5 | ( 6 | cd dist 7 | npm pack 8 | ) 9 | 10 | ./scripts/test-crc 11 | ./scripts/test-multicoin-address-validator 12 | ./tests/dependencies/test 13 | -------------------------------------------------------------------------------- /tests/dependencies/node-esm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "license": "ISC", 5 | "type": "module", 6 | "scripts": { 7 | "test": "./test" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /tests/dependencies/webpack-5-cjs/with-buffer.js: -------------------------------------------------------------------------------- 1 | import crc32 from 'crc/crc32'; 2 | import crc from 'crc'; 3 | 4 | // eslint-disable-next-line no-console 5 | console.log(crc32('hello world'), crc.crc32('hello world')); 6 | -------------------------------------------------------------------------------- /tests/crc1.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc1 from './.build/crc1'; 3 | 4 | describe('CRC1', () => { 5 | crcSuiteFor({ 6 | crc: crc1, 7 | value: '1234567890', 8 | expected: 'd', 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /tests/dependencies/esbuild/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "license": "ISC", 5 | "scripts": { 6 | "test": "./test" 7 | }, 8 | "dependencies": { 9 | "esbuild": "^0.14.27" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/crc8dvbs2.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc8dvbs2 from './.build/crc8dvbs2'; 3 | 4 | describe('CRC8 DVB-S2', () => { 5 | crcSuiteFor({ crc: crc8dvbs2, value: Buffer.from('45A2DFF1', 'hex'), expected: 'f6' }); 6 | }); 7 | -------------------------------------------------------------------------------- /tests/dependencies/rollup/index.js: -------------------------------------------------------------------------------- 1 | import crc32 from 'crc/calculators/crc32'; 2 | 3 | const helloWorld = new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]); 4 | 5 | // eslint-disable-next-line no-console 6 | console.log(crc32(helloWorld)); 7 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "license": "ISC", 5 | "dependencies": { 6 | "typescript": "4.5.4" 7 | }, 8 | "scripts": { 9 | "test": "./test" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/dependencies/esbuild/index-import.js: -------------------------------------------------------------------------------- 1 | import crc32 from 'crc/calculators/crc32'; 2 | 3 | const helloWorld = new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]); 4 | 5 | // eslint-disable-next-line no-console 6 | console.log(crc32(helloWorld)); 7 | -------------------------------------------------------------------------------- /tests/dependencies/esbuild/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | npm exec -c 'esbuild --bundle index-import.js --outdir=output --minify=false --sourcemap' 4 | npm exec -c "esbuild --bundle index-require.js --outdir=output --minify=false --sourcemap --platform=node --format=cjs" 5 | -------------------------------------------------------------------------------- /tests/dependencies/webpack-5-cjs/with-array.js: -------------------------------------------------------------------------------- 1 | import crc32 from 'crc/calculators/crc32'; 2 | 3 | const helloWorld = new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]); 4 | 5 | // eslint-disable-next-line no-console 6 | console.log(crc32(helloWorld)); 7 | -------------------------------------------------------------------------------- /tests/dependencies/esbuild/index-require.js: -------------------------------------------------------------------------------- 1 | const crc32 = require('crc/calculators/crc32'); 2 | 3 | const helloWorld = new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]); 4 | 5 | // eslint-disable-next-line no-console 6 | console.log(crc32(helloWorld)); 7 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-esm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "type": "module", 5 | "license": "ISC", 6 | "dependencies": { 7 | "typescript": "4.5.4" 8 | }, 9 | "scripts": { 10 | "test": "./test" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/dependencies/webpack-5-cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-webpack-test", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "webpack": "^5", 7 | "webpack-cli": "^4.9.1" 8 | }, 9 | "scripts": { 10 | "test": "./test" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tests/dependencies/rollup/rollup.config.js: -------------------------------------------------------------------------------- 1 | import { nodeResolve } from '@rollup/plugin-node-resolve'; 2 | import commonjs from '@rollup/plugin-commonjs'; 3 | 4 | export default { 5 | input: './index.js', 6 | output: { 7 | dir: 'output', 8 | format: 'cjs', 9 | }, 10 | plugins: [nodeResolve(), commonjs()], 11 | }; 12 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "eslint.format.enable": true, 4 | "[typescript]": { 5 | "editor.defaultFormatter": "esbenp.prettier-vscode" 6 | }, 7 | "[json]": { 8 | "editor.defaultFormatter": "dbaeumer.vscode-eslint" 9 | }, 10 | "typescript.tsdk": "node_modules/typescript/lib" 11 | } 12 | -------------------------------------------------------------------------------- /tests/dependencies/rollup/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "license": "ISC", 5 | "scripts": { 6 | "test": "./test" 7 | }, 8 | "dependencies": { 9 | "@rollup/plugin-commonjs": "^21.0.2", 10 | "@rollup/plugin-node-resolve": "^13.1.3", 11 | "rollup": "^2.70.1" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/dependencies/webpack-5-cjs/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entry: { 3 | 'with-array': `${__dirname}/with-array.js`, 4 | 'with-buffer': `${__dirname}/with-buffer.js`, 5 | }, 6 | output: { 7 | path: __dirname, 8 | filename: 'output/[name].js', 9 | }, 10 | mode: 'development', 11 | target: 'web', 12 | }; 13 | -------------------------------------------------------------------------------- /tests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "esModuleInterop": true, 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "lib": ["ESNext", "DOM"], 7 | "noImplicitAny": true, 8 | "skipLibCheck": true, 9 | "strict": true, 10 | "strictNullChecks": true 11 | }, 12 | "exclude": ["node_modules"] 13 | } 14 | -------------------------------------------------------------------------------- /src/create_buffer.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ 2 | /* eslint-disable no-prototype-builtins */ 3 | import { Buffer } from 'buffer'; 4 | import { BufferInput } from './types.js'; 5 | 6 | const createBuffer = (value: BufferInput, encoding?: BufferEncoding) => 7 | Buffer.from(value as any, encoding); 8 | 9 | export default createBuffer; 10 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-cjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "baseUrl": "./", 5 | "lib": ["es2020", "dom"], 6 | "module": "CommonJS", 7 | "moduleResolution": "node", 8 | "outDir": "./.build", 9 | "resolveJsonModule": true, 10 | "strict": true, 11 | "target": "ES5" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: 'typescript', 3 | printWidth: 100, 4 | singleQuote: true, 5 | trailingComma: 'all', 6 | arrowParens: 'avoid', 7 | overrides: [ 8 | { 9 | files: ['.*', '*.json'], 10 | options: { parser: 'json' }, 11 | }, 12 | { 13 | files: ['*.js'], 14 | options: { parser: 'typescript' }, 15 | }, 16 | ], 17 | }; 18 | -------------------------------------------------------------------------------- /src/calculators/crc1.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | const crc1: CRCCalculator = (current, previous = 0) => { 4 | let crc = ~~previous; 5 | let accum = 0; 6 | 7 | for (let index = 0; index < current.length; index++) { 8 | accum += current[index]; 9 | } 10 | 11 | crc += accum % 256; 12 | 13 | return crc % 256; 14 | }; 15 | 16 | export default crc1; 17 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import { Buffer } from 'buffer'; 2 | 3 | export type BufferInput = string | ArrayBuffer | Buffer; 4 | 5 | export interface CRCCalculator { 6 | (value: T, previous?: number): number; 7 | } 8 | 9 | export interface CRCModule extends CRCCalculator { 10 | signed: CRCCalculator; 11 | unsigned: CRCCalculator; 12 | model: string; 13 | } 14 | -------------------------------------------------------------------------------- /scripts/benchmarks/crc32-100b.js: -------------------------------------------------------------------------------- 1 | const benchmark = require('./benchmark'); 2 | 3 | global.string = benchmark.getBuffer(100).toString(); 4 | 5 | benchmark.add({ 6 | minSamples: 100, 7 | name: 'crc/crc32 100b', 8 | fn: 'var val = crc.crc32(string)', 9 | }); 10 | 11 | benchmark.add({ 12 | minSamples: 100, 13 | name: 'buffer-crc32 100b', 14 | fn: 'var val = bufferCRC32(string)', 15 | }); 16 | 17 | benchmark.run(); 18 | -------------------------------------------------------------------------------- /scripts/benchmarks/crc32-1kb.js: -------------------------------------------------------------------------------- 1 | const benchmark = require('./benchmark'); 2 | 3 | global.string = benchmark.getBuffer(1024).toString(); 4 | 5 | benchmark.add({ 6 | minSamples: 100, 7 | name: 'crc/crc32 1kb', 8 | fn: 'var val = crc.crc32(string)', 9 | }); 10 | 11 | benchmark.add({ 12 | minSamples: 100, 13 | name: 'buffer-crc32 1kb', 14 | fn: 'var val = bufferCRC32(string)', 15 | }); 16 | 17 | benchmark.run(); 18 | -------------------------------------------------------------------------------- /tests/dependencies/node-cjs/main.js: -------------------------------------------------------------------------------- 1 | const crc = require('crc'); 2 | 3 | crc.crc16ccitt('hello world'); 4 | crc.crc16kermit('hello world'); 5 | crc.crc16modbus('hello world'); 6 | crc.crc16('hello world'); 7 | crc.crc16xmodem('hello world'); 8 | crc.crc1('hello world'); 9 | crc.crc24('hello world'); 10 | crc.crc32('hello world'); 11 | crc.crc81wire('hello world'); 12 | crc.crc8('hello world'); 13 | crc.crcjam('hello world'); 14 | -------------------------------------------------------------------------------- /tests/dependencies/node-esm/default.js: -------------------------------------------------------------------------------- 1 | import crc from 'crc'; 2 | 3 | crc.crc16ccitt('hello world'); 4 | crc.crc16kermit('hello world'); 5 | crc.crc16modbus('hello world'); 6 | crc.crc16('hello world'); 7 | crc.crc16xmodem('hello world'); 8 | crc.crc1('hello world'); 9 | crc.crc24('hello world'); 10 | crc.crc32('hello world'); 11 | crc.crc81wire('hello world'); 12 | crc.crc8('hello world'); 13 | crc.crcjam('hello world'); 14 | -------------------------------------------------------------------------------- /scripts/benchmarks/crc32-1mb.js: -------------------------------------------------------------------------------- 1 | const benchmark = require('./benchmark'); 2 | 3 | global.string = benchmark.getBuffer(1000 * 1024).toString(); 4 | 5 | benchmark.add({ 6 | minSamples: 100, 7 | name: 'crc/crc32 1mb', 8 | fn: 'var val = crc.crc32(string)', 9 | }); 10 | 11 | benchmark.add({ 12 | minSamples: 100, 13 | name: 'buffer-crc32 1mb', 14 | fn: 'var val = bufferCRC32(string)', 15 | }); 16 | 17 | benchmark.run(); 18 | -------------------------------------------------------------------------------- /scripts/benchmarks/crc32-5kb.js: -------------------------------------------------------------------------------- 1 | const benchmark = require('./benchmark'); 2 | 3 | global.string = benchmark.getBuffer(5 * 1024).toString(); 4 | 5 | benchmark.add({ 6 | minSamples: 100, 7 | name: 'crc/crc32 5kb', 8 | fn: 'var val = crc.crc32(string)', 9 | }); 10 | 11 | benchmark.add({ 12 | minSamples: 100, 13 | name: 'buffer-crc32 5kb', 14 | fn: 'var val = bufferCRC32(string)', 15 | }); 16 | 17 | benchmark.run(); 18 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-esm/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "baseUrl": "./", 5 | "lib": ["es2020", "dom"], 6 | "module": "es2020", 7 | "moduleResolution": "node", 8 | "noFallthroughCasesInSwitch": true, 9 | "outDir": "./.build", 10 | "resolveJsonModule": true, 11 | "strict": true, 12 | "target": "es2015" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /scripts/benchmarks/crc32-100kb.js: -------------------------------------------------------------------------------- 1 | const benchmark = require('./benchmark'); 2 | 3 | global.string = benchmark.getBuffer(100 * 1024).toString(); 4 | 5 | benchmark.add({ 6 | minSamples: 100, 7 | name: 'crc/crc32 100kb', 8 | fn: 'var val = crc.crc32(string)', 9 | }); 10 | 11 | benchmark.add({ 12 | minSamples: 100, 13 | name: 'buffer-crc32 100kb', 14 | fn: 'var val = bufferCRC32(string)', 15 | }); 16 | 17 | benchmark.run(); 18 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-cjs/default.ts: -------------------------------------------------------------------------------- 1 | import crc from 'crc'; 2 | 3 | crc.crc16ccitt('hello world'); 4 | crc.crc16kermit('hello world'); 5 | crc.crc16modbus('hello world'); 6 | crc.crc16('hello world'); 7 | crc.crc16xmodem('hello world'); 8 | crc.crc1('hello world'); 9 | crc.crc24('hello world'); 10 | crc.crc32('hello world'); 11 | crc.crc81wire('hello world'); 12 | crc.crc8('hello world'); 13 | crc.crcjam('hello world'); 14 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-esm/default.ts: -------------------------------------------------------------------------------- 1 | import crc from 'crc'; 2 | 3 | crc.crc16ccitt('hello world'); 4 | crc.crc16kermit('hello world'); 5 | crc.crc16modbus('hello world'); 6 | crc.crc16('hello world'); 7 | crc.crc16xmodem('hello world'); 8 | crc.crc1('hello world'); 9 | crc.crc24('hello world'); 10 | crc.crc32('hello world'); 11 | crc.crc81wire('hello world'); 12 | crc.crc8('hello world'); 13 | crc.crcjam('hello world'); 14 | -------------------------------------------------------------------------------- /tests/crc16.test.ts: -------------------------------------------------------------------------------- 1 | import crcSuiteFor from './test_helpers'; 2 | import crc16 from './.build/crc16'; 3 | import createBuffer from './.build/create_buffer'; 4 | 5 | describe('CRC16', () => { 6 | crcSuiteFor({ crc: crc16 }); 7 | 8 | // https://github.com/alexgorbatchev/node-crc/issues/29 9 | crcSuiteFor({ 10 | crc: crc16, 11 | value: createBuffer('AR0AAAGP2KJc/vg/AAAAErgGAK8dAAgLAQAAPpo=', 'base64').slice(0, 27), 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /scripts/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -fr dist/cjs 4 | rm -fr dist/mjs 5 | tsc -p tsconfig-cjs.json 6 | tsc -p tsconfig-mjs.json 7 | tsc -p tsconfig-declarations.json 8 | rm dist/cjs/*.d.ts 9 | rm dist/cjs/calculators/*.d.ts 10 | 11 | cp LICENSE ./dist 12 | cp README.md ./dist 13 | 14 | cat >dist/cjs/package.json <dist/mjs/package.json < /dev/null && pwd ) 4 | 5 | cd $SCRIPT_DIR 6 | 7 | for d in * 8 | do 9 | if [ -d "$d" ]; then 10 | echo "Testing: $d" 11 | ( 12 | cd $d 13 | npm install --no-progress 1>/dev/null 14 | npm install ../../../dist/$(cd ../../../dist) --no-progress --no-save 1>/dev/null 15 | npm test 16 | ) 17 | echo "👍 PASSED" 18 | fi 19 | done 20 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowJs": true, 4 | "checkJs": true, 5 | "declaration": true, 6 | "esModuleInterop": true, 7 | "forceConsistentCasingInFileNames": true, 8 | "inlineSourceMap": false, 9 | "module": "NodeNext", 10 | "moduleResolution": "node", 11 | "noImplicitAny": true, 12 | "skipLibCheck": true, 13 | "strict": true, 14 | "strictNullChecks": true 15 | }, 16 | "include": ["src/*"], 17 | "exclude": ["node_modules"] 18 | } 19 | -------------------------------------------------------------------------------- /tests/dependencies/webpack-5-cjs/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | rm -fr ./output 4 | 5 | $(npm bin)/webpack --mode=production 6 | 7 | if [[ "$(node output/with-buffer.js)" != "222957957 222957957" ]]; then 8 | echo "👎 Webpack bundle didn't produce expected output (with-buffer.js)!" 9 | exit 1 10 | fi 11 | 12 | if [[ "$(node output/with-array.js)" != "222957957" ]]; then 13 | echo "👎 Webpack bundle didn't produce expected output (with-array.js)!" 14 | exit 1 15 | fi 16 | 17 | echo "👍 Webpack bundle ok!" 18 | -------------------------------------------------------------------------------- /src/define_crc.ts: -------------------------------------------------------------------------------- 1 | import createBuffer from './create_buffer.js'; 2 | import { CRCCalculator, CRCModule } from './types.js'; 3 | 4 | export default function defineCrc(model: string, calculator: CRCCalculator): CRCModule { 5 | const result: CRCModule = (value, previous) => calculator(createBuffer(value), previous) >>> 0; 6 | 7 | result.signed = (value, previous) => calculator(createBuffer(value), previous); 8 | result.unsigned = result; 9 | result.model = model; 10 | 11 | return result; 12 | } 13 | -------------------------------------------------------------------------------- /dist/cjs-default-unwrap/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | crc1: require('./crc1'), 3 | crc8: require('./crc8'), 4 | crc81wire: require('./crc81wire'), 5 | crc16: require('./crc16'), 6 | crc16ccitt: require('./crc16ccitt'), 7 | crc16modbus: require('./crc16modbus'), 8 | crc16xmodem: require('./crc16xmodem'), 9 | crc16kermit: require('./crc16kermit'), 10 | crc24: require('./crc24'), 11 | crc32: require('./crc32'), 12 | crc32mpeg: require('./crc32mpeg2'), 13 | crcjam: require('./crcjam'), 14 | }; 15 | 16 | module.exports.default = module.exports; 17 | -------------------------------------------------------------------------------- /scripts/test-multicoin-address-validator: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | cd tests 4 | 5 | if [ ! -d ./multicoin-address-validator ]; then 6 | ( 7 | git clone https://github.com/christsim/multicoin-address-validator.git ./multicoin-address-validator 8 | cd multicoin-address-validator 9 | git checkout f8f3626f441c0d53fdc3b89678629dc1d33c0546 10 | ) 11 | fi 12 | 13 | cd multicoin-address-validator 14 | 15 | if [ ! -d node_modules ]; then 16 | npm install 17 | fi 18 | 19 | npm install ../../dist 20 | 21 | $(npm bin)/mocha --config=../.mocharc-multicoin-address-validator.js test 22 | 23 | echo "👍 multicoin-address-validator tests okay!" 24 | -------------------------------------------------------------------------------- /src/calculators/crc16xmodem.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | const crc16xmodem: CRCCalculator = (current, previous) => { 4 | let crc = typeof previous !== 'undefined' ? ~~previous : 0x0; 5 | 6 | for (let index = 0; index < current.length; index++) { 7 | let code = (crc >>> 8) & 0xff; 8 | 9 | code ^= current[index] & 0xff; 10 | code ^= code >>> 4; 11 | crc = (crc << 8) & 0xffff; 12 | crc ^= code; 13 | code = (code << 5) & 0xffff; 14 | crc ^= code; 15 | code = (code << 7) & 0xffff; 16 | crc ^= code; 17 | } 18 | 19 | return crc; 20 | }; 21 | 22 | export default crc16xmodem; 23 | -------------------------------------------------------------------------------- /tests/dependencies/node-cjs/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "crc-test", 9 | "version": "1.0.0", 10 | "license": "ISC" 11 | }, 12 | "../../../dist": { 13 | "name": "crc", 14 | "version": "4.0.0", 15 | "extraneous": true, 16 | "license": "MIT", 17 | "engines": { 18 | "node": ">=12" 19 | }, 20 | "peerDependencies": { 21 | "buffer": ">=6.0.3" 22 | } 23 | }, 24 | "../../dist": { 25 | "extraneous": true 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/dependencies/node-esm/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "crc-test", 9 | "version": "1.0.0", 10 | "license": "ISC" 11 | }, 12 | "../../../dist": { 13 | "name": "crc", 14 | "version": "4.0.0", 15 | "extraneous": true, 16 | "license": "MIT", 17 | "engines": { 18 | "node": ">=12" 19 | }, 20 | "peerDependencies": { 21 | "buffer": ">=6.0.3" 22 | } 23 | }, 24 | "../../dist": { 25 | "extraneous": true 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parser: '@typescript-eslint/parser', 4 | plugins: ['@typescript-eslint', 'import'], 5 | extends: [ 6 | 'airbnb-base', 7 | 'prettier', 8 | 'plugin:@typescript-eslint/recommended', 9 | 'plugin:import/errors', 10 | 'plugin:import/warnings', 11 | 'plugin:import/typescript', 12 | ], 13 | parserOptions: { 14 | ecmaVersion: 2017, 15 | sourceType: 'module', 16 | }, 17 | env: { 18 | commonjs: true, 19 | node: true, 20 | es6: true, 21 | }, 22 | rules: { 23 | 'no-bitwise': 'off', 24 | 'no-plusplus': 'off', 25 | 'import/extensions': 'off', 26 | }, 27 | }; 28 | -------------------------------------------------------------------------------- /tests/pycrc/doc/Makefile: -------------------------------------------------------------------------------- 1 | XSLTPROC = xsltproc 2 | XSLTPARAM = --nonet --novalid 3 | HTML_STYLESHEET = /usr/share/xml/docbook/stylesheet/nwalsh/html/docbook.xsl 4 | MAN_STYLESHEET = /usr/share/xml/docbook/stylesheet/nwalsh/manpages/docbook.xsl 5 | 6 | source = pycrc.xml 7 | targets = $(source:.xml=.html) $(source:.xml=.1) 8 | 9 | all: $(targets) 10 | 11 | .PHONY: clean 12 | clean: 13 | $(RM) $(targets) 14 | 15 | .PHONY: check 16 | check: 17 | xmllint --valid --noout $(source) 18 | 19 | %.html: %.xml 20 | $(XSLTPROC) $(XSLTPARAM) -o $@ $(HTML_STYLESHEET) $< 21 | 22 | %.1: %.xml 23 | $(XSLTPROC) $(XSLTPARAM) -o $@ $(MAN_STYLESHEET) $< 24 | 25 | %.txt: %.html 26 | links -dump -no-numbering -no-references $< > $@ 27 | -------------------------------------------------------------------------------- /tests/dependencies/node-esm/individual.js: -------------------------------------------------------------------------------- 1 | import crc16ccitt from 'crc/crc16ccitt'; 2 | import crc16kermit from 'crc/crc16kermit'; 3 | import crc16modbus from 'crc/crc16modbus'; 4 | import crc16 from 'crc/crc16'; 5 | import crc16xmodem from 'crc/crc16xmodem'; 6 | import crc1 from 'crc/crc1'; 7 | import crc24 from 'crc/crc24'; 8 | import crc32 from 'crc/crc32'; 9 | import crc81wire from 'crc/crc81wire'; 10 | import crc8 from 'crc/crc8'; 11 | import crcjam from 'crc/crcjam'; 12 | 13 | crc16ccitt('hello world'); 14 | crc16kermit('hello world'); 15 | crc16modbus('hello world'); 16 | crc16('hello world'); 17 | crc16xmodem('hello world'); 18 | crc1('hello world'); 19 | crc24('hello world'); 20 | crc32('hello world'); 21 | crc81wire('hello world'); 22 | crc8('hello world'); 23 | crcjam('hello world'); 24 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-cjs/individual.ts: -------------------------------------------------------------------------------- 1 | import crc16ccitt from 'crc/crc16ccitt'; 2 | import crc16kermit from 'crc/crc16kermit'; 3 | import crc16modbus from 'crc/crc16modbus'; 4 | import crc16 from 'crc/crc16'; 5 | import crc16xmodem from 'crc/crc16xmodem'; 6 | import crc1 from 'crc/crc1'; 7 | import crc24 from 'crc/crc24'; 8 | import crc32 from 'crc/crc32'; 9 | import crc81wire from 'crc/crc81wire'; 10 | import crc8 from 'crc/crc8'; 11 | import crcjam from 'crc/crcjam'; 12 | 13 | crc16ccitt('hello world'); 14 | crc16kermit('hello world'); 15 | crc16modbus('hello world'); 16 | crc16('hello world'); 17 | crc16xmodem('hello world'); 18 | crc1('hello world'); 19 | crc24('hello world'); 20 | crc32('hello world'); 21 | crc81wire('hello world'); 22 | crc8('hello world'); 23 | crcjam('hello world'); 24 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-esm/individual.ts: -------------------------------------------------------------------------------- 1 | import crc16ccitt from 'crc/crc16ccitt'; 2 | import crc16kermit from 'crc/crc16kermit'; 3 | import crc16modbus from 'crc/crc16modbus'; 4 | import crc16 from 'crc/crc16'; 5 | import crc16xmodem from 'crc/crc16xmodem'; 6 | import crc1 from 'crc/crc1'; 7 | import crc24 from 'crc/crc24'; 8 | import crc32 from 'crc/crc32'; 9 | import crc81wire from 'crc/crc81wire'; 10 | import crc8 from 'crc/crc8'; 11 | import crcjam from 'crc/crcjam'; 12 | 13 | crc16ccitt('hello world'); 14 | crc16kermit('hello world'); 15 | crc16modbus('hello world'); 16 | crc16('hello world'); 17 | crc16xmodem('hello world'); 18 | crc1('hello world'); 19 | crc24('hello world'); 20 | crc32('hello world'); 21 | crc81wire('hello world'); 22 | crc8('hello world'); 23 | crcjam('hello world'); 24 | -------------------------------------------------------------------------------- /tests/dependencies/node-cjs/individual.js: -------------------------------------------------------------------------------- 1 | const crc16ccitt = require('crc/crc16ccitt'); 2 | const crc16kermit = require('crc/crc16kermit'); 3 | const crc16modbus = require('crc/crc16modbus'); 4 | const crc16 = require('crc/crc16'); 5 | const crc16xmodem = require('crc/crc16xmodem'); 6 | const crc1 = require('crc/crc1'); 7 | const crc24 = require('crc/crc24'); 8 | const crc32 = require('crc/crc32'); 9 | const crc81wire = require('crc/crc81wire'); 10 | const crc8 = require('crc/crc8'); 11 | const crcjam = require('crc/crcjam'); 12 | 13 | crc16ccitt('hello world'); 14 | crc16kermit('hello world'); 15 | crc16modbus('hello world'); 16 | crc16('hello world'); 17 | crc16xmodem('hello world'); 18 | crc1('hello world'); 19 | crc24('hello world'); 20 | crc32('hello world'); 21 | crc81wire('hello world'); 22 | crc8('hello world'); 23 | crcjam('hello world'); 24 | -------------------------------------------------------------------------------- /scripts/benchmarks/benchmark.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable import/no-extraneous-dependencies */ 2 | const benchmark = require('benchmark'); 3 | const benchmarks = require('beautify-benchmark'); 4 | const seedrandom = require('seedrandom'); 5 | 6 | const getBuffer = (size) => { 7 | const buffer = Buffer.alloc(size); 8 | const rng = seedrandom(`body ${size}`); 9 | 10 | for (let i = 0; i < buffer.length - 1; i++) { 11 | buffer[i] = (rng() * 94 + 32) | 0; 12 | } 13 | 14 | return buffer; 15 | }; 16 | 17 | global.crc = require('../../lib'); 18 | global.bufferCRC32 = require('buffer-crc32'); 19 | 20 | const suite = new benchmark.Suite(); 21 | suite.on('start', () => process.stdout.write('Working...\n\n')); 22 | suite.on('cycle', (e) => benchmarks.add(e.target)); 23 | suite.on('complete', () => benchmarks.log()); 24 | 25 | module.exports = { 26 | getBuffer, 27 | add() { 28 | return suite.add(...arguments); 29 | }, 30 | run() { 31 | return suite.run({ async: false }); 32 | }, 33 | }; 34 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import crc1 from './crc1.js'; 2 | import crc8 from './crc8.js'; 3 | import crc81wire from './crc81wire.js'; 4 | import crc8dvbs2 from './crc8dvbs2.js'; 5 | import crc16 from './crc16.js'; 6 | import crc16ccitt from './crc16ccitt.js'; 7 | import crc16modbus from './crc16modbus.js'; 8 | import crc16xmodem from './crc16xmodem.js'; 9 | import crc16kermit from './crc16kermit.js'; 10 | import crc24 from './crc24.js'; 11 | import crc32 from './crc32.js'; 12 | import crc32mpeg2 from './crc32mpeg2.js'; 13 | import crcjam from './crcjam.js'; 14 | 15 | export { crc1 }; 16 | export { crc8 }; 17 | export { crc81wire }; 18 | export { crc8dvbs2 }; 19 | export { crc16 }; 20 | export { crc16ccitt }; 21 | export { crc16modbus }; 22 | export { crc16xmodem }; 23 | export { crc16kermit }; 24 | export { crc24 }; 25 | export { crc32 }; 26 | export { crc32mpeg2 }; 27 | export { crcjam }; 28 | 29 | export default { 30 | crc1, 31 | crc8, 32 | crc81wire, 33 | crc8dvbs2, 34 | crc16, 35 | crc16ccitt, 36 | crc16modbus, 37 | crc16xmodem, 38 | crc16kermit, 39 | crc24, 40 | crc32, 41 | crc32mpeg2, 42 | crcjam, 43 | }; 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright 2014 Alex Gorbatchev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /tests/pycrc/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2013, Thomas Pircher 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /tests/dependencies/node-esm/calculators.js: -------------------------------------------------------------------------------- 1 | import crc16ccitt from 'crc/calculators/crc16ccitt'; 2 | import crc16kermit from 'crc/calculators/crc16kermit'; 3 | import crc16modbus from 'crc/calculators/crc16modbus'; 4 | import crc16 from 'crc/calculators/crc16'; 5 | import crc16xmodem from 'crc/calculators/crc16xmodem'; 6 | import crc1 from 'crc/calculators/crc1'; 7 | import crc24 from 'crc/calculators/crc24'; 8 | import crc32 from 'crc/calculators/crc32'; 9 | import crc81wire from 'crc/calculators/crc81wire'; 10 | import crc8 from 'crc/calculators/crc8'; 11 | import crcjam from 'crc/calculators/crcjam'; 12 | 13 | crc16ccitt(new TextEncoder().encode('hello world')); 14 | crc16kermit(new TextEncoder().encode('hello world')); 15 | crc16modbus(new TextEncoder().encode('hello world')); 16 | crc16(new TextEncoder().encode('hello world')); 17 | crc16xmodem(new TextEncoder().encode('hello world')); 18 | crc1(new TextEncoder().encode('hello world')); 19 | crc24(new TextEncoder().encode('hello world')); 20 | crc32(new TextEncoder().encode('hello world')); 21 | crc81wire(new TextEncoder().encode('hello world')); 22 | crc8(new TextEncoder().encode('hello world')); 23 | crcjam(new TextEncoder().encode('hello world')); 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc", 3 | "private": "true", 4 | "scripts": { 5 | "lint": "eslint src/{,**/}*.ts test/{,**/}*.ts", 6 | "test": "./scripts/test", 7 | "build": "./scripts/build", 8 | "benchmark": "./scripts/benchmark" 9 | }, 10 | "devDependencies": { 11 | "@types/chai": "^4.3.4", 12 | "@types/mocha": "^10.0.1", 13 | "@types/node": "^18.11.15", 14 | "@types/prettier": "^2.7.1", 15 | "@typescript-eslint/eslint-plugin": "^5.46.1", 16 | "@typescript-eslint/parser": "^5.46.1", 17 | "beautify-benchmark": "^0.2.4", 18 | "benchmark": "^2.1.4", 19 | "buffer-crc32": "^0.2.13", 20 | "buffer": "^6.0.3", 21 | "chai": "^4.3.7", 22 | "eslint": "^8.29.0", 23 | "eslint-config-airbnb-base": "^15.0.0", 24 | "eslint-config-prettier": "^8.5.0", 25 | "eslint-config-typescript": "^3.0.0", 26 | "eslint-formatter-pretty": "^4.1.0", 27 | "eslint-plugin-import": "^2.26.0", 28 | "eslint-plugin-no-only-tests": "^3.1.0", 29 | "eslint-plugin-prettier": "^4.2.1", 30 | "mocha": "^10.2.0", 31 | "prettier": "^2.8.1", 32 | "seedrandom": "^3.0.5", 33 | "ts-node": "^10.9.1", 34 | "typescript": "^4.9.4" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-cjs/calculators.ts: -------------------------------------------------------------------------------- 1 | import crc16ccitt from 'crc/calculators/crc16ccitt'; 2 | import crc16kermit from 'crc/calculators/crc16kermit'; 3 | import crc16modbus from 'crc/calculators/crc16modbus'; 4 | import crc16 from 'crc/calculators/crc16'; 5 | import crc16xmodem from 'crc/calculators/crc16xmodem'; 6 | import crc1 from 'crc/calculators/crc1'; 7 | import crc24 from 'crc/calculators/crc24'; 8 | import crc32 from 'crc/calculators/crc32'; 9 | import crc81wire from 'crc/calculators/crc81wire'; 10 | import crc8 from 'crc/calculators/crc8'; 11 | import crcjam from 'crc/calculators/crcjam'; 12 | 13 | crc16ccitt(new TextEncoder().encode('hello world')); 14 | crc16kermit(new TextEncoder().encode('hello world')); 15 | crc16modbus(new TextEncoder().encode('hello world')); 16 | crc16(new TextEncoder().encode('hello world')); 17 | crc16xmodem(new TextEncoder().encode('hello world')); 18 | crc1(new TextEncoder().encode('hello world')); 19 | crc24(new TextEncoder().encode('hello world')); 20 | crc32(new TextEncoder().encode('hello world')); 21 | crc81wire(new TextEncoder().encode('hello world')); 22 | crc8(new TextEncoder().encode('hello world')); 23 | crcjam(new TextEncoder().encode('hello world')); 24 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-esm/calculators.ts: -------------------------------------------------------------------------------- 1 | import crc16ccitt from 'crc/calculators/crc16ccitt'; 2 | import crc16kermit from 'crc/calculators/crc16kermit'; 3 | import crc16modbus from 'crc/calculators/crc16modbus'; 4 | import crc16 from 'crc/calculators/crc16'; 5 | import crc16xmodem from 'crc/calculators/crc16xmodem'; 6 | import crc1 from 'crc/calculators/crc1'; 7 | import crc24 from 'crc/calculators/crc24'; 8 | import crc32 from 'crc/calculators/crc32'; 9 | import crc81wire from 'crc/calculators/crc81wire'; 10 | import crc8 from 'crc/calculators/crc8'; 11 | import crcjam from 'crc/calculators/crcjam'; 12 | 13 | crc16ccitt(new TextEncoder().encode('hello world')); 14 | crc16kermit(new TextEncoder().encode('hello world')); 15 | crc16modbus(new TextEncoder().encode('hello world')); 16 | crc16(new TextEncoder().encode('hello world')); 17 | crc16xmodem(new TextEncoder().encode('hello world')); 18 | crc1(new TextEncoder().encode('hello world')); 19 | crc24(new TextEncoder().encode('hello world')); 20 | crc32(new TextEncoder().encode('hello world')); 21 | crc81wire(new TextEncoder().encode('hello world')); 22 | crc8(new TextEncoder().encode('hello world')); 23 | crcjam(new TextEncoder().encode('hello world')); 24 | -------------------------------------------------------------------------------- /tests/dependencies/node-cjs/calculators.js: -------------------------------------------------------------------------------- 1 | const crc16ccitt = require('crc/calculators/crc16ccitt'); 2 | const crc16kermit = require('crc/calculators/crc16kermit'); 3 | const crc16modbus = require('crc/calculators/crc16modbus'); 4 | const crc16 = require('crc/calculators/crc16'); 5 | const crc16xmodem = require('crc/calculators/crc16xmodem'); 6 | const crc1 = require('crc/calculators/crc1'); 7 | const crc24 = require('crc/calculators/crc24'); 8 | const crc32 = require('crc/calculators/crc32'); 9 | const crc81wire = require('crc/calculators/crc81wire'); 10 | const crc8 = require('crc/calculators/crc8'); 11 | const crcjam = require('crc/calculators/crcjam'); 12 | 13 | crc16ccitt(new TextEncoder().encode('hello world')); 14 | crc16kermit(new TextEncoder().encode('hello world')); 15 | crc16modbus(new TextEncoder().encode('hello world')); 16 | crc16(new TextEncoder().encode('hello world')); 17 | crc16xmodem(new TextEncoder().encode('hello world')); 18 | crc1(new TextEncoder().encode('hello world')); 19 | crc24(new TextEncoder().encode('hello world')); 20 | crc32(new TextEncoder().encode('hello world')); 21 | crc81wire(new TextEncoder().encode('hello world')); 22 | crc8(new TextEncoder().encode('hello world')); 23 | crcjam(new TextEncoder().encode('hello world')); 24 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-cjs/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "crc-test", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "typescript": "4.5.4" 13 | } 14 | }, 15 | "../../../dist": { 16 | "name": "crc", 17 | "version": "4.0.0", 18 | "extraneous": true, 19 | "license": "MIT", 20 | "engines": { 21 | "node": ">=12" 22 | }, 23 | "peerDependencies": { 24 | "buffer": ">=6.0.3" 25 | } 26 | }, 27 | "../../dist": { 28 | "extraneous": true 29 | }, 30 | "node_modules/typescript": { 31 | "version": "4.5.4", 32 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", 33 | "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==", 34 | "bin": { 35 | "tsc": "bin/tsc", 36 | "tsserver": "bin/tsserver" 37 | }, 38 | "engines": { 39 | "node": ">=4.2.0" 40 | } 41 | } 42 | }, 43 | "dependencies": { 44 | "typescript": { 45 | "version": "4.5.4", 46 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", 47 | "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==" 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/dependencies/typescript-4.5.4-esm/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "crc-test", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "typescript": "4.5.4" 13 | } 14 | }, 15 | "../../../dist": { 16 | "name": "crc", 17 | "version": "4.0.0", 18 | "extraneous": true, 19 | "license": "MIT", 20 | "engines": { 21 | "node": ">=12" 22 | }, 23 | "peerDependencies": { 24 | "buffer": ">=6.0.3" 25 | } 26 | }, 27 | "../../dist": { 28 | "extraneous": true 29 | }, 30 | "node_modules/typescript": { 31 | "version": "4.5.4", 32 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", 33 | "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==", 34 | "bin": { 35 | "tsc": "bin/tsc", 36 | "tsserver": "bin/tsserver" 37 | }, 38 | "engines": { 39 | "node": ">=4.2.0" 40 | } 41 | } 42 | }, 43 | "dependencies": { 44 | "typescript": { 45 | "version": "4.5.4", 46 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", 47 | "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==" 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/calculators/crc8.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --model=crc-8 --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, 6 | 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d, 7 | 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd, 8 | 0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd, 9 | 0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea, 10 | 0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a, 11 | 0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a, 12 | 0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a, 13 | 0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4, 14 | 0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4, 15 | 0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44, 16 | 0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34, 17 | 0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63, 18 | 0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13, 19 | 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83, 20 | 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3, 21 | ]; 22 | 23 | if (typeof Int32Array !== 'undefined') { 24 | TABLE = new Int32Array(TABLE); 25 | } 26 | 27 | const crc8: CRCCalculator = (current, previous = 0) => { 28 | let crc = ~~previous; 29 | 30 | for (let index = 0; index < current.length; index++) { 31 | crc = TABLE[(crc ^ current[index]) & 0xff] & 0xff; 32 | } 33 | 34 | return crc; 35 | }; 36 | 37 | export default crc8; 38 | -------------------------------------------------------------------------------- /src/calculators/crc81wire.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --model=dallas-1-wire --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 6 | 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc, 7 | 0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c, 0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde, 0x3c, 0x62, 8 | 0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c, 0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff, 9 | 0x46, 0x18, 0xfa, 0xa4, 0x27, 0x79, 0x9b, 0xc5, 0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07, 10 | 0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb, 0x78, 0x26, 0xc4, 0x9a, 11 | 0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24, 12 | 0xf8, 0xa6, 0x44, 0x1a, 0x99, 0xc7, 0x25, 0x7b, 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9, 13 | 0x8c, 0xd2, 0x30, 0x6e, 0xed, 0xb3, 0x51, 0x0f, 0x4e, 0x10, 0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd, 14 | 0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, 0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50, 15 | 0xaf, 0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, 0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee, 16 | 0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1, 0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73, 17 | 0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5, 0x8b, 18 | 0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16, 19 | 0xe9, 0xb7, 0x55, 0x0b, 0x88, 0xd6, 0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8, 20 | 0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, 0xb6, 0xe8, 0x0a, 0x54, 0xd7, 0x89, 0x6b, 0x35, 21 | ]; 22 | 23 | if (typeof Int32Array !== 'undefined') { 24 | TABLE = new Int32Array(TABLE); 25 | } 26 | 27 | const crc81wire: CRCCalculator = (current, previous = 0) => { 28 | let crc = ~~previous; 29 | 30 | for (let index = 0; index < current.length; index++) { 31 | crc = TABLE[(crc ^ current[index]) & 0xff] & 0xff; 32 | } 33 | 34 | return crc; 35 | }; 36 | 37 | export default crc81wire; 38 | -------------------------------------------------------------------------------- /src/calculators/crc8dvbs2.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --generate=c --width=8 --poly=0xd5 --reflect-in=false --reflect-out=false --xor-in=0xff --xor-out=0x00` 4 | let TABLE: Array | Int32Array = [ 5 | 0x00, 0xd5, 0x7f, 0xaa, 0xfe, 0x2b, 0x81, 0x54, 0x29, 0xfc, 0x56, 0x83, 0xd7, 0x02, 0xa8, 0x7d, 6 | 0x52, 0x87, 0x2d, 0xf8, 0xac, 0x79, 0xd3, 0x06, 0x7b, 0xae, 0x04, 0xd1, 0x85, 0x50, 0xfa, 0x2f, 7 | 0xa4, 0x71, 0xdb, 0x0e, 0x5a, 0x8f, 0x25, 0xf0, 0x8d, 0x58, 0xf2, 0x27, 0x73, 0xa6, 0x0c, 0xd9, 8 | 0xf6, 0x23, 0x89, 0x5c, 0x08, 0xdd, 0x77, 0xa2, 0xdf, 0x0a, 0xa0, 0x75, 0x21, 0xf4, 0x5e, 0x8b, 9 | 0x9d, 0x48, 0xe2, 0x37, 0x63, 0xb6, 0x1c, 0xc9, 0xb4, 0x61, 0xcb, 0x1e, 0x4a, 0x9f, 0x35, 0xe0, 10 | 0xcf, 0x1a, 0xb0, 0x65, 0x31, 0xe4, 0x4e, 0x9b, 0xe6, 0x33, 0x99, 0x4c, 0x18, 0xcd, 0x67, 0xb2, 11 | 0x39, 0xec, 0x46, 0x93, 0xc7, 0x12, 0xb8, 0x6d, 0x10, 0xc5, 0x6f, 0xba, 0xee, 0x3b, 0x91, 0x44, 12 | 0x6b, 0xbe, 0x14, 0xc1, 0x95, 0x40, 0xea, 0x3f, 0x42, 0x97, 0x3d, 0xe8, 0xbc, 0x69, 0xc3, 0x16, 13 | 0xef, 0x3a, 0x90, 0x45, 0x11, 0xc4, 0x6e, 0xbb, 0xc6, 0x13, 0xb9, 0x6c, 0x38, 0xed, 0x47, 0x92, 14 | 0xbd, 0x68, 0xc2, 0x17, 0x43, 0x96, 0x3c, 0xe9, 0x94, 0x41, 0xeb, 0x3e, 0x6a, 0xbf, 0x15, 0xc0, 15 | 0x4b, 0x9e, 0x34, 0xe1, 0xb5, 0x60, 0xca, 0x1f, 0x62, 0xb7, 0x1d, 0xc8, 0x9c, 0x49, 0xe3, 0x36, 16 | 0x19, 0xcc, 0x66, 0xb3, 0xe7, 0x32, 0x98, 0x4d, 0x30, 0xe5, 0x4f, 0x9a, 0xce, 0x1b, 0xb1, 0x64, 17 | 0x72, 0xa7, 0x0d, 0xd8, 0x8c, 0x59, 0xf3, 0x26, 0x5b, 0x8e, 0x24, 0xf1, 0xa5, 0x70, 0xda, 0x0f, 18 | 0x20, 0xf5, 0x5f, 0x8a, 0xde, 0x0b, 0xa1, 0x74, 0x09, 0xdc, 0x76, 0xa3, 0xf7, 0x22, 0x88, 0x5d, 19 | 0xd6, 0x03, 0xa9, 0x7c, 0x28, 0xfd, 0x57, 0x82, 0xff, 0x2a, 0x80, 0x55, 0x01, 0xd4, 0x7e, 0xab, 20 | 0x84, 0x51, 0xfb, 0x2e, 0x7a, 0xaf, 0x05, 0xd0, 0xad, 0x78, 0xd2, 0x07, 0x53, 0x86, 0x2c, 0xf9, 21 | ]; 22 | 23 | if (typeof Int32Array !== 'undefined') { 24 | TABLE = new Int32Array(TABLE); 25 | } 26 | 27 | const crc8dvbs2: CRCCalculator = (current, previous = 0) => { 28 | let crc = ~~previous; 29 | 30 | for (let index = 0; index < current.length; index++) { 31 | crc = TABLE[(crc ^ current[index]) & 0xff] & 0xff; 32 | } 33 | 34 | return crc; 35 | }; 36 | 37 | export default crc8dvbs2; 38 | -------------------------------------------------------------------------------- /src/calculators/crc16.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --model=crc-16 --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, 0x06c0, 0x0780, 0xc741, 6 | 0x0500, 0xc5c1, 0xc481, 0x0440, 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 7 | 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, 8 | 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, 9 | 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, 0xd201, 0x12c0, 0x1380, 0xd341, 10 | 0x1100, 0xd1c1, 0xd081, 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, 11 | 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 12 | 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 13 | 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, 14 | 0x2d00, 0xedc1, 0xec81, 0x2c40, 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, 15 | 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 16 | 0x6300, 0xa3c1, 0xa281, 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, 17 | 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, 0x6ac0, 0x6b80, 0xab41, 18 | 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, 19 | 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, 20 | 0x7700, 0xb7c1, 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, 21 | 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 22 | 0x5500, 0x95c1, 0x9481, 0x5440, 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, 23 | 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, 0x8801, 0x48c0, 0x4980, 0x8941, 24 | 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, 25 | 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, 26 | 0x4100, 0x81c1, 0x8081, 0x4040, 27 | ]; 28 | 29 | if (typeof Int32Array !== 'undefined') { 30 | TABLE = new Int32Array(TABLE); 31 | } 32 | 33 | const crc16: CRCCalculator = (current, previous = 0) => { 34 | let crc = ~~previous; 35 | 36 | for (let index = 0; index < current.length; index++) { 37 | crc = (TABLE[(crc ^ current[index]) & 0xff] ^ (crc >> 8)) & 0xffff; 38 | } 39 | 40 | return crc; 41 | }; 42 | 43 | export default crc16; 44 | -------------------------------------------------------------------------------- /src/calculators/crc16ccitt.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --model=ccitt --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 6 | 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 7 | 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, 8 | 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 9 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738, 10 | 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 11 | 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 12 | 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 13 | 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, 14 | 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 15 | 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 16 | 0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 17 | 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x02b1, 0x1290, 0x22f3, 0x32d2, 18 | 0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 19 | 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8, 20 | 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 21 | 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 22 | 0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 23 | 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 24 | 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 25 | 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 26 | 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, 27 | ]; 28 | 29 | if (typeof Int32Array !== 'undefined') { 30 | TABLE = new Int32Array(TABLE); 31 | } 32 | 33 | const crc16ccitt: CRCCalculator = (current, previous) => { 34 | let crc = typeof previous !== 'undefined' ? ~~previous : 0xffff; 35 | 36 | for (let index = 0; index < current.length; index++) { 37 | crc = (TABLE[((crc >> 8) ^ current[index]) & 0xff] ^ (crc << 8)) & 0xffff; 38 | } 39 | 40 | return crc; 41 | }; 42 | 43 | export default crc16ccitt; 44 | -------------------------------------------------------------------------------- /src/calculators/crc16kermit.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --model=kermit --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 6 | 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 7 | 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399, 8 | 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 9 | 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 10 | 0xfbef, 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 11 | 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e, 12 | 0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 13 | 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 14 | 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 15 | 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 16 | 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 17 | 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 18 | 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 19 | 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710, 20 | 0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 21 | 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 22 | 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 23 | 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e, 0xf687, 0xc41c, 0xd595, 24 | 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 25 | 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 26 | 0x3de3, 0x2c6a, 0x1ef1, 0x0f78, 27 | ]; 28 | 29 | if (typeof Int32Array !== 'undefined') { 30 | TABLE = new Int32Array(TABLE); 31 | } 32 | 33 | const crc16kermit: CRCCalculator = (current, previous) => { 34 | let crc = typeof previous !== 'undefined' ? ~~previous : 0x0000; 35 | 36 | for (let index = 0; index < current.length; index++) { 37 | crc = (TABLE[(crc ^ current[index]) & 0xff] ^ (crc >> 8)) & 0xffff; 38 | } 39 | 40 | return crc; 41 | }; 42 | 43 | export default crc16kermit; 44 | -------------------------------------------------------------------------------- /src/calculators/crc16modbus.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --model=crc-16-modbus --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, 0x06c0, 0x0780, 0xc741, 6 | 0x0500, 0xc5c1, 0xc481, 0x0440, 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 7 | 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, 8 | 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, 9 | 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, 0xd201, 0x12c0, 0x1380, 0xd341, 10 | 0x1100, 0xd1c1, 0xd081, 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, 11 | 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 12 | 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 13 | 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, 14 | 0x2d00, 0xedc1, 0xec81, 0x2c40, 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, 15 | 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 16 | 0x6300, 0xa3c1, 0xa281, 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, 17 | 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, 0x6ac0, 0x6b80, 0xab41, 18 | 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, 19 | 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, 20 | 0x7700, 0xb7c1, 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, 21 | 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 22 | 0x5500, 0x95c1, 0x9481, 0x5440, 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, 23 | 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, 0x8801, 0x48c0, 0x4980, 0x8941, 24 | 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, 25 | 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, 26 | 0x4100, 0x81c1, 0x8081, 0x4040, 27 | ]; 28 | 29 | if (typeof Int32Array !== 'undefined') { 30 | TABLE = new Int32Array(TABLE); 31 | } 32 | 33 | const crc16modbus: CRCCalculator = (current, previous) => { 34 | let crc = typeof previous !== 'undefined' ? ~~previous : 0xffff; 35 | 36 | for (let index = 0; index < current.length; index++) { 37 | crc = (TABLE[(crc ^ current[index]) & 0xff] ^ (crc >> 8)) & 0xffff; 38 | } 39 | 40 | return crc; 41 | }; 42 | 43 | export default crc16modbus; 44 | -------------------------------------------------------------------------------- /tests/pycrc/test/check_files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | PYCRC=`dirname $0`/../pycrc.py 5 | outdir_old="/tmp/pycrc_out" 6 | outdir_new="/tmp/pycrc_new" 7 | tarfile="pycrc_files.tar.gz" 8 | 9 | usage() { 10 | echo >&2 "usage: $0 [OPTIONS]" 11 | echo >&2 "" 12 | echo >&2 "with OPTIONS in" 13 | echo >&2 " -c check the generated output" 14 | echo >&2 " -g generate the database" 15 | echo >&2 " -n no cleanup: don't delete the directories with the generated code" 16 | echo >&2 " -h this help message" 17 | } 18 | 19 | 20 | opt_check=off 21 | opt_no_cleanup=off 22 | opt_generate=off 23 | 24 | while getopts cgnh opt; do 25 | case "$opt" in 26 | c) opt_check=on;; 27 | g) opt_generate=on;; 28 | n) opt_no_cleanup=on;; 29 | h) usage 30 | exit 0 31 | ;; 32 | \?) usage # unknown flag 33 | exit 1 34 | ;; 35 | esac 36 | done 37 | shift `expr $OPTIND - 1` 38 | 39 | if [ -e "$outdir_old" ]; then 40 | echo >&2 "Output directory $outdir_old exists!" 41 | exit 1 42 | fi 43 | if [ -e "$outdir_new" ]; then 44 | echo >&2 "Output directory $outdir_new exists!" 45 | exit 1 46 | fi 47 | 48 | 49 | cleanup() { 50 | if [ "$opt_no_cleanup" = "on" ]; then 51 | echo "No cleanup. Please delete $outdir_old and $outdir_new when you're done" 52 | else 53 | rm -rf "$outdir_old" "$outdir_new" 54 | fi 55 | } 56 | 57 | trap cleanup 0 1 2 3 15 58 | 59 | 60 | populate() { 61 | outdir=$1 62 | mkdir -p "$outdir" 63 | models=`awk 'BEGIN { FS="'"'"'" } $2 == "name" && $3 ~ /^: */ { print $4 }' ../crc_models.py` 64 | for m in $models; do 65 | for algo in "bit-by-bit" "bit-by-bit-fast" "bitwise-expression" "table-driven"; do 66 | $PYCRC --model $m --algorithm $algo --generate h -o "${outdir}/${m}_${algo}.h" 67 | $PYCRC --model $m --algorithm $algo --generate c -o "${outdir}/${m}_${algo}.c" 68 | sed -i -e 's/Generated on ... ... .. ..:..:.. ....,/Generated on XXX XXX XX XX:XX:XX XXXX,/; s/by pycrc v[0-9.]*/by pycrc vXXX/;' "${outdir}/${m}_${algo}.h" 69 | sed -i -e 's/Generated on ... ... .. ..:..:.. ....,/Generated on XXX XXX XX XX:XX:XX XXXX,/; s/by pycrc v[0-9.]*/by pycrc vXXX/;' "${outdir}/${m}_${algo}.c" 70 | done 71 | done 72 | } 73 | 74 | do_check() { 75 | tar xzf "$tarfile" -C "`dirname $outdir_new`" 76 | populate "$outdir_new" 77 | diff -ru "$outdir_old" "$outdir_new" 78 | } 79 | 80 | 81 | if [ "$opt_check" = "on" ]; then 82 | if [ ! -f "$tarfile" ]; then 83 | echo >&2 "Can't find tarfile $tarfile" 84 | exit 1 85 | fi 86 | do_check 87 | fi 88 | 89 | if [ "$opt_generate" = "on" ]; then 90 | populate "$outdir_old" 91 | dirname="`dirname $outdir_old`" 92 | basename="`basename $outdir_old`" 93 | tar czf "$tarfile" -C "$dirname" "$basename" 94 | fi 95 | -------------------------------------------------------------------------------- /tests/pycrc/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | _ __ _ _ ___ _ __ ___ 4 | | '_ \| | | |/ __| '__/ __| 5 | | |_) | |_| | (__| | | (__ 6 | | .__/ \__, |\___|_| \___| 7 | |_| |___/ 8 | 9 | http://www.tty1.net/pycrc/ 10 | 11 | 12 | pycrc is a free, easy to use Cyclic Redundancy Check (CRC) calculator and 13 | C source code generator. 14 | 15 | 16 | 17 | System Requirements 18 | =================== 19 | 20 | pycrc requires Python 2.6 or later. Python 3.x is supported. 21 | The last version compatible with Python 2.4 is pycrc v0.7.10. 22 | 23 | 24 | 25 | Installation 26 | ============ 27 | 28 | This program doesn't need any particular installation. The script can be 29 | called from any directory. 30 | Simply call the python interpreter with the script as parameter: 31 | 32 | python pycrc.py [options] 33 | 34 | On UNIX-like systems, you might want to make the script executable: 35 | 36 | chmod +x pycrc.py 37 | 38 | Then the script can be called like an application. 39 | 40 | ./pycrc.py [options] 41 | 42 | 43 | 44 | Getting help 45 | ============ 46 | 47 | If you are new to pycrc and want to generate C code, start with 48 | [the tutorial](http://www.tty1.net/pycrc/tutorial_en.html). 49 | 50 | The [pycrc manual page](http://www.tty1.net/pycrc/pycrc.html) explains the command 51 | line options in some detail and also gives some more examples how to use pycrc. 52 | 53 | If you have questions about using pycrc which is not answered in a satisfactory 54 | way by the documentation, please send a mail to the pycrc user mailing list 55 | . Subscribe to the mailing list 56 | [pycrc users list](https://lists.sourceforge.net/lists/listinfo/pycrc-users). 57 | Due to excessive spamming a subscription is required to post on the list. 58 | 59 | If you have found a bug in pycrc, please take the time and file it to the 60 | [bug tracker](http://sourceforge.net/p/pycrc/bugs/) or record a 61 | [feature request](http://sourceforge.net/p/pycrc/feature-requests/). 62 | Thanks for your collaboration. 63 | 64 | Also see the [frequently asked questions](http://www.tty1.net/pycrc/faq.html). 65 | 66 | 67 | 68 | Feedback 69 | ======== 70 | 71 | If you like pycrc, let me know and drop me a note. If you don't like pycrc let 72 | me know what you don't like and why. In both cases, I would really appreciate 73 | some [feed back](http://sourceforge.net/projects/pycrc/reviews/). 74 | If you want some idea how to say thanks for this software, please have a look 75 | [here](http://www.tty1.net/say-thanks_en.html). 76 | 77 | 78 | 79 | Copyright of the generated source code 80 | ====================================== 81 | 82 | Prior to v0.6, pycrc was released under the GPL and an additional addition to 83 | the licence was required to permit to use the generated source code in products 84 | with a OSI unapproved licence. As of version 0.6, pycrc is released under the 85 | terms of the MIT licence and such an additional clause to the licence is no 86 | more required. 87 | The code generated by pycrc is not considered a substantial portion of the 88 | software, therefore the licence does not cover the generated code, and the 89 | author of pycrc will not claim any copyright on the generated code. 90 | -------------------------------------------------------------------------------- /src/calculators/crc24.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-drive --model=crc-24 --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x000000, 0x864cfb, 0x8ad50d, 0x0c99f6, 0x93e6e1, 0x15aa1a, 0x1933ec, 0x9f7f17, 0xa18139, 6 | 0x27cdc2, 0x2b5434, 0xad18cf, 0x3267d8, 0xb42b23, 0xb8b2d5, 0x3efe2e, 0xc54e89, 0x430272, 7 | 0x4f9b84, 0xc9d77f, 0x56a868, 0xd0e493, 0xdc7d65, 0x5a319e, 0x64cfb0, 0xe2834b, 0xee1abd, 8 | 0x685646, 0xf72951, 0x7165aa, 0x7dfc5c, 0xfbb0a7, 0x0cd1e9, 0x8a9d12, 0x8604e4, 0x00481f, 9 | 0x9f3708, 0x197bf3, 0x15e205, 0x93aefe, 0xad50d0, 0x2b1c2b, 0x2785dd, 0xa1c926, 0x3eb631, 10 | 0xb8faca, 0xb4633c, 0x322fc7, 0xc99f60, 0x4fd39b, 0x434a6d, 0xc50696, 0x5a7981, 0xdc357a, 11 | 0xd0ac8c, 0x56e077, 0x681e59, 0xee52a2, 0xe2cb54, 0x6487af, 0xfbf8b8, 0x7db443, 0x712db5, 12 | 0xf7614e, 0x19a3d2, 0x9fef29, 0x9376df, 0x153a24, 0x8a4533, 0x0c09c8, 0x00903e, 0x86dcc5, 13 | 0xb822eb, 0x3e6e10, 0x32f7e6, 0xb4bb1d, 0x2bc40a, 0xad88f1, 0xa11107, 0x275dfc, 0xdced5b, 14 | 0x5aa1a0, 0x563856, 0xd074ad, 0x4f0bba, 0xc94741, 0xc5deb7, 0x43924c, 0x7d6c62, 0xfb2099, 15 | 0xf7b96f, 0x71f594, 0xee8a83, 0x68c678, 0x645f8e, 0xe21375, 0x15723b, 0x933ec0, 0x9fa736, 16 | 0x19ebcd, 0x8694da, 0x00d821, 0x0c41d7, 0x8a0d2c, 0xb4f302, 0x32bff9, 0x3e260f, 0xb86af4, 17 | 0x2715e3, 0xa15918, 0xadc0ee, 0x2b8c15, 0xd03cb2, 0x567049, 0x5ae9bf, 0xdca544, 0x43da53, 18 | 0xc596a8, 0xc90f5e, 0x4f43a5, 0x71bd8b, 0xf7f170, 0xfb6886, 0x7d247d, 0xe25b6a, 0x641791, 19 | 0x688e67, 0xeec29c, 0x3347a4, 0xb50b5f, 0xb992a9, 0x3fde52, 0xa0a145, 0x26edbe, 0x2a7448, 20 | 0xac38b3, 0x92c69d, 0x148a66, 0x181390, 0x9e5f6b, 0x01207c, 0x876c87, 0x8bf571, 0x0db98a, 21 | 0xf6092d, 0x7045d6, 0x7cdc20, 0xfa90db, 0x65efcc, 0xe3a337, 0xef3ac1, 0x69763a, 0x578814, 22 | 0xd1c4ef, 0xdd5d19, 0x5b11e2, 0xc46ef5, 0x42220e, 0x4ebbf8, 0xc8f703, 0x3f964d, 0xb9dab6, 23 | 0xb54340, 0x330fbb, 0xac70ac, 0x2a3c57, 0x26a5a1, 0xa0e95a, 0x9e1774, 0x185b8f, 0x14c279, 24 | 0x928e82, 0x0df195, 0x8bbd6e, 0x872498, 0x016863, 0xfad8c4, 0x7c943f, 0x700dc9, 0xf64132, 25 | 0x693e25, 0xef72de, 0xe3eb28, 0x65a7d3, 0x5b59fd, 0xdd1506, 0xd18cf0, 0x57c00b, 0xc8bf1c, 26 | 0x4ef3e7, 0x426a11, 0xc426ea, 0x2ae476, 0xaca88d, 0xa0317b, 0x267d80, 0xb90297, 0x3f4e6c, 27 | 0x33d79a, 0xb59b61, 0x8b654f, 0x0d29b4, 0x01b042, 0x87fcb9, 0x1883ae, 0x9ecf55, 0x9256a3, 28 | 0x141a58, 0xefaaff, 0x69e604, 0x657ff2, 0xe33309, 0x7c4c1e, 0xfa00e5, 0xf69913, 0x70d5e8, 29 | 0x4e2bc6, 0xc8673d, 0xc4fecb, 0x42b230, 0xddcd27, 0x5b81dc, 0x57182a, 0xd154d1, 0x26359f, 30 | 0xa07964, 0xace092, 0x2aac69, 0xb5d37e, 0x339f85, 0x3f0673, 0xb94a88, 0x87b4a6, 0x01f85d, 31 | 0x0d61ab, 0x8b2d50, 0x145247, 0x921ebc, 0x9e874a, 0x18cbb1, 0xe37b16, 0x6537ed, 0x69ae1b, 32 | 0xefe2e0, 0x709df7, 0xf6d10c, 0xfa48fa, 0x7c0401, 0x42fa2f, 0xc4b6d4, 0xc82f22, 0x4e63d9, 33 | 0xd11cce, 0x575035, 0x5bc9c3, 0xdd8538, 34 | ]; 35 | 36 | if (typeof Int32Array !== 'undefined') { 37 | TABLE = new Int32Array(TABLE); 38 | } 39 | 40 | const crc24: CRCCalculator = (current, previous) => { 41 | let crc = typeof previous !== 'undefined' ? ~~previous : 0xb704ce; 42 | 43 | for (let index = 0; index < current.length; index++) { 44 | crc = (TABLE[((crc >> 16) ^ current[index]) & 0xff] ^ (crc << 8)) & 0xffffff; 45 | } 46 | 47 | return crc; 48 | }; 49 | 50 | export default crc24; 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # crc 2 | 3 | Functions for calculating Cyclic Redundancy Checks (CRC) values for the Node.js and front-end. 4 | 5 | ## Features 6 | 7 | - Written in TypeScript and provides typings out of the box. 8 | - Supports ESM and CommonJS. 9 | - Pure JavaScript implementation, no native dependencies. 10 | - Full test suite using `pycrc` as a refenrence. 11 | - Supports for the following CRC algorithms: 12 | - CRC1 (`crc1`) 13 | - CRC8 (`crc8`) 14 | - CRC8 1-Wire (`crc81wire`) 15 | - CRC8 DVB-S2 (`crc8dvbs2`) 16 | - CRC16 (`crc16`) 17 | - CRC16 CCITT (`crc16ccitt`) 18 | - CRC16 Modbus (`crc16modbus`) 19 | - CRC16 Kermit (`crc16kermit`) 20 | - CRC16 XModem (`crc16xmodem`) 21 | - CRC24 (`crc24`) 22 | - CRC32 (`crc32`) 23 | - CRC32 MPEG-2 (`crc32mpeg2`) 24 | - CRCJAM (`crcjam`) 25 | 26 | ## Installation 27 | 28 | ``` 29 | npm install crc 30 | ``` 31 | 32 | ## Usage 33 | 34 | Using specific CRC is the recommended way to reduce bundle size: 35 | 36 | ```js 37 | import crc32 from 'crc/crc32'; 38 | crc32('hello').toString(16); 39 | // "3610a686" 40 | ``` 41 | 42 | Alternatively you can use main default export: 43 | 44 | ```js 45 | import crc from 'crc'; 46 | crc.crc32('hello').toString(16); 47 | // "3610a686" 48 | ``` 49 | 50 | If you really wish to minimize bundle size, you can import CRC calculators directly and pass an instance of `Int8Array`: 51 | 52 | ```js 53 | import crc32 from 'crc/calculators/crc32'; 54 | const helloWorld = new Int8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]); 55 | crc32(helloWorld).toString(16); 56 | // "3610a686" 57 | ``` 58 | 59 | CommonJS is supported as well without the need to unwrap `.default`: 60 | 61 | ```js 62 | const crc32 = require('crc/crc32'); 63 | crc32('hello').toString(16); 64 | // "3610a686" 65 | ``` 66 | 67 | Calculate a CRC32 of a file: 68 | 69 | ```js 70 | crc32(fs.readFileSync('README.md', 'utf-8')).toString(16); 71 | // "127ad531" 72 | ``` 73 | 74 | Or using a `Buffer`: 75 | 76 | ```js 77 | crc32(fs.readFileSync('README.md', 'utf-8')).toString(16); 78 | // "127ad531" 79 | ``` 80 | 81 | Incrementally calculate a CRC: 82 | 83 | ```js 84 | let value = crc32('one'); 85 | value = crc32('two', value); 86 | value = crc32('three', value); 87 | value.toString(16); 88 | // "9e1c092" 89 | ``` 90 | 91 | ## Tests 92 | 93 | ``` 94 | npm test 95 | ``` 96 | 97 | ## Thanks! 98 | 99 | [pycrc](http://www.tty1.net/pycrc/) library is which the source of all of the CRC tables. 100 | 101 | # License 102 | 103 | The MIT License (MIT) 104 | 105 | Copyright (c) 2014 Alex Gorbatchev 106 | 107 | Permission is hereby granted, free of charge, to any person obtaining a copy 108 | of this software and associated documentation files (the "Software"), to deal 109 | in the Software without restriction, including without limitation the rights 110 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 111 | copies of the Software, and to permit persons to whom the Software is 112 | furnished to do so, subject to the following conditions: 113 | 114 | The above copyright notice and this permission notice shall be included in 115 | all copies or substantial portions of the Software. 116 | 117 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 118 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 119 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 120 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 121 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 122 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 123 | THE SOFTWARE. 124 | -------------------------------------------------------------------------------- /src/calculators/crcjam.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --model=jam --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 6 | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 7 | 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 8 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 9 | 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 10 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 11 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 12 | 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 13 | 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 14 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 15 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 16 | 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 17 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 18 | 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 19 | 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 20 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 21 | 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 22 | 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 23 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 24 | 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 25 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 26 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 27 | 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 28 | 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 29 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 30 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 31 | 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 32 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 33 | 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 34 | 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 35 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 36 | 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, 37 | ]; 38 | 39 | if (typeof Int32Array !== 'undefined') { 40 | TABLE = new Int32Array(TABLE); 41 | } 42 | 43 | const crcjam: CRCCalculator = (current, previous = -1) => { 44 | let crc = previous === 0 ? 0 : ~~previous; 45 | 46 | for (let index = 0; index < current.length; index++) { 47 | crc = TABLE[(crc ^ current[index]) & 0xff] ^ (crc >>> 8); 48 | } 49 | 50 | return crc; 51 | }; 52 | 53 | export default crcjam; 54 | -------------------------------------------------------------------------------- /src/calculators/crc32mpeg2.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --model=crc-32-mpeg --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, 6 | 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 7 | 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, 8 | 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, 9 | 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 10 | 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, 11 | 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, 12 | 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 13 | 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, 14 | 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 15 | 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 16 | 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, 17 | 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, 18 | 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 19 | 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 20 | 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a, 21 | 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 22 | 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, 23 | 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, 24 | 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 25 | 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, 26 | 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, 27 | 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 28 | 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, 29 | 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 30 | 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 31 | 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, 32 | 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 33 | 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 34 | 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 35 | 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, 36 | 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4, 37 | ]; 38 | 39 | if (typeof Int32Array !== 'undefined') { 40 | TABLE = new Int32Array(TABLE); 41 | } 42 | 43 | const crc32mpeg2: CRCCalculator = (current, previous) => { 44 | let crc = typeof previous !== 'undefined' ? ~~previous : 0xffffffff; 45 | 46 | for (let index = 0; index < current.length; index++) { 47 | crc = TABLE[((crc >> 24) ^ current[index]) & 0xff] ^ (crc << 8); 48 | } 49 | 50 | return crc; 51 | }; 52 | 53 | export default crc32mpeg2; 54 | -------------------------------------------------------------------------------- /src/calculators/crc32.ts: -------------------------------------------------------------------------------- 1 | import { CRCCalculator } from '../types.js'; 2 | 3 | // Generated by `./pycrc.py --algorithm=table-driven --model=crc-32 --generate=c` 4 | let TABLE: Array | Int32Array = [ 5 | 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 6 | 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 7 | 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 8 | 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 9 | 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 10 | 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 11 | 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 12 | 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 13 | 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 14 | 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 15 | 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 16 | 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 17 | 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 18 | 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 19 | 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 20 | 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 21 | 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 22 | 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 23 | 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 24 | 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 25 | 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 26 | 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 27 | 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 28 | 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 29 | 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 30 | 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 31 | 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 32 | 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 33 | 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 34 | 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 35 | 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 36 | 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, 37 | ]; 38 | 39 | if (typeof Int32Array !== 'undefined') { 40 | TABLE = new Int32Array(TABLE); 41 | } 42 | 43 | const crc32: CRCCalculator = (current, previous) => { 44 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion 45 | let crc = previous === 0 ? 0 : ~~previous! ^ -1; 46 | 47 | for (let index = 0; index < current.length; index++) { 48 | crc = TABLE[(crc ^ current[index]) & 0xff] ^ (crc >>> 8); 49 | } 50 | 51 | return crc ^ -1; 52 | }; 53 | 54 | export default crc32; 55 | -------------------------------------------------------------------------------- /tests/test_helpers.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | import chai from 'chai'; 3 | import { exec } from 'child_process'; 4 | import { CRCModule } from './.build/types'; 5 | 6 | const TEST_VALUES = [ 7 | '1234567890', 8 | 'cwd String Current working directory of the child process', 9 | 'env Object Environment key-value pairs', 10 | "encoding String (Default: 'utf8')", 11 | 'timeout Number (Default: 0)', 12 | 'maxBuffer Number (Default: 200*1024)', 13 | "killSignal String (Default: 'SIGTERM')", 14 | ]; 15 | 16 | chai.should(); 17 | 18 | type Callback = (err?: Error | null, result?: string | number) => void; 19 | 20 | function getReferenceValueForBuffer( 21 | model: string, 22 | buffer: Buffer, 23 | initial: number | undefined, 24 | expected: string | undefined, 25 | callback: Callback, 26 | ) { 27 | if (expected) { 28 | callback(null, expected); 29 | } else { 30 | const initialArg = typeof initial !== 'undefined' ? `--xor-in=0x${initial.toString(16)}` : ''; 31 | const filename = `${__dirname}/tmp`; 32 | const cmd = `pycrc.py --model=${model} ${initialArg} --check-file="${filename}"`; 33 | 34 | fs.writeFileSync(filename, buffer); 35 | 36 | exec(`${__dirname}/pycrc/${cmd}`, (err, reference) => { 37 | fs.unlinkSync(filename); 38 | callback(err, (reference || '').replace(/^0x|\n$/g, '')); 39 | }); 40 | } 41 | } 42 | 43 | function getReferenceValueForString( 44 | model: string, 45 | checkString: string, 46 | initial: number | undefined, 47 | expected: string | undefined, 48 | callback: Callback, 49 | ) { 50 | if (expected) { 51 | callback(null, expected); 52 | } else { 53 | const initialArg = typeof initial !== 'undefined' ? `--xor-in=0x${initial.toString(16)}` : ''; 54 | const cmd = `pycrc.py --model=${model} ${initialArg} --check-string="${checkString}"`; 55 | exec(`${__dirname}/pycrc/${cmd}`, (err, reference) => 56 | callback(err, (reference || '').replace(/^0x|\n$/g, '')), 57 | ); 58 | } 59 | } 60 | 61 | function testStringValue( 62 | crc: CRCModule, 63 | checkString: string, 64 | initial: number | undefined, 65 | expected: string | undefined, 66 | callback: Callback, 67 | ) { 68 | getReferenceValueForString(crc.model, checkString, initial, expected, (err, reference) => { 69 | if (err) { 70 | callback(err); 71 | } else { 72 | crc(checkString, initial).toString(16).should.equal(reference); 73 | callback(); 74 | } 75 | }); 76 | } 77 | 78 | function testBufferValue( 79 | crc: CRCModule, 80 | buffer: Buffer, 81 | initial: number | undefined, 82 | expected: string | undefined, 83 | callback: Callback, 84 | ) { 85 | getReferenceValueForBuffer(crc.model, buffer, initial, expected, (err, reference) => { 86 | if (err) { 87 | callback(err); 88 | } else { 89 | crc(buffer, initial).toString(16).should.equal(reference); 90 | callback(); 91 | } 92 | }); 93 | } 94 | 95 | function testStringSplitValue( 96 | crc: CRCModule, 97 | testValue: string, 98 | initial: number | undefined, 99 | expected: string | undefined, 100 | callback: Callback, 101 | ) { 102 | const middle = testValue.length / 2; 103 | const chunk1 = testValue.substr(0, middle); 104 | const chunk2 = testValue.substr(middle); 105 | const v1 = crc(chunk1, initial); 106 | const v2 = crc(chunk2, v1); 107 | 108 | getReferenceValueForString(crc.model, testValue, initial, expected, (err, reference) => { 109 | if (err) { 110 | callback(err); 111 | } else { 112 | v2.toString(16).should.equal(reference); 113 | callback(); 114 | } 115 | }); 116 | } 117 | 118 | function testBufferSplitValue( 119 | crc: CRCModule, 120 | testValue: Buffer, 121 | initial: number | undefined, 122 | expected: string | undefined, 123 | callback: Callback, 124 | ) { 125 | const middle = testValue.length / 2; 126 | const chunk1 = testValue.slice(0, middle); 127 | const chunk2 = testValue.slice(middle); 128 | const v1 = crc(chunk1, initial); 129 | const v2 = crc(chunk2, v1); 130 | 131 | getReferenceValueForBuffer(crc.model, testValue, initial, expected, (err, reference) => { 132 | if (err) { 133 | callback(err); 134 | } else { 135 | v2.toString(16).should.equal(reference); 136 | callback(); 137 | } 138 | }); 139 | } 140 | 141 | interface Params { 142 | crc: CRCModule; 143 | value?: string | Buffer; 144 | expected?: string; 145 | initial?: number; 146 | } 147 | 148 | export default function crcSuiteFor({ crc, value, expected, initial }: Params): void { 149 | if (value) { 150 | if (Buffer.isBuffer(value)) { 151 | describe(`BUFFER: ${value.toString('base64')}`, () => { 152 | it('should calculate a full checksum', done => 153 | testBufferValue(crc, value, initial, expected, done)); 154 | it('should calculate a checksum for multiple data', done => 155 | testBufferSplitValue(crc, value, initial, expected, done)); 156 | }); 157 | } else { 158 | describe(`STRING: ${value}`, () => { 159 | it('should calculate a full checksum', done => 160 | testStringValue(crc, value, initial, expected, done)); 161 | it('should calculate a checksum for multiple data', done => 162 | testStringSplitValue(crc, value, initial, expected, done)); 163 | }); 164 | } 165 | } else { 166 | TEST_VALUES.forEach(testValue => 167 | describe(`STRING: ${testValue}`, () => { 168 | it('should calculate a full checksum', done => 169 | testStringValue(crc, testValue, initial, expected, done)); 170 | it('should calculate a full checksum with initial 0x0', done => 171 | testStringValue(crc, testValue, 0, expected, done)); 172 | it('should calculate a checksum for multiple data', done => 173 | testStringSplitValue(crc, testValue, initial, expected, done)); 174 | it('should calculate a checksum for multiple data with initial 0x0', done => 175 | testStringSplitValue(crc, testValue, 0, expected, done)); 176 | }), 177 | ); 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /tests/pycrc/test/performance.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | PYCRC=`dirname $0`/../pycrc.py 5 | 6 | function cleanup { 7 | rm -f a.out performance.c crc_bbb.[ch] crc_bbf.[ch] crc_tb[l4].[ch] crc_bw[e4].[ch] 8 | } 9 | 10 | trap cleanup 0 1 2 3 15 11 | 12 | 13 | prefix=bbb 14 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate c -o crc_$prefix.c --algo bit-by-bit 15 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate h -o crc_$prefix.h --algo bit-by-bit 16 | prefix=bbf 17 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate h -o crc_$prefix.h --algo bit-by-bit-fast 18 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate c -o crc_$prefix.c --algo bit-by-bit-fast 19 | prefix=tbl 20 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate h -o crc_$prefix.h --algo table-driven 21 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate c -o crc_$prefix.c --algo table-driven 22 | prefix=tb4 23 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate h -o crc_$prefix.h --algo table-driven --table-idx-width 4 24 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate c -o crc_$prefix.c --algo table-driven --table-idx-width 4 25 | prefix=bwe 26 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate h -o crc_$prefix.h --algo bitwise-expression 27 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate c -o crc_$prefix.c --algo bitwise-expression 28 | prefix=bw4 29 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate h -o crc_$prefix.h --algo bitwise-expression --table-idx-width 4 30 | $PYCRC --model crc-32 --symbol-prefix crc_${prefix}_ --generate c -o crc_$prefix.c --algo bitwise-expression --table-idx-width 4 31 | 32 | 33 | function print_main { 34 | cat < 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #define NUM_RUNS (256*256) 49 | 50 | unsigned char buf[1024]; 51 | 52 | void test_bbb(unsigned char *buf, size_t buf_len, size_t num_runs, clock_t clock_per_sec); 53 | void test_bbf(unsigned char *buf, size_t buf_len, size_t num_runs, clock_t clock_per_sec); 54 | void test_tbl(unsigned char *buf, size_t buf_len, size_t num_runs, clock_t clock_per_sec); 55 | void test_tb4(unsigned char *buf, size_t buf_len, size_t num_runs, clock_t clock_per_sec); 56 | void test_bwe(unsigned char *buf, size_t buf_len, size_t num_runs, clock_t clock_per_sec); 57 | void test_bw4(unsigned char *buf, size_t buf_len, size_t num_runs, clock_t clock_per_sec); 58 | 59 | /** 60 | * Print results. 61 | * 62 | * \param dsc Description of the test 63 | * \param crc Resulting CRC 64 | * \param buflen Length of one buffer 65 | * \param num_runs Number of runs over that buffer 66 | * \param t_user user time 67 | * \param t_sys system time 68 | * \return void 69 | *****************************************************************************/ 70 | void show_times(const char *dsc, unsigned int crc, size_t buflen, size_t num_runs, double t_user, double t_sys) 71 | { 72 | printf("%s of %ld bytes (%ld * %ld): 0x%08x\n", dsc, (long)buflen*num_runs, (long)buflen, (long)num_runs, crc); 73 | printf("%13s: %7.3f s\n", "user time", t_user); 74 | printf("%13s: %7.3f s\n", "system time", t_sys); 75 | printf("\n"); 76 | } 77 | 78 | 79 | /** 80 | * C main function. 81 | * 82 | * \retval 0 on success 83 | * \retval 1 on failure 84 | *****************************************************************************/ 85 | int main(void) 86 | { 87 | unsigned int i; 88 | long int clock_per_sec; 89 | 90 | for (i = 0; i < sizeof(buf); i++) { 91 | buf[i] = (unsigned char)rand(); 92 | } 93 | clock_per_sec = sysconf(_SC_CLK_TCK); 94 | 95 | // bit-by-bit 96 | test_bbb(buf, sizeof(buf), NUM_RUNS, clock_per_sec); 97 | 98 | // bit-by-bit-fast 99 | test_bbf(buf, sizeof(buf), NUM_RUNS, clock_per_sec); 100 | 101 | // table-driven 102 | test_tbl(buf, sizeof(buf), NUM_RUNS, clock_per_sec); 103 | 104 | // table-driven idx4 105 | test_tb4(buf, sizeof(buf), NUM_RUNS, clock_per_sec); 106 | 107 | // bitwise-expression 108 | test_bwe(buf, sizeof(buf), NUM_RUNS, clock_per_sec); 109 | 110 | // table-driven idx4 111 | test_bw4(buf, sizeof(buf), NUM_RUNS, clock_per_sec); 112 | 113 | return 0; 114 | } 115 | EOF 116 | } 117 | 118 | function print_routine { 119 | algo=$1 120 | prefix=$2 121 | cat < performance.c 162 | print_routine "bit-by-bit" bbb >> performance.c 163 | print_routine "bit-by-bit-fast" bbf >> performance.c 164 | print_routine "table-driven" tbl >> performance.c 165 | print_routine "table-driven idx4" tb4 >> performance.c 166 | print_routine "bitwise-expression" bwe >> performance.c 167 | print_routine "bitwise-expression idx4" bw4 >> performance.c 168 | 169 | gcc -W -Wall -O3 crc_bbb.c crc_bbf.c crc_tbl.c crc_tb4.c crc_bwe.c crc_bw4.c performance.c 170 | ./a.out 171 | -------------------------------------------------------------------------------- /dist/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc", 3 | "version": "4.3.2", 4 | "description": "Module for calculating Cyclic Redundancy Check (CRC) for Node.js and the browser.", 5 | "author": { 6 | "name": "Alex Gorbatchev", 7 | "url": "https://github.com/alexgorbatchev" 8 | }, 9 | "homepage": "https://github.com/alexgorbatchev/crc", 10 | "bugs": "https://github.com/alexgorbatchev/crc/issues", 11 | "repository": "alexgorbatchev/crc", 12 | "license": "MIT", 13 | "keywords": [ 14 | "crc", 15 | "crc16ccitt", 16 | "crc16kermit", 17 | "crc16modbus", 18 | "crc16", 19 | "crc16xmodem", 20 | "crc1", 21 | "crc24", 22 | "crc32", 23 | "crc81wire", 24 | "crc8", 25 | "crc8dvbs2", 26 | "crcjam" 27 | ], 28 | "type": "module", 29 | "types": "./mjs/index.d.ts", 30 | "main": "./cjs-default-unwrap/index.js", 31 | "module": "./mjs/index.js", 32 | "exports": { 33 | ".": { 34 | "types": "./mjs/index.d.ts", 35 | "import": "./mjs/index.js", 36 | "require": "./cjs-default-unwrap/index.js" 37 | }, 38 | "./crc16ccitt": { 39 | "types": "./mjs/crc16ccitt.d.ts", 40 | "import": "./mjs/crc16ccitt.js", 41 | "require": "./cjs-default-unwrap/crc16ccitt.js" 42 | }, 43 | "./calculators/crc16ccitt": { 44 | "types": "./mjs/calculators/crc16ccitt.d.ts", 45 | "import": "./mjs/calculators/crc16ccitt.js", 46 | "require": "./cjs-default-unwrap/calculators/crc16ccitt.js" 47 | }, 48 | "./crc16kermit": { 49 | "types": "./mjs/crc16kermit.d.ts", 50 | "import": "./mjs/crc16kermit.js", 51 | "require": "./cjs-default-unwrap/crc16kermit.js" 52 | }, 53 | "./calculators/crc16kermit": { 54 | "types": "./mjs/calculators/crc16kermit.d.ts", 55 | "import": "./mjs/calculators/crc16kermit.js", 56 | "require": "./cjs-default-unwrap/calculators/crc16kermit.js" 57 | }, 58 | "./crc16modbus": { 59 | "types": "./mjs/crc16modbus.d.ts", 60 | "import": "./mjs/crc16modbus.js", 61 | "require": "./cjs-default-unwrap/crc16modbus.js" 62 | }, 63 | "./calculators/crc16modbus": { 64 | "types": "./mjs/calculators/crc16modbus.d.ts", 65 | "import": "./mjs/calculators/crc16modbus.js", 66 | "require": "./cjs-default-unwrap/calculators/crc16modbus.js" 67 | }, 68 | "./crc16": { 69 | "types": "./mjs/crc16.d.ts", 70 | "import": "./mjs/crc16.js", 71 | "require": "./cjs-default-unwrap/crc16.js" 72 | }, 73 | "./calculators/crc16": { 74 | "types": "./mjs/calculators/crc16.d.ts", 75 | "import": "./mjs/calculators/crc16.js", 76 | "require": "./cjs-default-unwrap/calculators/crc16.js" 77 | }, 78 | "./crc16xmodem": { 79 | "types": "./mjs/crc16xmodem.d.ts", 80 | "import": "./mjs/crc16xmodem.js", 81 | "require": "./cjs-default-unwrap/crc16xmodem.js" 82 | }, 83 | "./calculators/crc16xmodem": { 84 | "types": "./mjs/calculators/crc16xmodem.d.ts", 85 | "import": "./mjs/calculators/crc16xmodem.js", 86 | "require": "./cjs-default-unwrap/calculators/crc16xmodem.js" 87 | }, 88 | "./crc1": { 89 | "types": "./mjs/crc1.d.ts", 90 | "import": "./mjs/crc1.js", 91 | "require": "./cjs-default-unwrap/crc1.js" 92 | }, 93 | "./calculators/crc1": { 94 | "types": "./mjs/calculators/crc1.d.ts", 95 | "import": "./mjs/calculators/crc1.js", 96 | "require": "./cjs-default-unwrap/calculators/crc1.js" 97 | }, 98 | "./crc24": { 99 | "types": "./mjs/crc24.d.ts", 100 | "import": "./mjs/crc24.js", 101 | "require": "./cjs-default-unwrap/crc24.js" 102 | }, 103 | "./calculators/crc24": { 104 | "types": "./mjs/calculators/crc24.d.ts", 105 | "import": "./mjs/calculators/crc24.js", 106 | "require": "./cjs-default-unwrap/calculators/crc24.js" 107 | }, 108 | "./crc32": { 109 | "types": "./mjs/crc32.d.ts", 110 | "import": "./mjs/crc32.js", 111 | "require": "./cjs-default-unwrap/crc32.js" 112 | }, 113 | "./calculators/crc32": { 114 | "types": "./mjs/calculators/crc32.d.ts", 115 | "import": "./mjs/calculators/crc32.js", 116 | "require": "./cjs-default-unwrap/calculators/crc32.js" 117 | }, 118 | "./crc32mpeg2": { 119 | "types": "./mjs/crc32mpeg2.d.ts", 120 | "import": "./mjs/crc32mpeg2.js", 121 | "require": "./cjs-default-unwrap/crc32mpeg2.js" 122 | }, 123 | "./calculators/crc32mpeg2": { 124 | "types": "./mjs/calculators/crc32mpeg2.d.ts", 125 | "import": "./mjs/calculators/crc32mpeg2.js", 126 | "require": "./cjs-default-unwrap/calculators/crc32mpeg2.js" 127 | }, 128 | "./crc81wire": { 129 | "types": "./mjs/crc81wire.d.ts", 130 | "import": "./mjs/crc81wire.js", 131 | "require": "./cjs-default-unwrap/crc81wire.js" 132 | }, 133 | "./calculators/crc81wire": { 134 | "types": "./mjs/calculators/crc81wire.d.ts", 135 | "import": "./mjs/calculators/crc81wire.js", 136 | "require": "./cjs-default-unwrap/calculators/crc81wire.js" 137 | }, 138 | "./crc8": { 139 | "types": "./mjs/crc8.d.ts", 140 | "import": "./mjs/crc8.js", 141 | "require": "./cjs-default-unwrap/crc8.js" 142 | }, 143 | "./calculators/crc8": { 144 | "types": "./mjs/calculators/crc8.d.ts", 145 | "import": "./mjs/calculators/crc8.js", 146 | "require": "./cjs-default-unwrap/calculators/crc8.js" 147 | }, 148 | "./crc8dvbs2": { 149 | "types": "./mjs/crc8dvbs2.d.ts", 150 | "import": "./mjs/crc8dvbs2.js", 151 | "require": "./cjs-default-unwrap/crc8dvbs2.js" 152 | }, 153 | "./calculators/crc8dvbs2": { 154 | "types": "./mjs/calculators/crc8dvbs2.d.ts", 155 | "import": "./mjs/calculators/crc8dvbs2.js", 156 | "require": "./cjs-default-unwrap/calculators/crc8dvbs2.js" 157 | }, 158 | "./crcjam": { 159 | "types": "./mjs/crcjam.d.ts", 160 | "import": "./mjs/crcjam.js", 161 | "require": "./cjs-default-unwrap/crcjam.js" 162 | }, 163 | "./calculators/crcjam": { 164 | "types": "./mjs/calculators/crcjam.d.ts", 165 | "import": "./mjs/calculators/crcjam.js", 166 | "require": "./cjs-default-unwrap/calculators/crcjam.js" 167 | } 168 | }, 169 | "sideEffects": false, 170 | "engines": { 171 | "node": ">=12" 172 | }, 173 | "files": [ 174 | "calculators", 175 | "cjs", 176 | "cjs-default-unwrap", 177 | "mjs", 178 | "*.js", 179 | "*.d.ts" 180 | ], 181 | "peerDependencies": { 182 | "buffer": ">=6.0.3" 183 | }, 184 | "peerDependenciesMeta": { 185 | "buffer": { 186 | "optional": true 187 | } 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /tests/pycrc/test/main.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2013 Thomas Pircher 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "crc.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | static bool atob(const char *str); 30 | static crc_t xtoi(const char *str); 31 | static int get_config(int argc, char *argv[], crc_cfg_t *cfg); 32 | #if CRC_ALGO_BIT_BY_BIT 33 | static crc_t crc_verify(const crc_cfg_t *cfg, crc_t crc_pre_final, crc_t crc); 34 | static crc_t crc_reflect(crc_t data, size_t data_len); 35 | #endif 36 | 37 | 38 | 39 | static bool verbose = false; 40 | static unsigned char str[256] = "123456789"; 41 | 42 | bool atob(const char *str) 43 | { 44 | if (!str) { 45 | return 0; 46 | } 47 | if (isdigit(str[0])) { 48 | return (bool)atoi(str); 49 | } 50 | if (tolower(str[0]) == 't') { 51 | return true; 52 | } 53 | return false; 54 | } 55 | 56 | crc_t xtoi(const char *str) 57 | { 58 | crc_t ret = 0; 59 | 60 | if (!str) { 61 | return 0; 62 | } 63 | if (str[0] == '0' && tolower(str[1]) == 'x') { 64 | str += 2; 65 | while (*str) { 66 | if (isdigit(*str)) 67 | ret = 16 * ret + *str - '0'; 68 | else if (isxdigit(*str)) 69 | ret = 16 * ret + tolower(*str) - 'a' + 10; 70 | else 71 | return ret; 72 | str++; 73 | } 74 | } else if (isdigit(*str)) { 75 | while (*str) { 76 | if (isdigit(*str)) 77 | ret = 10 * ret + *str - '0'; 78 | else 79 | return ret; 80 | str++; 81 | } 82 | } 83 | return ret; 84 | } 85 | 86 | 87 | int get_config(int argc, char *argv[], crc_cfg_t *cfg) 88 | { 89 | int c; 90 | int option_index; 91 | static struct option long_options[] = { 92 | {"width", 1, 0, 'w'}, 93 | {"poly", 1, 0, 'p'}, 94 | {"reflect-in", 1, 0, 'n'}, 95 | {"xor-in", 1, 0, 'i'}, 96 | {"reflect-out", 1, 0, 'u'}, 97 | {"xor-out", 1, 0, 'o'}, 98 | {"verbose", 0, 0, 'v'}, 99 | {"check-string", 1, 0, 's'}, 100 | {"table-idx-with", 1, 0, 't'}, 101 | {0, 0, 0, 0} 102 | }; 103 | 104 | while (1) { 105 | option_index = 0; 106 | 107 | c = getopt_long(argc, argv, "w:p:ni:uo:v", long_options, &option_index); 108 | if (c == -1) 109 | break; 110 | 111 | switch (c) { 112 | case 0: 113 | printf("option %s", long_options[option_index].name); 114 | if (optarg) 115 | printf(" with arg %s", optarg); 116 | printf ("\n"); 117 | case 'w': 118 | cfg->width = atoi(optarg); 119 | break; 120 | case 'p': 121 | cfg->poly = xtoi(optarg); 122 | break; 123 | case 'n': 124 | cfg->reflect_in = atob(optarg); 125 | break; 126 | case 'i': 127 | cfg->xor_in = xtoi(optarg); 128 | break; 129 | case 'u': 130 | cfg->reflect_out = atob(optarg); 131 | break; 132 | case 'o': 133 | cfg->xor_out = xtoi(optarg); 134 | break; 135 | case 's': 136 | memcpy(str, optarg, strlen(optarg) < sizeof(str) ? strlen(optarg) + 1 : sizeof(str)); 137 | str[sizeof(str) - 1] = '\0'; 138 | break; 139 | case 'v': 140 | verbose = true; 141 | break; 142 | case 't': 143 | // ignore --table_idx_width option 144 | break; 145 | case '?': 146 | return -1; 147 | case ':': 148 | fprintf(stderr, "missing argument to option %c\n", c); 149 | return -1; 150 | default: 151 | fprintf(stderr, "unhandled option %c\n", c); 152 | return -1; 153 | } 154 | } 155 | cfg->msb_mask = (crc_t)1u << (cfg->width - 1); 156 | cfg->crc_mask = (cfg->msb_mask - 1) | cfg->msb_mask; 157 | cfg->crc_shift = cfg->width < 8 ? 8 - cfg->width : 0; 158 | 159 | cfg->poly &= cfg->crc_mask; 160 | cfg->xor_in &= cfg->crc_mask; 161 | cfg->xor_out &= cfg->crc_mask; 162 | return 0; 163 | } 164 | 165 | 166 | #if CRC_ALGO_BIT_BY_BIT 167 | crc_t crc_verify(const crc_cfg_t *cfg, crc_t crc_pre_final, crc_t crc) 168 | { 169 | crc_t result; 170 | unsigned char data; 171 | unsigned int i; 172 | 173 | // don't verify if the width is not a multiple of 8 174 | if (cfg->width % 8) { 175 | return 0; 176 | } 177 | if (cfg->xor_out) { 178 | crc ^= cfg->xor_out; 179 | } 180 | if (cfg->reflect_out) { 181 | crc = crc_reflect(crc, cfg->width); 182 | } 183 | result = crc_pre_final; 184 | for (i = 0; i < cfg->width / 8; i++) { 185 | data = (crc >> (cfg->width - 8 * i - 8)) & 0xff; 186 | if (cfg->reflect_in) { 187 | data = crc_reflect(data, 8); 188 | } 189 | result = crc_update(cfg, result, &data, 1); 190 | } 191 | // no crc_finalize, because if the CRC calculation is correct, result == 0. 192 | // A crc_finalize would XOR-in again some ones into the solution. 193 | // In theory the finalize function of the bit-by-bit algorithm 194 | // would also loop over cfg->width zero bits, but since 195 | // a) result == 0, and 196 | // b) input data == 0 197 | // the output would always be zero 198 | return result; 199 | } 200 | 201 | crc_t crc_reflect(crc_t data, size_t data_len) 202 | { 203 | unsigned int i; 204 | crc_t ret; 205 | 206 | ret = 0; 207 | for (i = 0; i < data_len; i++) 208 | { 209 | if (data & 0x01) { 210 | ret = (ret << 1) | 1; 211 | } else { 212 | ret = ret << 1; 213 | } 214 | data >>= 1; 215 | } 216 | return ret; 217 | } 218 | #endif // CRC_ALGO_BIT_BY_BIT 219 | 220 | 221 | int main(int argc, char *argv[]) 222 | { 223 | crc_cfg_t cfg = { 224 | 0, // width 225 | 0, // poly 226 | 0, // xor_in 227 | 0, // reflect_in 228 | 0, // xor_out 229 | 0, // reflect_out 230 | 231 | 0, // crc_mask 232 | 0, // msb_mask 233 | 0, // crc_shift 234 | }; 235 | crc_t crc; 236 | crc_t crc_test, crc_pre_final; 237 | char format[20]; 238 | int ret, i; 239 | 240 | ret = get_config(argc, argv, &cfg); 241 | if (ret == 0) { 242 | # if CRC_ALGO_TABLE_DRIVEN 243 | crc_table_gen(&cfg); 244 | # endif // CRC_ALGO_TABLE_DRIVEN 245 | crc = crc_init(&cfg); 246 | crc = crc_pre_final = crc_update(&cfg, crc, str, strlen((char *)str)); 247 | crc = crc_finalize(&cfg, crc); 248 | 249 | # if CRC_ALGO_BIT_BY_BIT 250 | if (crc_verify(&cfg, crc_pre_final, crc) != 0) { 251 | fprintf(stderr, "error: crc verification failed\n"); 252 | return 1; 253 | } 254 | # endif 255 | 256 | // calculate the checksum again, but this time loop over the input 257 | // bytes one-by-one. 258 | crc_test = crc_init(&cfg); 259 | for (i = 0; str[i]; i++) 260 | { 261 | crc_test = crc_update(&cfg, crc_test, str + i, 1); 262 | } 263 | crc_test = crc_finalize(&cfg, crc_test); 264 | if (crc_test != crc) { 265 | fprintf(stderr, "error: crc loop verification failed\n"); 266 | return 1; 267 | } 268 | 269 | if (verbose) { 270 | snprintf(format, sizeof(format), "%%-16s = 0x%%0%dx\n", (unsigned int)(cfg.width + 3) / 4); 271 | printf("%-16s = %d\n", "width", (unsigned int)cfg.width); 272 | printf(format, "poly", (unsigned int)cfg.poly); 273 | printf("%-16s = %s\n", "reflect_in", cfg.reflect_in ? "true": "false"); 274 | printf(format, "xor_in", cfg.xor_in); 275 | printf("%-16s = %s\n", "reflect_out", cfg.reflect_out ? "true": "false"); 276 | printf(format, "xor_out", (unsigned int)cfg.xor_out); 277 | printf(format, "crc_mask", (unsigned int)cfg.crc_mask); 278 | printf(format, "msb_mask", (unsigned int)cfg.msb_mask); 279 | } 280 | printf("0x%llx\n", (unsigned long long int)crc); 281 | } 282 | return !ret; 283 | } 284 | -------------------------------------------------------------------------------- /tests/pycrc/crc_algorithms.py: -------------------------------------------------------------------------------- 1 | # pycrc -- parameterisable CRC calculation utility and C source code generator 2 | # 3 | # Copyright (c) 2006-2013 Thomas Pircher 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to 7 | # deal in the Software without restriction, including without limitation the 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | # sell copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | # IN THE SOFTWARE. 22 | 23 | 24 | """ 25 | CRC algorithms implemented in Python. 26 | If you want to study the Python implementation of the CRC routines, then this 27 | is a good place to start from. 28 | 29 | The algorithms Bit by Bit, Bit by Bit Fast and Table-Driven are implemented. 30 | 31 | This module can also be used as a library from within Python. 32 | 33 | Examples 34 | ======== 35 | 36 | This is an example use of the different algorithms: 37 | 38 | >>> from crc_algorithms import Crc 39 | >>> 40 | >>> crc = Crc(width = 16, poly = 0x8005, 41 | ... reflect_in = True, xor_in = 0x0000, 42 | ... reflect_out = True, xor_out = 0x0000) 43 | >>> print("0x%x" % crc.bit_by_bit("123456789")) 44 | >>> print("0x%x" % crc.bit_by_bit_fast("123456789")) 45 | >>> print("0x%x" % crc.table_driven("123456789")) 46 | """ 47 | 48 | # Class Crc 49 | ############################################################################### 50 | class Crc(object): 51 | """ 52 | A base class for CRC routines. 53 | """ 54 | 55 | # Class constructor 56 | ############################################################################### 57 | def __init__(self, width, poly, reflect_in, xor_in, reflect_out, xor_out, table_idx_width = None): 58 | """The Crc constructor. 59 | 60 | The parameters are as follows: 61 | width 62 | poly 63 | reflect_in 64 | xor_in 65 | reflect_out 66 | xor_out 67 | """ 68 | self.Width = width 69 | self.Poly = poly 70 | self.ReflectIn = reflect_in 71 | self.XorIn = xor_in 72 | self.ReflectOut = reflect_out 73 | self.XorOut = xor_out 74 | self.TableIdxWidth = table_idx_width 75 | 76 | self.MSB_Mask = 0x1 << (self.Width - 1) 77 | self.Mask = ((self.MSB_Mask - 1) << 1) | 1 78 | if self.TableIdxWidth != None: 79 | self.TableWidth = 1 << self.TableIdxWidth 80 | else: 81 | self.TableIdxWidth = 8 82 | self.TableWidth = 1 << self.TableIdxWidth 83 | 84 | self.DirectInit = self.XorIn 85 | self.NonDirectInit = self.__get_nondirect_init(self.XorIn) 86 | if self.Width < 8: 87 | self.CrcShift = 8 - self.Width 88 | else: 89 | self.CrcShift = 0 90 | 91 | 92 | # function __get_nondirect_init 93 | ############################################################################### 94 | def __get_nondirect_init(self, init): 95 | """ 96 | return the non-direct init if the direct algorithm has been selected. 97 | """ 98 | crc = init 99 | for i in range(self.Width): 100 | bit = crc & 0x01 101 | if bit: 102 | crc^= self.Poly 103 | crc >>= 1 104 | if bit: 105 | crc |= self.MSB_Mask 106 | return crc & self.Mask 107 | 108 | 109 | # function reflect 110 | ############################################################################### 111 | def reflect(self, data, width): 112 | """ 113 | reflect a data word, i.e. reverts the bit order. 114 | """ 115 | x = data & 0x01 116 | for i in range(width - 1): 117 | data >>= 1 118 | x = (x << 1) | (data & 0x01) 119 | return x 120 | 121 | 122 | # function bit_by_bit 123 | ############################################################################### 124 | def bit_by_bit(self, in_data): 125 | """ 126 | Classic simple and slow CRC implementation. This function iterates bit 127 | by bit over the augmented input message and returns the calculated CRC 128 | value at the end. 129 | """ 130 | # If the input data is a string, convert to bytes. 131 | if isinstance(in_data, str): 132 | in_data = [ord(c) for c in in_data] 133 | 134 | register = self.NonDirectInit 135 | for octet in in_data: 136 | if self.ReflectIn: 137 | octet = self.reflect(octet, 8) 138 | for i in range(8): 139 | topbit = register & self.MSB_Mask 140 | register = ((register << 1) & self.Mask) | ((octet >> (7 - i)) & 0x01) 141 | if topbit: 142 | register ^= self.Poly 143 | 144 | for i in range(self.Width): 145 | topbit = register & self.MSB_Mask 146 | register = ((register << 1) & self.Mask) 147 | if topbit: 148 | register ^= self.Poly 149 | 150 | if self.ReflectOut: 151 | register = self.reflect(register, self.Width) 152 | return register ^ self.XorOut 153 | 154 | 155 | # function bit_by_bit_fast 156 | ############################################################################### 157 | def bit_by_bit_fast(self, in_data): 158 | """ 159 | This is a slightly modified version of the bit-by-bit algorithm: it 160 | does not need to loop over the augmented bits, i.e. the Width 0-bits 161 | wich are appended to the input message in the bit-by-bit algorithm. 162 | """ 163 | # If the input data is a string, convert to bytes. 164 | if isinstance(in_data, str): 165 | in_data = [ord(c) for c in in_data] 166 | 167 | register = self.DirectInit 168 | for octet in in_data: 169 | if self.ReflectIn: 170 | octet = self.reflect(octet, 8) 171 | for i in range(8): 172 | topbit = register & self.MSB_Mask 173 | if octet & (0x80 >> i): 174 | topbit ^= self.MSB_Mask 175 | register <<= 1 176 | if topbit: 177 | register ^= self.Poly 178 | register &= self.Mask 179 | if self.ReflectOut: 180 | register = self.reflect(register, self.Width) 181 | return register ^ self.XorOut 182 | 183 | 184 | # function gen_table 185 | ############################################################################### 186 | def gen_table(self): 187 | """ 188 | This function generates the CRC table used for the table_driven CRC 189 | algorithm. The Python version cannot handle tables of an index width 190 | other than 8. See the generated C code for tables with different sizes 191 | instead. 192 | """ 193 | table_length = 1 << self.TableIdxWidth 194 | tbl = [0] * table_length 195 | for i in range(table_length): 196 | register = i 197 | if self.ReflectIn: 198 | register = self.reflect(register, self.TableIdxWidth) 199 | register = register << (self.Width - self.TableIdxWidth + self.CrcShift) 200 | for j in range(self.TableIdxWidth): 201 | if register & (self.MSB_Mask << self.CrcShift) != 0: 202 | register = (register << 1) ^ (self.Poly << self.CrcShift) 203 | else: 204 | register = (register << 1) 205 | if self.ReflectIn: 206 | register = self.reflect(register >> self.CrcShift, self.Width) << self.CrcShift 207 | tbl[i] = register & (self.Mask << self.CrcShift) 208 | return tbl 209 | 210 | 211 | # function table_driven 212 | ############################################################################### 213 | def table_driven(self, in_data): 214 | """ 215 | The Standard table_driven CRC algorithm. 216 | """ 217 | # If the input data is a string, convert to bytes. 218 | if isinstance(in_data, str): 219 | in_data = [ord(c) for c in in_data] 220 | 221 | tbl = self.gen_table() 222 | 223 | register = self.DirectInit << self.CrcShift 224 | if not self.ReflectIn: 225 | for octet in in_data: 226 | tblidx = ((register >> (self.Width - self.TableIdxWidth + self.CrcShift)) ^ octet) & 0xff 227 | register = ((register << (self.TableIdxWidth - self.CrcShift)) ^ tbl[tblidx]) & (self.Mask << self.CrcShift) 228 | register = register >> self.CrcShift 229 | else: 230 | register = self.reflect(register, self.Width + self.CrcShift) << self.CrcShift 231 | for octet in in_data: 232 | tblidx = ((register >> self.CrcShift) ^ octet) & 0xff 233 | register = ((register >> self.TableIdxWidth) ^ tbl[tblidx]) & (self.Mask << self.CrcShift) 234 | register = self.reflect(register, self.Width + self.CrcShift) & self.Mask 235 | 236 | if self.ReflectOut: 237 | register = self.reflect(register, self.Width) 238 | return register ^ self.XorOut 239 | 240 | -------------------------------------------------------------------------------- /tests/pycrc/pycrc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # pycrc -- parameterisable CRC calculation utility and C source code generator 4 | # 5 | # Copyright (c) 2006-2013 Thomas Pircher 6 | # 7 | # Permission is hereby granted, free of charge, to any person obtaining a copy 8 | # of this software and associated documentation files (the "Software"), to 9 | # deal in the Software without restriction, including without limitation the 10 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 11 | # sell copies of the Software, and to permit persons to whom the Software is 12 | # furnished to do so, subject to the following conditions: 13 | # 14 | # The above copyright notice and this permission notice shall be included in 15 | # all copies or substantial portions of the Software. 16 | # 17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 | # IN THE SOFTWARE. 24 | 25 | 26 | """ 27 | pycrc is a fully parameterisable Cyclic Redundancy Check (CRC) calculation 28 | utility and C source code generator written in Python. 29 | 30 | It can: 31 | - generate the checksum of a string 32 | - generate the checksum of a file 33 | - generate the C header file and source of any of the algorithms below 34 | 35 | It supports the following CRC algorithms: 36 | - bit-by-bit the basic algorithm which operates bit by bit on the 37 | augmented message 38 | - bit-by-bit-fast a variation of the simple bit-by-bit algorithm 39 | - table-driven the standard table driven algorithm 40 | """ 41 | 42 | from __future__ import print_function 43 | from crc_opt import Options 44 | from crc_algorithms import Crc 45 | from crc_parser import MacroParser, ParseError 46 | import binascii 47 | import sys 48 | 49 | 50 | # function print_parameters 51 | ############################################################################### 52 | def print_parameters(opt): 53 | """ 54 | Generate a string with the options pretty-printed (used in the --verbose mode). 55 | """ 56 | in_str = "" 57 | in_str += "Width = $crc_width\n" 58 | in_str += "Poly = $crc_poly\n" 59 | in_str += "ReflectIn = $crc_reflect_in\n" 60 | in_str += "XorIn = $crc_xor_in\n" 61 | in_str += "ReflectOut = $crc_reflect_out\n" 62 | in_str += "XorOut = $crc_xor_out\n" 63 | in_str += "Algorithm = $crc_algorithm\n" 64 | 65 | mp = MacroParser(opt) 66 | mp.parse(in_str) 67 | return mp.out_str 68 | 69 | 70 | # function check_string 71 | ############################################################################### 72 | def check_string(opt): 73 | """ 74 | Return the calculated CRC sum of a string. 75 | """ 76 | error = False 77 | if opt.UndefinedCrcParameters: 78 | sys.stderr.write("%s: error: undefined parameters\n" % sys.argv[0]) 79 | sys.exit(1) 80 | if opt.Algorithm == 0: 81 | opt.Algorithm = opt.Algo_Bit_by_Bit | opt.Algo_Bit_by_Bit_Fast | opt.Algo_Table_Driven 82 | 83 | alg = Crc(width = opt.Width, poly = opt.Poly, 84 | reflect_in = opt.ReflectIn, xor_in = opt.XorIn, 85 | reflect_out = opt.ReflectOut, xor_out = opt.XorOut, 86 | table_idx_width = opt.TableIdxWidth) 87 | 88 | crc = None 89 | if opt.Algorithm & opt.Algo_Bit_by_Bit: 90 | bbb_crc = alg.bit_by_bit(opt.CheckString) 91 | if crc != None and bbb_crc != crc: 92 | error = True 93 | crc = bbb_crc 94 | if opt.Algorithm & opt.Algo_Bit_by_Bit_Fast: 95 | bbf_crc = alg.bit_by_bit_fast(opt.CheckString) 96 | if crc != None and bbf_crc != crc: 97 | error = True 98 | crc = bbf_crc 99 | if opt.Algorithm & opt.Algo_Table_Driven: 100 | # no point making the python implementation slower by using less than 8 bits as index. 101 | opt.TableIdxWidth = 8 102 | tbl_crc = alg.table_driven(opt.CheckString) 103 | if crc != None and tbl_crc != crc: 104 | error = True 105 | crc = tbl_crc 106 | 107 | if error: 108 | sys.stderr.write("%s: error: different checksums!\n" % sys.argv[0]) 109 | if opt.Algorithm & opt.Algo_Bit_by_Bit: 110 | sys.stderr.write(" bit-by-bit: 0x%x\n" % bbb_crc) 111 | if opt.Algorithm & opt.Algo_Bit_by_Bit_Fast: 112 | sys.stderr.write(" bit-by-bit-fast: 0x%x\n" % bbf_crc) 113 | if opt.Algorithm & opt.Algo_Table_Driven: 114 | sys.stderr.write(" table_driven: 0x%x\n" % tbl_crc) 115 | sys.exit(1) 116 | return crc 117 | 118 | 119 | # function check_hexstring 120 | ############################################################################### 121 | def check_hexstring(opt): 122 | """ 123 | Return the calculated CRC sum of a hex string. 124 | """ 125 | if opt.UndefinedCrcParameters: 126 | sys.stderr.write("%s: error: undefined parameters\n" % sys.argv[0]) 127 | sys.exit(1) 128 | if len(opt.CheckString) % 2 != 0: 129 | opt.CheckString = "0" + opt.CheckString 130 | if sys.version_info >= (3,0): 131 | opt.CheckString = bytes(opt.CheckString, 'UTF-8') 132 | try: 133 | check_str = binascii.unhexlify(opt.CheckString) 134 | except TypeError: 135 | sys.stderr.write("%s: error: invalid hex string %s\n" % (sys.argv[0], opt.CheckString)) 136 | sys.exit(1) 137 | 138 | opt.CheckString = check_str 139 | return check_string(opt) 140 | 141 | 142 | # function crc_file_update 143 | ############################################################################### 144 | def crc_file_update(alg, register, check_byte_str): 145 | """ 146 | Update the CRC using the bit-by-bit-fast CRC algorithm. 147 | """ 148 | for octet in check_byte_str: 149 | if not isinstance(octet, int): 150 | # Python 2.x compatibility 151 | octet = ord(octet) 152 | if alg.ReflectIn: 153 | octet = alg.reflect(octet, 8) 154 | for j in range(8): 155 | bit = register & alg.MSB_Mask 156 | register <<= 1 157 | if octet & (0x80 >> j): 158 | bit ^= alg.MSB_Mask 159 | if bit: 160 | register ^= alg.Poly 161 | register &= alg.Mask 162 | return register 163 | 164 | 165 | # function check_file 166 | ############################################################################### 167 | def check_file(opt): 168 | """ 169 | Calculate the CRC of a file. 170 | This algorithm uses the table_driven CRC algorithm. 171 | """ 172 | if opt.UndefinedCrcParameters: 173 | sys.stderr.write("%s: error: undefined parameters\n" % sys.argv[0]) 174 | sys.exit(1) 175 | alg = Crc(width = opt.Width, poly = opt.Poly, 176 | reflect_in = opt.ReflectIn, xor_in = opt.XorIn, 177 | reflect_out = opt.ReflectOut, xor_out = opt.XorOut, 178 | table_idx_width = opt.TableIdxWidth) 179 | 180 | try: 181 | in_file = open(opt.CheckFile, 'rb') 182 | except IOError: 183 | sys.stderr.write("%s: error: can't open file %s\n" % (sys.argv[0], opt.CheckFile)) 184 | sys.exit(1) 185 | 186 | if not opt.ReflectIn: 187 | register = opt.XorIn 188 | else: 189 | register = alg.reflect(opt.XorIn, opt.Width) 190 | # Read bytes from the file. 191 | check_byte_str = in_file.read() 192 | while check_byte_str: 193 | register = crc_file_update(alg, register, check_byte_str) 194 | check_byte_str = in_file.read() 195 | in_file.close() 196 | 197 | if opt.ReflectOut: 198 | register = alg.reflect(register, opt.Width) 199 | register = register ^ opt.XorOut 200 | return register 201 | 202 | 203 | # main function 204 | ############################################################################### 205 | def main(): 206 | """ 207 | Main function. 208 | """ 209 | opt = Options() 210 | opt.parse(sys.argv[1:]) 211 | if opt.Verbose: 212 | print(print_parameters(opt)) 213 | if opt.Action == opt.Action_Check_String: 214 | crc = check_string(opt) 215 | print("0x%x" % crc) 216 | if opt.Action == opt.Action_Check_Hex_String: 217 | crc = check_hexstring(opt) 218 | print("0x%x" % crc) 219 | if opt.Action == opt.Action_Check_File: 220 | crc = check_file(opt) 221 | print("0x%x" % crc) 222 | if opt.Action in set([opt.Action_Generate_H, opt.Action_Generate_C, opt.Action_Generate_C_Main, opt.Action_Generate_Table]): 223 | mp = MacroParser(opt) 224 | if opt.Action == opt.Action_Generate_H: 225 | in_str = "$h_template" 226 | elif opt.Action == opt.Action_Generate_C: 227 | in_str = "$c_template" 228 | elif opt.Action == opt.Action_Generate_C_Main: 229 | in_str = "$c_template\n\n$main_template" 230 | elif opt.Action == opt.Action_Generate_Table: 231 | in_str = "$crc_table_init" 232 | else: 233 | sys.stderr.write("%s: error: unknown action. Please file a bug report!\n" % sys.argv[0]) 234 | sys.exit(1) 235 | mp.parse(in_str) 236 | if opt.OutputFile == None: 237 | print(mp.out_str) 238 | else: 239 | try: 240 | out_file = open(opt.OutputFile, "w") 241 | out_file.write(mp.out_str) 242 | out_file.close() 243 | except IOError: 244 | sys.stderr.write("%s: error: cannot write to file %s\n" % (sys.argv[0], opt.OutputFile)) 245 | sys.exit(1) 246 | return 0 247 | 248 | 249 | # program entry point 250 | ############################################################################### 251 | if __name__ == "__main__": 252 | sys.exit(main()) 253 | -------------------------------------------------------------------------------- /tests/pycrc/crc_lexer.py: -------------------------------------------------------------------------------- 1 | # pycrc -- parameterisable CRC calculation utility and C source code generator 2 | # 3 | # Copyright (c) 2006-2013 Thomas Pircher 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to 7 | # deal in the Software without restriction, including without limitation the 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | # sell copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | # IN THE SOFTWARE. 22 | 23 | 24 | """ 25 | Lexical analyzer for pycrc. This module is used internally by pycrc for the 26 | macro processing and code generation. 27 | 28 | A basic example of how the lexer is used: 29 | 30 | from crc_lexer import Lexer 31 | 32 | input_str = "the input string to parse" 33 | lex = Lexer() 34 | lex.set_str(input_str) 35 | while True: 36 | tok = lex.peek() 37 | if tok == lex.tok_EOF: 38 | break 39 | else: 40 | print("%4d: %s\n" % (tok, lex.text)) 41 | lex.advance() 42 | """ 43 | 44 | from __future__ import print_function 45 | import re 46 | 47 | 48 | # Class Lexer 49 | ############################################################################### 50 | class Lexer(object): 51 | """ 52 | A lexical analyser base class. 53 | """ 54 | # Tokens. 55 | tok_unknown = 0 56 | tok_EOF = 1 57 | tok_gibberish = 10 58 | tok_identifier = 11 59 | tok_block_open = 12 60 | tok_block_close = 13 61 | tok_num = 20 62 | tok_str = 21 63 | tok_par_open = 22 64 | tok_par_close = 23 65 | tok_op = 24 66 | tok_and = 25 67 | tok_or = 26 68 | 69 | # States of the lexer. 70 | state_gibberish = 0 71 | state_expr = 1 72 | 73 | # Regular Expressions used by the parser. 74 | re_id = re.compile("^\\$[a-zA-Z][a-zA-Z0-9_-]*") 75 | re_num = re.compile("^(0[xX][0-9a-fA-F]+|[0-9]+)") 76 | re_op = re.compile("<=|<|==|!=|>=|>") 77 | re_str = re.compile("\"?([a-zA-Z0-9_-]+)\"?") 78 | 79 | 80 | # Class constructor 81 | ############################################################################### 82 | def __init__(self, input_str = ""): 83 | """ 84 | The class constructor. 85 | """ 86 | self.set_str(input_str) 87 | self.state = self.state_gibberish 88 | 89 | 90 | # function set_str 91 | ############################################################################### 92 | def set_str(self, input_str): 93 | """ 94 | Set the parse input string. 95 | """ 96 | self.input_str = input_str 97 | self.text = "" 98 | self.next_token = None 99 | 100 | 101 | # function peek 102 | ############################################################################### 103 | def peek(self): 104 | """ 105 | Return the next token, without taking it away from the input_str. 106 | """ 107 | if self.next_token == None: 108 | self.next_token = self._parse_next() 109 | return self.next_token 110 | 111 | 112 | # function advance 113 | ############################################################################### 114 | def advance(self, skip_nl = False): 115 | """ 116 | Discard the current symbol from the input stream and advance to the 117 | following characters. If skip_nl is True, then skip also a following 118 | newline character. 119 | """ 120 | self.next_token = None 121 | if skip_nl and len(self.input_str) > 1 and self.input_str[0] == "\n": 122 | self.input_str = self.input_str[1:] 123 | 124 | 125 | # function delete_spaces 126 | ############################################################################### 127 | def delete_spaces(self, skip_unconditional = True): 128 | """ 129 | Delete spaces in the input string. 130 | If skip_unconditional is False, then skip the spaces only if followed 131 | by $if() $else() or $elif(). 132 | """ 133 | new_input = self.input_str.lstrip(" \t") 134 | 135 | # check for an identifier 136 | m = self.re_id.match(new_input) 137 | if m != None: 138 | text = m.group(0)[1:] 139 | # if the identifier is a reserved keyword, skip the spaces. 140 | if (text == "if" or text == "elif" or text == "else"): 141 | skip_unconditional = True 142 | if skip_unconditional: 143 | self.next_token = None 144 | self.input_str = new_input 145 | 146 | 147 | # function prepend 148 | ############################################################################### 149 | def prepend(self, in_str): 150 | """ 151 | Prepend the parameter to to the input string. 152 | """ 153 | self.input_str = in_str + self.input_str 154 | 155 | 156 | # function set_state 157 | ############################################################################### 158 | def set_state(self, new_state): 159 | """ 160 | Set the new state for the lexer. 161 | This changes the behaviour of the lexical scanner from normal operation 162 | to expression scanning (within $if () expressions) and back. 163 | """ 164 | self.state = new_state 165 | self.next_token = None 166 | 167 | 168 | # function _parse_next 169 | ############################################################################### 170 | def _parse_next(self): 171 | """ 172 | Parse the next token, update the state variables and take the consumed 173 | text from the imput stream. 174 | """ 175 | if len(self.input_str) == 0: 176 | return self.tok_EOF 177 | 178 | if self.state == self.state_gibberish: 179 | return self._parse_gibberish() 180 | if self.state == self.state_expr: 181 | return self._parse_expr() 182 | return self.tok_unknown 183 | 184 | 185 | # function _parse_gibberish 186 | ############################################################################### 187 | def _parse_gibberish(self): 188 | """ 189 | Parse the next token, update the state variables and take the consumed 190 | text from the imput stream. 191 | """ 192 | # check for an identifier 193 | m = self.re_id.match(self.input_str) 194 | if m != None: 195 | self.text = m.group(0)[1:] 196 | self.input_str = self.input_str[m.end():] 197 | return self.tok_identifier 198 | 199 | if len(self.input_str) > 1: 200 | # check for "{:" 201 | if self.input_str[0:2] == "{:": 202 | self.text = self.input_str[0:2] 203 | self.input_str = self.input_str[2:] 204 | return self.tok_block_open 205 | # check for ":}" 206 | if self.input_str[0:2] == ":}": 207 | self.text = self.input_str[0:2] 208 | self.input_str = self.input_str[2:] 209 | return self.tok_block_close 210 | # check for "$$" 211 | if self.input_str[0:2] == "$$": 212 | self.text = self.input_str[0:1] 213 | self.input_str = self.input_str[2:] 214 | return self.tok_gibberish 215 | # check for malformed "$" 216 | if self.input_str[0] == "$": 217 | self.text = self.input_str[0:1] 218 | return self.tok_unknown 219 | 220 | # the character is gibberish. 221 | # find the position of the next special character. 222 | pos = self.input_str.find("$") 223 | tmp = self.input_str.find("{:") 224 | if pos < 0 or (tmp >= 0 and tmp < pos): 225 | pos = tmp 226 | tmp = self.input_str.find(":}") 227 | if pos < 0 or (tmp >= 0 and tmp < pos): 228 | pos = tmp 229 | 230 | if pos < 0 or len(self.input_str) == 1: 231 | # neither id nor block start nor block end found: 232 | # the whole text is just gibberish. 233 | self.text = self.input_str 234 | self.input_str = "" 235 | else: 236 | self.text = self.input_str[:pos] 237 | self.input_str = self.input_str[pos:] 238 | return self.tok_gibberish 239 | 240 | 241 | # function _parse_expr 242 | ############################################################################### 243 | def _parse_expr(self): 244 | """ 245 | Parse the next token, update the state variables and take the consumed 246 | text from the imput stream. 247 | """ 248 | # skip whitespaces 249 | pos = 0 250 | while pos < len(self.input_str) and self.input_str[pos] == ' ': 251 | pos = pos + 1 252 | if pos > 0: 253 | self.input_str = self.input_str[pos:] 254 | 255 | if len(self.input_str) == 0: 256 | return self.tok_EOF 257 | 258 | m = self.re_id.match(self.input_str) 259 | if m != None: 260 | self.text = m.group(0)[1:] 261 | self.input_str = self.input_str[m.end():] 262 | return self.tok_identifier 263 | 264 | m = self.re_num.match(self.input_str) 265 | if m != None: 266 | self.text = m.group(0) 267 | self.input_str = self.input_str[m.end():] 268 | return self.tok_num 269 | 270 | m = self.re_op.match(self.input_str) 271 | if m != None: 272 | self.text = m.string[:m.end()] 273 | self.input_str = self.input_str[m.end():] 274 | return self.tok_op 275 | 276 | if self.input_str[:4] == "and ": 277 | self.text = "and" 278 | self.input_str = self.input_str[len(self.text) + 1:] 279 | return self.tok_and 280 | 281 | if self.input_str[:3] == "or ": 282 | self.text = "or" 283 | self.input_str = self.input_str[len(self.text) + 1:] 284 | return self.tok_or 285 | 286 | m = self.re_str.match(self.input_str) 287 | if m != None: 288 | self.text = m.group(1) 289 | self.input_str = self.input_str[m.end():] 290 | return self.tok_str 291 | 292 | if self.input_str[0] == "(": 293 | self.text = self.input_str[0] 294 | self.input_str = self.input_str[len(self.text):] 295 | return self.tok_par_open 296 | 297 | if self.input_str[0] == ")": 298 | self.text = self.input_str[0] 299 | self.input_str = self.input_str[len(self.text):] 300 | return self.tok_par_close 301 | 302 | return self.tok_unknown 303 | -------------------------------------------------------------------------------- /tests/pycrc/crc_models.py: -------------------------------------------------------------------------------- 1 | # pycrc -- parameterisable CRC calculation utility and C source code generator 2 | # 3 | # Copyright (c) 2006-2013 Thomas Pircher 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to 7 | # deal in the Software without restriction, including without limitation the 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | # sell copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | # IN THE SOFTWARE. 22 | 23 | 24 | """ 25 | Collection of CRC models. This module contains the CRC models known to pycrc. 26 | 27 | To print the parameters of a particular model: 28 | 29 | from crc_models import CrcModels 30 | 31 | models = CrcModels() 32 | print(models.getList()) 33 | m = models.getParams("crc-32") 34 | if m != None: 35 | print("Width: %(width)s" % m) 36 | print("Poly: %(poly)s" % m) 37 | print("ReflectIn: %(reflect_in)s" % m) 38 | print("XorIn: %(xor_in)s" % m) 39 | print("ReflectOut: %(reflect_out)s" % m) 40 | print("XorOut: %(xor_out)s" % m) 41 | print("Check: %(check)s" % m) 42 | else: 43 | print("model not found.") 44 | """ 45 | 46 | 47 | 48 | # Class CrcModels 49 | ############################################################################### 50 | class CrcModels(object): 51 | """ 52 | CRC Models. 53 | 54 | All models are defined as constant class variables. 55 | """ 56 | 57 | models = [] 58 | 59 | models.append({ 60 | 'name': 'crc-5', 61 | 'width': 5, 62 | 'poly': 0x05, 63 | 'reflect_in': True, 64 | 'xor_in': 0x1f, 65 | 'reflect_out': True, 66 | 'xor_out': 0x1f, 67 | 'check': 0x19, 68 | }) 69 | models.append({ 70 | 'name': 'crc-8', 71 | 'width': 8, 72 | 'poly': 0x07, 73 | 'reflect_in': False, 74 | 'xor_in': 0x0, 75 | 'reflect_out': False, 76 | 'xor_out': 0x0, 77 | 'check': 0xf4, 78 | }) 79 | models.append({ 80 | 'name': 'dallas-1-wire', 81 | 'width': 8, 82 | 'poly': 0x31, 83 | 'reflect_in': True, 84 | 'xor_in': 0x0, 85 | 'reflect_out': True, 86 | 'xor_out': 0x0, 87 | 'check': 0xa1, 88 | }) 89 | models.append({ 90 | 'name': 'crc-12-3gpp', 91 | 'width': 12, 92 | 'poly': 0x80f, 93 | 'reflect_in': False, 94 | 'xor_in': 0x0, 95 | 'reflect_out': True, 96 | 'xor_out': 0x0, 97 | 'check': 0xdaf, 98 | }) 99 | models.append({ 100 | 'name': 'crc-15', 101 | 'width': 15, 102 | 'poly': 0x4599, 103 | 'reflect_in': False, 104 | 'xor_in': 0x0, 105 | 'reflect_out': False, 106 | 'xor_out': 0x0, 107 | 'check': 0x59e, 108 | }) 109 | models.append({ 110 | 'name': 'crc-16', 111 | 'width': 16, 112 | 'poly': 0x8005, 113 | 'reflect_in': True, 114 | 'xor_in': 0x0, 115 | 'reflect_out': True, 116 | 'xor_out': 0x0, 117 | 'check': 0xbb3d, 118 | }) 119 | models.append({ 120 | 'name': 'crc-16-usb', 121 | 'width': 16, 122 | 'poly': 0x8005, 123 | 'reflect_in': True, 124 | 'xor_in': 0xffff, 125 | 'reflect_out': True, 126 | 'xor_out': 0xffff, 127 | 'check': 0xb4c8, 128 | }) 129 | models.append({ 130 | 'name': 'crc-16-modbus', 131 | 'width': 16, 132 | 'poly': 0x8005, 133 | 'reflect_in': True, 134 | 'xor_in': 0xffff, 135 | 'reflect_out': True, 136 | 'xor_out': 0x0, 137 | 'check': 0x4b37, 138 | }) 139 | models.append({ 140 | 'name': 'crc-16-genibus', 141 | 'width': 16, 142 | 'poly': 0x1021, 143 | 'reflect_in': False, 144 | 'xor_in': 0xffff, 145 | 'reflect_out': False, 146 | 'xor_out': 0xffff, 147 | 'check': 0xd64e, 148 | }) 149 | models.append({ 150 | 'name': 'ccitt', 151 | 'width': 16, 152 | 'poly': 0x1021, 153 | 'reflect_in': False, 154 | 'xor_in': 0xffff, 155 | 'reflect_out': False, 156 | 'xor_out': 0x0, 157 | 'check': 0x29b1, 158 | }) 159 | models.append({ 160 | 'name': 'r-crc-16', 161 | 'width': 16, 162 | 'poly': 0x0589, 163 | 'reflect_in': False, 164 | 'xor_in': 0x0, 165 | 'reflect_out': False, 166 | 'xor_out': 0x0001, 167 | 'check': 0x007e, 168 | }) 169 | models.append({ 170 | 'name': 'kermit', 171 | 'width': 16, 172 | 'poly': 0x1021, 173 | 'reflect_in': True, 174 | 'xor_in': 0x0, 175 | 'reflect_out': True, 176 | 'xor_out': 0x0, 177 | 'check': 0x2189, 178 | }) 179 | models.append({ 180 | 'name': 'x-25', 181 | 'width': 16, 182 | 'poly': 0x1021, 183 | 'reflect_in': True, 184 | 'xor_in': 0xffff, 185 | 'reflect_out': True, 186 | 'xor_out': 0xffff, 187 | 'check': 0x906e, 188 | }) 189 | models.append({ 190 | 'name': 'xmodem', 191 | 'width': 16, 192 | 'poly': 0x1021, 193 | 'reflect_in': False, 194 | 'xor_in': 0x0, 195 | 'reflect_out': False, 196 | 'xor_out': 0x0, 197 | 'check': 0x31c3, 198 | }) 199 | models.append({ 200 | 'name': 'zmodem', 201 | 'width': 16, 202 | 'poly': 0x1021, 203 | 'reflect_in': False, 204 | 'xor_in': 0x0, 205 | 'reflect_out': False, 206 | 'xor_out': 0x0, 207 | 'check': 0x31c3, 208 | }) 209 | models.append({ 210 | 'name': 'crc-24', 211 | 'width': 24, 212 | 'poly': 0x864cfb, 213 | 'reflect_in': False, 214 | 'xor_in': 0xb704ce, 215 | 'reflect_out': False, 216 | 'xor_out': 0x0, 217 | 'check': 0x21cf02, 218 | }) 219 | models.append({ 220 | 'name': 'crc-32', 221 | 'width': 32, 222 | 'poly': 0x4c11db7, 223 | 'reflect_in': True, 224 | 'xor_in': 0xffffffff, 225 | 'reflect_out': True, 226 | 'xor_out': 0xffffffff, 227 | 'check': 0xcbf43926, 228 | }) 229 | models.append({ 230 | 'name': 'crc-32c', 231 | 'width': 32, 232 | 'poly': 0x1edc6f41, 233 | 'reflect_in': True, 234 | 'xor_in': 0xffffffff, 235 | 'reflect_out': True, 236 | 'xor_out': 0xffffffff, 237 | 'check': 0xe3069283, 238 | }) 239 | models.append({ 240 | 'name': 'crc-32-mpeg', 241 | 'width': 32, 242 | 'poly': 0x4c11db7, 243 | 'reflect_in': False, 244 | 'xor_in': 0xffffffff, 245 | 'reflect_out': False, 246 | 'xor_out': 0x0, 247 | 'check': 0x0376e6e7, 248 | }) 249 | models.append({ 250 | 'name': 'crc-32-bzip2', 251 | 'width': 32, 252 | 'poly': 0x04c11db7, 253 | 'reflect_in': False, 254 | 'xor_in': 0xffffffff, 255 | 'reflect_out': False, 256 | 'xor_out': 0xffffffff, 257 | 'check': 0xfc891918, 258 | }) 259 | models.append({ 260 | 'name': 'posix', 261 | 'width': 32, 262 | 'poly': 0x4c11db7, 263 | 'reflect_in': False, 264 | 'xor_in': 0x0, 265 | 'reflect_out': False, 266 | 'xor_out': 0xffffffff, 267 | 'check': 0x765e7680, 268 | }) 269 | models.append({ 270 | 'name': 'jam', 271 | 'width': 32, 272 | 'poly': 0x4c11db7, 273 | 'reflect_in': True, 274 | 'xor_in': 0xffffffff, 275 | 'reflect_out': True, 276 | 'xor_out': 0x0, 277 | 'check': 0x340bc6d9, 278 | }) 279 | models.append({ 280 | 'name': 'xfer', 281 | 'width': 32, 282 | 'poly': 0x000000af, 283 | 'reflect_in': False, 284 | 'xor_in': 0x0, 285 | 'reflect_out': False, 286 | 'xor_out': 0x0, 287 | 'check': 0xbd0be338, 288 | }) 289 | models.append({ 290 | 'name': 'crc-64', 291 | 'width': 64, 292 | 'poly': 0x000000000000001b, 293 | 'reflect_in': True, 294 | 'xor_in': 0x0, 295 | 'reflect_out': True, 296 | 'xor_out': 0x0, 297 | 'check': 0x46a5a9388a5beffe, 298 | }) 299 | models.append({ 300 | 'name': 'crc-64-jones', 301 | 'width': 64, 302 | 'poly': 0xad93d23594c935a9, 303 | 'reflect_in': True, 304 | 'xor_in': 0xffffffffffffffff, 305 | 'reflect_out': True, 306 | 'xor_out': 0x0, 307 | 'check': 0xcaa717168609f281, 308 | }) 309 | models.append({ 310 | 'name': 'crc-64-xz', 311 | 'width': 64, 312 | 'poly': 0x42f0e1eba9ea3693, 313 | 'reflect_in': True, 314 | 'xor_in': 0xffffffffffffffff, 315 | 'reflect_out': True, 316 | 'xor_out': 0xffffffffffffffff, 317 | 'check': 0x995dc9bbdf1939fa, 318 | }) 319 | 320 | 321 | # function getList 322 | ############################################################################### 323 | def getList(self): 324 | """ 325 | This function returns the list of supported CRC models. 326 | """ 327 | l = [] 328 | for i in self.models: 329 | l.append(i['name']) 330 | return l 331 | 332 | 333 | # function getParams 334 | ############################################################################### 335 | def getParams(self, model): 336 | """ 337 | This function returns the parameters of a given model. 338 | """ 339 | model = model.lower(); 340 | for i in self.models: 341 | if i['name'] == model: 342 | return i 343 | return None 344 | -------------------------------------------------------------------------------- /tests/dependencies/rollup/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "crc-test", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "@rollup/plugin-commonjs": "^21.0.2", 13 | "@rollup/plugin-node-resolve": "^13.1.3", 14 | "rollup": "^2.70.1" 15 | } 16 | }, 17 | "../../../dist": { 18 | "name": "crc", 19 | "version": "4.1.1", 20 | "extraneous": true, 21 | "license": "MIT", 22 | "engines": { 23 | "node": ">=12" 24 | }, 25 | "peerDependencies": { 26 | "buffer": ">=6.0.3" 27 | } 28 | }, 29 | "node_modules/@rollup/plugin-commonjs": { 30 | "version": "21.0.2", 31 | "license": "MIT", 32 | "dependencies": { 33 | "@rollup/pluginutils": "^3.1.0", 34 | "commondir": "^1.0.1", 35 | "estree-walker": "^2.0.1", 36 | "glob": "^7.1.6", 37 | "is-reference": "^1.2.1", 38 | "magic-string": "^0.25.7", 39 | "resolve": "^1.17.0" 40 | }, 41 | "engines": { 42 | "node": ">= 8.0.0" 43 | }, 44 | "peerDependencies": { 45 | "rollup": "^2.38.3" 46 | } 47 | }, 48 | "node_modules/@rollup/plugin-commonjs/node_modules/estree-walker": { 49 | "version": "2.0.2", 50 | "license": "MIT" 51 | }, 52 | "node_modules/@rollup/plugin-node-resolve": { 53 | "version": "13.1.3", 54 | "license": "MIT", 55 | "dependencies": { 56 | "@rollup/pluginutils": "^3.1.0", 57 | "@types/resolve": "1.17.1", 58 | "builtin-modules": "^3.1.0", 59 | "deepmerge": "^4.2.2", 60 | "is-module": "^1.0.0", 61 | "resolve": "^1.19.0" 62 | }, 63 | "engines": { 64 | "node": ">= 10.0.0" 65 | }, 66 | "peerDependencies": { 67 | "rollup": "^2.42.0" 68 | } 69 | }, 70 | "node_modules/@rollup/pluginutils": { 71 | "version": "3.1.0", 72 | "license": "MIT", 73 | "dependencies": { 74 | "@types/estree": "0.0.39", 75 | "estree-walker": "^1.0.1", 76 | "picomatch": "^2.2.2" 77 | }, 78 | "engines": { 79 | "node": ">= 8.0.0" 80 | }, 81 | "peerDependencies": { 82 | "rollup": "^1.20.0||^2.0.0" 83 | } 84 | }, 85 | "node_modules/@types/estree": { 86 | "version": "0.0.39", 87 | "license": "MIT" 88 | }, 89 | "node_modules/@types/node": { 90 | "version": "17.0.23", 91 | "license": "MIT" 92 | }, 93 | "node_modules/@types/resolve": { 94 | "version": "1.17.1", 95 | "license": "MIT", 96 | "dependencies": { 97 | "@types/node": "*" 98 | } 99 | }, 100 | "node_modules/balanced-match": { 101 | "version": "1.0.2", 102 | "license": "MIT" 103 | }, 104 | "node_modules/brace-expansion": { 105 | "version": "1.1.11", 106 | "license": "MIT", 107 | "dependencies": { 108 | "balanced-match": "^1.0.0", 109 | "concat-map": "0.0.1" 110 | } 111 | }, 112 | "node_modules/builtin-modules": { 113 | "version": "3.2.0", 114 | "license": "MIT", 115 | "engines": { 116 | "node": ">=6" 117 | }, 118 | "funding": { 119 | "url": "https://github.com/sponsors/sindresorhus" 120 | } 121 | }, 122 | "node_modules/commondir": { 123 | "version": "1.0.1", 124 | "license": "MIT" 125 | }, 126 | "node_modules/concat-map": { 127 | "version": "0.0.1", 128 | "license": "MIT" 129 | }, 130 | "node_modules/deepmerge": { 131 | "version": "4.2.2", 132 | "license": "MIT", 133 | "engines": { 134 | "node": ">=0.10.0" 135 | } 136 | }, 137 | "node_modules/estree-walker": { 138 | "version": "1.0.1", 139 | "license": "MIT" 140 | }, 141 | "node_modules/fs.realpath": { 142 | "version": "1.0.0", 143 | "license": "ISC" 144 | }, 145 | "node_modules/function-bind": { 146 | "version": "1.1.1", 147 | "license": "MIT" 148 | }, 149 | "node_modules/glob": { 150 | "version": "7.2.0", 151 | "license": "ISC", 152 | "dependencies": { 153 | "fs.realpath": "^1.0.0", 154 | "inflight": "^1.0.4", 155 | "inherits": "2", 156 | "minimatch": "^3.0.4", 157 | "once": "^1.3.0", 158 | "path-is-absolute": "^1.0.0" 159 | }, 160 | "engines": { 161 | "node": "*" 162 | }, 163 | "funding": { 164 | "url": "https://github.com/sponsors/isaacs" 165 | } 166 | }, 167 | "node_modules/has": { 168 | "version": "1.0.3", 169 | "license": "MIT", 170 | "dependencies": { 171 | "function-bind": "^1.1.1" 172 | }, 173 | "engines": { 174 | "node": ">= 0.4.0" 175 | } 176 | }, 177 | "node_modules/inflight": { 178 | "version": "1.0.6", 179 | "license": "ISC", 180 | "dependencies": { 181 | "once": "^1.3.0", 182 | "wrappy": "1" 183 | } 184 | }, 185 | "node_modules/inherits": { 186 | "version": "2.0.4", 187 | "license": "ISC" 188 | }, 189 | "node_modules/is-core-module": { 190 | "version": "2.8.1", 191 | "license": "MIT", 192 | "dependencies": { 193 | "has": "^1.0.3" 194 | }, 195 | "funding": { 196 | "url": "https://github.com/sponsors/ljharb" 197 | } 198 | }, 199 | "node_modules/is-module": { 200 | "version": "1.0.0", 201 | "license": "MIT" 202 | }, 203 | "node_modules/is-reference": { 204 | "version": "1.2.1", 205 | "license": "MIT", 206 | "dependencies": { 207 | "@types/estree": "*" 208 | } 209 | }, 210 | "node_modules/magic-string": { 211 | "version": "0.25.9", 212 | "license": "MIT", 213 | "dependencies": { 214 | "sourcemap-codec": "^1.4.8" 215 | } 216 | }, 217 | "node_modules/minimatch": { 218 | "version": "3.1.2", 219 | "license": "ISC", 220 | "dependencies": { 221 | "brace-expansion": "^1.1.7" 222 | }, 223 | "engines": { 224 | "node": "*" 225 | } 226 | }, 227 | "node_modules/once": { 228 | "version": "1.4.0", 229 | "license": "ISC", 230 | "dependencies": { 231 | "wrappy": "1" 232 | } 233 | }, 234 | "node_modules/path-is-absolute": { 235 | "version": "1.0.1", 236 | "license": "MIT", 237 | "engines": { 238 | "node": ">=0.10.0" 239 | } 240 | }, 241 | "node_modules/path-parse": { 242 | "version": "1.0.7", 243 | "license": "MIT" 244 | }, 245 | "node_modules/picomatch": { 246 | "version": "2.3.1", 247 | "license": "MIT", 248 | "engines": { 249 | "node": ">=8.6" 250 | }, 251 | "funding": { 252 | "url": "https://github.com/sponsors/jonschlinkert" 253 | } 254 | }, 255 | "node_modules/resolve": { 256 | "version": "1.22.0", 257 | "license": "MIT", 258 | "dependencies": { 259 | "is-core-module": "^2.8.1", 260 | "path-parse": "^1.0.7", 261 | "supports-preserve-symlinks-flag": "^1.0.0" 262 | }, 263 | "bin": { 264 | "resolve": "bin/resolve" 265 | }, 266 | "funding": { 267 | "url": "https://github.com/sponsors/ljharb" 268 | } 269 | }, 270 | "node_modules/rollup": { 271 | "version": "2.70.1", 272 | "license": "MIT", 273 | "bin": { 274 | "rollup": "dist/bin/rollup" 275 | }, 276 | "engines": { 277 | "node": ">=10.0.0" 278 | }, 279 | "optionalDependencies": { 280 | "fsevents": "~2.3.2" 281 | } 282 | }, 283 | "node_modules/sourcemap-codec": { 284 | "version": "1.4.8", 285 | "license": "MIT" 286 | }, 287 | "node_modules/supports-preserve-symlinks-flag": { 288 | "version": "1.0.0", 289 | "license": "MIT", 290 | "engines": { 291 | "node": ">= 0.4" 292 | }, 293 | "funding": { 294 | "url": "https://github.com/sponsors/ljharb" 295 | } 296 | }, 297 | "node_modules/wrappy": { 298 | "version": "1.0.2", 299 | "license": "ISC" 300 | } 301 | }, 302 | "dependencies": { 303 | "@rollup/plugin-commonjs": { 304 | "version": "21.0.2", 305 | "requires": { 306 | "@rollup/pluginutils": "^3.1.0", 307 | "commondir": "^1.0.1", 308 | "estree-walker": "^2.0.1", 309 | "glob": "^7.1.6", 310 | "is-reference": "^1.2.1", 311 | "magic-string": "^0.25.7", 312 | "resolve": "^1.17.0" 313 | }, 314 | "dependencies": { 315 | "estree-walker": { 316 | "version": "2.0.2" 317 | } 318 | } 319 | }, 320 | "@rollup/plugin-node-resolve": { 321 | "version": "13.1.3", 322 | "requires": { 323 | "@rollup/pluginutils": "^3.1.0", 324 | "@types/resolve": "1.17.1", 325 | "builtin-modules": "^3.1.0", 326 | "deepmerge": "^4.2.2", 327 | "is-module": "^1.0.0", 328 | "resolve": "^1.19.0" 329 | } 330 | }, 331 | "@rollup/pluginutils": { 332 | "version": "3.1.0", 333 | "requires": { 334 | "@types/estree": "0.0.39", 335 | "estree-walker": "^1.0.1", 336 | "picomatch": "^2.2.2" 337 | } 338 | }, 339 | "@types/estree": { 340 | "version": "0.0.39" 341 | }, 342 | "@types/node": { 343 | "version": "17.0.23" 344 | }, 345 | "@types/resolve": { 346 | "version": "1.17.1", 347 | "requires": { 348 | "@types/node": "*" 349 | } 350 | }, 351 | "balanced-match": { 352 | "version": "1.0.2" 353 | }, 354 | "brace-expansion": { 355 | "version": "1.1.11", 356 | "requires": { 357 | "balanced-match": "^1.0.0", 358 | "concat-map": "0.0.1" 359 | } 360 | }, 361 | "builtin-modules": { 362 | "version": "3.2.0" 363 | }, 364 | "commondir": { 365 | "version": "1.0.1" 366 | }, 367 | "concat-map": { 368 | "version": "0.0.1" 369 | }, 370 | "deepmerge": { 371 | "version": "4.2.2" 372 | }, 373 | "estree-walker": { 374 | "version": "1.0.1" 375 | }, 376 | "fs.realpath": { 377 | "version": "1.0.0" 378 | }, 379 | "function-bind": { 380 | "version": "1.1.1" 381 | }, 382 | "glob": { 383 | "version": "7.2.0", 384 | "requires": { 385 | "fs.realpath": "^1.0.0", 386 | "inflight": "^1.0.4", 387 | "inherits": "2", 388 | "minimatch": "^3.0.4", 389 | "once": "^1.3.0", 390 | "path-is-absolute": "^1.0.0" 391 | } 392 | }, 393 | "has": { 394 | "version": "1.0.3", 395 | "requires": { 396 | "function-bind": "^1.1.1" 397 | } 398 | }, 399 | "inflight": { 400 | "version": "1.0.6", 401 | "requires": { 402 | "once": "^1.3.0", 403 | "wrappy": "1" 404 | } 405 | }, 406 | "inherits": { 407 | "version": "2.0.4" 408 | }, 409 | "is-core-module": { 410 | "version": "2.8.1", 411 | "requires": { 412 | "has": "^1.0.3" 413 | } 414 | }, 415 | "is-module": { 416 | "version": "1.0.0" 417 | }, 418 | "is-reference": { 419 | "version": "1.2.1", 420 | "requires": { 421 | "@types/estree": "*" 422 | } 423 | }, 424 | "magic-string": { 425 | "version": "0.25.9", 426 | "requires": { 427 | "sourcemap-codec": "^1.4.8" 428 | } 429 | }, 430 | "minimatch": { 431 | "version": "3.1.2", 432 | "requires": { 433 | "brace-expansion": "^1.1.7" 434 | } 435 | }, 436 | "once": { 437 | "version": "1.4.0", 438 | "requires": { 439 | "wrappy": "1" 440 | } 441 | }, 442 | "path-is-absolute": { 443 | "version": "1.0.1" 444 | }, 445 | "path-parse": { 446 | "version": "1.0.7" 447 | }, 448 | "picomatch": { 449 | "version": "2.3.1" 450 | }, 451 | "resolve": { 452 | "version": "1.22.0", 453 | "requires": { 454 | "is-core-module": "^2.8.1", 455 | "path-parse": "^1.0.7", 456 | "supports-preserve-symlinks-flag": "^1.0.0" 457 | } 458 | }, 459 | "rollup": { 460 | "version": "2.70.1", 461 | "requires": { 462 | "fsevents": "~2.3.2" 463 | } 464 | }, 465 | "sourcemap-codec": { 466 | "version": "1.4.8" 467 | }, 468 | "supports-preserve-symlinks-flag": { 469 | "version": "1.0.0" 470 | }, 471 | "wrappy": { 472 | "version": "1.0.2" 473 | } 474 | } 475 | } 476 | -------------------------------------------------------------------------------- /tests/pycrc/crc_parser.py: -------------------------------------------------------------------------------- 1 | # pycrc -- parameterisable CRC calculation utility and C source code generator 2 | # 3 | # Copyright (c) 2006-2013 Thomas Pircher 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to 7 | # deal in the Software without restriction, including without limitation the 8 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9 | # sell copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | # IN THE SOFTWARE. 22 | 23 | 24 | """ 25 | Macro Language parser for pycrc. 26 | use as follows: 27 | 28 | import sys 29 | from crc_opt import Options 30 | from crc_parser import MacroParser, ParseError 31 | 32 | opt = Options() 33 | opt.parse(sys.argv[1:]) 34 | mp = MacroParser(opt) 35 | if mp.parse("Test 1 2 3"): 36 | print(mp.out_str) 37 | """ 38 | 39 | from crc_symtable import SymbolTable, SymbolLookupError 40 | from crc_lexer import Lexer 41 | import re 42 | import sys 43 | 44 | 45 | # Class ParseError 46 | ############################################################################### 47 | class ParseError(Exception): 48 | """ 49 | The exception class for the parser. 50 | """ 51 | 52 | # Class constructor 53 | ############################################################################### 54 | def __init__(self, reason): 55 | self.reason = reason 56 | 57 | # function __str__ 58 | ############################################################################### 59 | def __str__(self): 60 | return self.reason 61 | 62 | 63 | # Class MacroParser 64 | ############################################################################### 65 | class MacroParser(object): 66 | """ 67 | The macro language parser and code generator class. 68 | """ 69 | re_is_int = re.compile("^[-+]?[0-9]+$") 70 | #re_is_hex = re.compile("^(0[xX])?[0-9a-fA-F]+$") 71 | re_is_hex = re.compile("^0[xX][0-9a-fA-F]+$") 72 | 73 | 74 | # Class constructor 75 | ############################################################################### 76 | def __init__(self, opt): 77 | self.opt = opt 78 | self.sym = SymbolTable(opt) 79 | self.out_str = None 80 | self.lex = Lexer() 81 | 82 | # function parse 83 | # 84 | # The used grammar is: 85 | # data: /* empty */ 86 | # | data GIBBERISH 87 | # | data IDENTIFIER 88 | # | data '{:' data ':}' 89 | # | data if_block 90 | # ; 91 | # 92 | # if_block: IF '(' exp_or ')' '{:' data ':}' elif_blocks else_block 93 | # ; 94 | # 95 | # elif_blocks: /* empty */ 96 | # | elif_blocks ELIF '(' exp_or ')' '{:' data ':}' 97 | # ; 98 | # 99 | # else_block: /* empty */ 100 | # | ELSE '{:' data ':}' 101 | # ; 102 | # 103 | # exp_or: exp_and 104 | # | exp_or TOK_OR exp_and 105 | # ; 106 | # 107 | # exp_and: term 108 | # | exp_and TOK_AND exp_comparison 109 | # ; 110 | # 111 | # exp_comparison: term TOK_COMPARISON term 112 | # ; 113 | # 114 | # term: LITERAL 115 | # | IDENTIFIER 116 | # | '(' exp_or ')' 117 | # ; 118 | ############################################################################### 119 | def parse(self, in_str): 120 | """ 121 | Parse a macro string. 122 | """ 123 | self.lex.set_str(in_str) 124 | self.out_str = "" 125 | self._parse_data(do_print = True) 126 | 127 | tok = self.lex.peek() 128 | if tok != self.lex.tok_EOF: 129 | raise ParseError("%s: error: misaligned closing block '%s'" % (sys.argv[0], self.lex.text)) 130 | 131 | 132 | # function _parse_data 133 | ############################################################################### 134 | def _parse_data(self, do_print): 135 | """ 136 | Private top-level parsing function. 137 | """ 138 | tok = self.lex.peek() 139 | while tok != self.lex.tok_EOF: 140 | if tok == self.lex.tok_gibberish: 141 | self._parse_gibberish(do_print) 142 | elif tok == self.lex.tok_block_open: 143 | self._parse_data_block(do_print) 144 | elif tok == self.lex.tok_identifier and self.lex.text == "if": 145 | self._parse_if_block(do_print) 146 | elif tok == self.lex.tok_identifier: 147 | self._parse_identifier(do_print) 148 | elif tok == self.lex.tok_block_close: 149 | return 150 | else: 151 | raise ParseError("%s: error: wrong token '%s'" % (sys.argv[0], self.lex.text)) 152 | tok = self.lex.peek() 153 | 154 | 155 | # function _parse_gibberish 156 | ############################################################################### 157 | def _parse_gibberish(self, do_print): 158 | """ 159 | Parse gibberish. 160 | Actually, just print the characters in 'text' if do_print is True. 161 | """ 162 | if do_print: 163 | self.out_str = self.out_str + self.lex.text 164 | self.lex.advance() 165 | 166 | 167 | # function _parse_identifier 168 | ############################################################################### 169 | def _parse_identifier(self, do_print): 170 | """ 171 | Parse an identifier. 172 | """ 173 | try: 174 | sym_value = self.sym.getTerminal(self.lex.text) 175 | except SymbolLookupError: 176 | raise ParseError("%s: error: unknown terminal '%s'" % (sys.argv[0], self.lex.text)) 177 | self.lex.advance() 178 | if do_print: 179 | self.lex.prepend(sym_value) 180 | 181 | 182 | # function _parse_if_block 183 | ############################################################################### 184 | def _parse_if_block(self, do_print): 185 | """ 186 | Parse an if block. 187 | """ 188 | # parse the expression following the 'if' and the associated block. 189 | exp_res = self._parse_conditional_block(do_print) 190 | do_print = do_print and not exp_res 191 | 192 | # try $elif 193 | tok = self.lex.peek() 194 | while tok == self.lex.tok_identifier and self.lex.text == "elif": 195 | exp_res = self._parse_conditional_block(do_print) 196 | do_print = do_print and not exp_res 197 | tok = self.lex.peek() 198 | 199 | # try $else 200 | if tok == self.lex.tok_identifier and self.lex.text == "else": 201 | # get rid of the tok_identifier, 'else' and following spaces 202 | self.lex.advance() 203 | self.lex.delete_spaces() 204 | 205 | # expect a data block 206 | self._parse_data_block(do_print) 207 | 208 | 209 | 210 | # function _parse_conditional_block 211 | ############################################################################### 212 | def _parse_conditional_block(self, do_print): 213 | """ 214 | Parse a conditional block (such as $if or $elif). 215 | Return the truth value of the expression. 216 | """ 217 | # get rid of the tok_identifier, 'if' or 'elif' 218 | self.lex.advance() 219 | self.lex.set_state(self.lex.state_expr) 220 | 221 | # expect an open parenthesis 222 | tok = self.lex.peek() 223 | if tok != self.lex.tok_par_open: 224 | raise ParseError("%s: error: open parenthesis expected: '%s'" % (sys.argv[0], self.lex.text)) 225 | self.lex.advance() 226 | 227 | # parse the boolean expression 228 | exp_res = self._parse_exp_or() 229 | 230 | # expect a closed parenthesis 231 | tok = self.lex.peek() 232 | if tok != self.lex.tok_par_close: 233 | raise ParseError("%s: error: closed parenthesis expected: '%s'" % (sys.argv[0], self.lex.text)) 234 | self.lex.advance() 235 | 236 | # get rid of eventual spaces, and switch back to gibberish. 237 | self.lex.delete_spaces() 238 | self.lex.set_state(self.lex.state_gibberish) 239 | 240 | # expect a data block 241 | self._parse_data_block(do_print and exp_res) 242 | 243 | # get rid of eventual spaces 244 | # but only if followed by $if, $else or $elif 245 | self.lex.delete_spaces(skip_unconditional = False) 246 | 247 | return exp_res 248 | 249 | 250 | # function _parse_data_block 251 | ############################################################################### 252 | def _parse_data_block(self, do_print): 253 | """ 254 | Parse a data block. 255 | """ 256 | # expect an open block 257 | tok = self.lex.peek() 258 | if tok != self.lex.tok_block_open: 259 | raise ParseError("%s: error: open block expected: '%s'" % (sys.argv[0], self.lex.text)) 260 | self.lex.advance(skip_nl = True) 261 | 262 | # more data follows... 263 | self._parse_data(do_print) 264 | 265 | # expect a closed block 266 | tok = self.lex.peek() 267 | if tok != self.lex.tok_block_close: 268 | raise ParseError("%s: error: closed block expected: '%s'" % (sys.argv[0], self.lex.text)) 269 | self.lex.advance(skip_nl = True) 270 | 271 | 272 | # function _parse_exp_or 273 | ############################################################################### 274 | def _parse_exp_or(self): 275 | """ 276 | Parse a boolean 'or' expression. 277 | """ 278 | ret = False 279 | while True: 280 | ret = self._parse_exp_and() or ret 281 | 282 | # is the expression terminated? 283 | tok = self.lex.peek() 284 | if tok == self.lex.tok_par_close: 285 | return ret 286 | # expect an 'or' token. 287 | elif tok == self.lex.tok_or: 288 | self.lex.advance() 289 | # everything else is the end of the expression. 290 | # Let the caling function worry about error reporting. 291 | else: 292 | return ret 293 | return False 294 | 295 | 296 | # function _parse_exp_and 297 | ############################################################################### 298 | def _parse_exp_and(self): 299 | """ 300 | Parse a boolean 'and' expression. 301 | """ 302 | ret = True 303 | while True: 304 | ret = self._parse_exp_comparison() and ret 305 | 306 | # is the expression terminated? 307 | tok = self.lex.peek() 308 | if tok == self.lex.tok_par_close: 309 | return ret 310 | # expect an 'and' token. 311 | elif tok == self.lex.tok_and: 312 | self.lex.advance() 313 | # everything else is a parse error. 314 | else: 315 | return ret 316 | return False 317 | 318 | 319 | # function _parse_exp_comparison 320 | ############################################################################### 321 | def _parse_exp_comparison(self): 322 | """ 323 | Parse a boolean comparison. 324 | """ 325 | # left hand side of the comparison 326 | lhs = self._parse_exp_term() 327 | 328 | # expect a comparison 329 | tok = self.lex.peek() 330 | if tok != self.lex.tok_op: 331 | raise ParseError("%s: error: operator expected: '%s'" % (sys.argv[0], self.lex.text)) 332 | operator = self.lex.text 333 | self.lex.advance() 334 | 335 | # right hand side of the comparison 336 | rhs = self._parse_exp_term() 337 | 338 | # if both operands ar numbers, convert them 339 | num_l = self._get_num(lhs) 340 | num_r = self._get_num(rhs) 341 | if num_l != None and num_r != None: 342 | lhs = num_l 343 | rhs = num_r 344 | 345 | # now calculate the result of the comparison, whatever that means 346 | if operator == "<=": 347 | ret = lhs <= rhs 348 | elif operator == "<": 349 | ret = lhs < rhs 350 | elif operator == "==": 351 | ret = lhs == rhs 352 | elif operator == "!=": 353 | ret = lhs != rhs 354 | elif operator == ">=": 355 | ret = lhs >= rhs 356 | elif operator == ">": 357 | ret = lhs > rhs 358 | else: 359 | raise ParseError("%s: error: unknow operator: '%s'" % (sys.argv[0], self.lex.text)) 360 | return ret 361 | 362 | 363 | # function _parse_exp_term 364 | ############################################################################### 365 | def _parse_exp_term(self): 366 | """ 367 | Parse a terminal. 368 | """ 369 | tok = self.lex.peek() 370 | 371 | # identifier 372 | if tok == self.lex.tok_identifier: 373 | try: 374 | ret = self.sym.getTerminal(self.lex.text) 375 | except SymbolLookupError: 376 | raise ParseError("%s: error: unknown terminal '%s'" % (sys.argv[0], self.lex.text)) 377 | if ret == None: 378 | ret = "Undefined" 379 | # string 380 | elif tok == self.lex.tok_str: 381 | ret = self.lex.text 382 | # number 383 | elif tok == self.lex.tok_num: 384 | ret = self.lex.text 385 | # parenthesised expression 386 | elif tok == self.lex.tok_par_open: 387 | self.lex.advance() 388 | ret = self._parse_exp_or() 389 | tok = self.lex.peek() 390 | if tok != self.lex.tok_par_close: 391 | raise ParseError("%s: error: closed parenthesis expected: '%s'" % (sys.argv[0], self.lex.text)) 392 | self.lex.advance() 393 | return ret 394 | 395 | 396 | # function _get_num 397 | ############################################################################### 398 | def _get_num(self, in_str): 399 | """ 400 | Check if in_str is a number and return the numeric value. 401 | """ 402 | ret = None 403 | 404 | if in_str != None: 405 | m = self.re_is_int.match(in_str) 406 | if m != None: 407 | ret = int(in_str) 408 | 409 | m = self.re_is_hex.match(in_str) 410 | if m != None: 411 | ret = int(in_str, 16) 412 | 413 | return ret 414 | -------------------------------------------------------------------------------- /tests/dependencies/esbuild/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crc-test", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "crc-test", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "esbuild": "^0.14.27" 13 | } 14 | }, 15 | "node_modules/esbuild": { 16 | "version": "0.14.27", 17 | "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.14.27.tgz", 18 | "integrity": "sha512-MZQt5SywZS3hA9fXnMhR22dv0oPGh6QtjJRIYbgL1AeqAoQZE+Qn5ppGYQAoHv/vq827flj4tIJ79Mrdiwk46Q==", 19 | "hasInstallScript": true, 20 | "bin": { 21 | "esbuild": "bin/esbuild" 22 | }, 23 | "engines": { 24 | "node": ">=12" 25 | }, 26 | "optionalDependencies": { 27 | "esbuild-android-64": "0.14.27", 28 | "esbuild-android-arm64": "0.14.27", 29 | "esbuild-darwin-64": "0.14.27", 30 | "esbuild-darwin-arm64": "0.14.27", 31 | "esbuild-freebsd-64": "0.14.27", 32 | "esbuild-freebsd-arm64": "0.14.27", 33 | "esbuild-linux-32": "0.14.27", 34 | "esbuild-linux-64": "0.14.27", 35 | "esbuild-linux-arm": "0.14.27", 36 | "esbuild-linux-arm64": "0.14.27", 37 | "esbuild-linux-mips64le": "0.14.27", 38 | "esbuild-linux-ppc64le": "0.14.27", 39 | "esbuild-linux-riscv64": "0.14.27", 40 | "esbuild-linux-s390x": "0.14.27", 41 | "esbuild-netbsd-64": "0.14.27", 42 | "esbuild-openbsd-64": "0.14.27", 43 | "esbuild-sunos-64": "0.14.27", 44 | "esbuild-windows-32": "0.14.27", 45 | "esbuild-windows-64": "0.14.27", 46 | "esbuild-windows-arm64": "0.14.27" 47 | } 48 | }, 49 | "node_modules/esbuild-android-64": { 50 | "version": "0.14.27", 51 | "resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.14.27.tgz", 52 | "integrity": "sha512-LuEd4uPuj/16Y8j6kqy3Z2E9vNY9logfq8Tq+oTE2PZVuNs3M1kj5Qd4O95ee66yDGb3isaOCV7sOLDwtMfGaQ==", 53 | "cpu": [ 54 | "x64" 55 | ], 56 | "optional": true, 57 | "os": [ 58 | "android" 59 | ], 60 | "engines": { 61 | "node": ">=12" 62 | } 63 | }, 64 | "node_modules/esbuild-android-arm64": { 65 | "version": "0.14.27", 66 | "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.14.27.tgz", 67 | "integrity": "sha512-E8Ktwwa6vX8q7QeJmg8yepBYXaee50OdQS3BFtEHKrzbV45H4foMOeEE7uqdjGQZFBap5VAqo7pvjlyA92wznQ==", 68 | "cpu": [ 69 | "arm64" 70 | ], 71 | "optional": true, 72 | "os": [ 73 | "android" 74 | ], 75 | "engines": { 76 | "node": ">=12" 77 | } 78 | }, 79 | "node_modules/esbuild-darwin-64": { 80 | "version": "0.14.27", 81 | "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.27.tgz", 82 | "integrity": "sha512-czw/kXl/1ZdenPWfw9jDc5iuIYxqUxgQ/Q+hRd4/3udyGGVI31r29LCViN2bAJgGvQkqyLGVcG03PJPEXQ5i2g==", 83 | "cpu": [ 84 | "x64" 85 | ], 86 | "optional": true, 87 | "os": [ 88 | "darwin" 89 | ], 90 | "engines": { 91 | "node": ">=12" 92 | } 93 | }, 94 | "node_modules/esbuild-darwin-arm64": { 95 | "version": "0.14.27", 96 | "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.27.tgz", 97 | "integrity": "sha512-BEsv2U2U4o672oV8+xpXNxN9bgqRCtddQC6WBh4YhXKDcSZcdNh7+6nS+DM2vu7qWIWNA4JbRG24LUUYXysimQ==", 98 | "cpu": [ 99 | "arm64" 100 | ], 101 | "optional": true, 102 | "os": [ 103 | "darwin" 104 | ], 105 | "engines": { 106 | "node": ">=12" 107 | } 108 | }, 109 | "node_modules/esbuild-freebsd-64": { 110 | "version": "0.14.27", 111 | "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.27.tgz", 112 | "integrity": "sha512-7FeiFPGBo+ga+kOkDxtPmdPZdayrSzsV9pmfHxcyLKxu+3oTcajeZlOO1y9HW+t5aFZPiv7czOHM4KNd0tNwCA==", 113 | "cpu": [ 114 | "x64" 115 | ], 116 | "optional": true, 117 | "os": [ 118 | "freebsd" 119 | ], 120 | "engines": { 121 | "node": ">=12" 122 | } 123 | }, 124 | "node_modules/esbuild-freebsd-arm64": { 125 | "version": "0.14.27", 126 | "resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.27.tgz", 127 | "integrity": "sha512-8CK3++foRZJluOWXpllG5zwAVlxtv36NpHfsbWS7TYlD8S+QruXltKlXToc/5ZNzBK++l6rvRKELu/puCLc7jA==", 128 | "cpu": [ 129 | "arm64" 130 | ], 131 | "optional": true, 132 | "os": [ 133 | "freebsd" 134 | ], 135 | "engines": { 136 | "node": ">=12" 137 | } 138 | }, 139 | "node_modules/esbuild-linux-32": { 140 | "version": "0.14.27", 141 | "resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.14.27.tgz", 142 | "integrity": "sha512-qhNYIcT+EsYSBClZ5QhLzFzV5iVsP1YsITqblSaztr3+ZJUI+GoK8aXHyzKd7/CKKuK93cxEMJPpfi1dfsOfdw==", 143 | "cpu": [ 144 | "ia32" 145 | ], 146 | "optional": true, 147 | "os": [ 148 | "linux" 149 | ], 150 | "engines": { 151 | "node": ">=12" 152 | } 153 | }, 154 | "node_modules/esbuild-linux-64": { 155 | "version": "0.14.27", 156 | "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.27.tgz", 157 | "integrity": "sha512-ESjck9+EsHoTaKWlFKJpPZRN26uiav5gkI16RuI8WBxUdLrrAlYuYSndxxKgEn1csd968BX/8yQZATYf/9+/qg==", 158 | "cpu": [ 159 | "x64" 160 | ], 161 | "optional": true, 162 | "os": [ 163 | "linux" 164 | ], 165 | "engines": { 166 | "node": ">=12" 167 | } 168 | }, 169 | "node_modules/esbuild-linux-arm": { 170 | "version": "0.14.27", 171 | "resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.14.27.tgz", 172 | "integrity": "sha512-JnnmgUBdqLQO9hoNZQqNHFWlNpSX82vzB3rYuCJMhtkuaWQEmQz6Lec1UIxJdC38ifEghNTBsF9bbe8dFilnCw==", 173 | "cpu": [ 174 | "arm" 175 | ], 176 | "optional": true, 177 | "os": [ 178 | "linux" 179 | ], 180 | "engines": { 181 | "node": ">=12" 182 | } 183 | }, 184 | "node_modules/esbuild-linux-arm64": { 185 | "version": "0.14.27", 186 | "resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.27.tgz", 187 | "integrity": "sha512-no6Mi17eV2tHlJnqBHRLekpZ2/VYx+NfGxKcBE/2xOMYwctsanCaXxw4zapvNrGE9X38vefVXLz6YCF8b1EHiQ==", 188 | "cpu": [ 189 | "arm64" 190 | ], 191 | "optional": true, 192 | "os": [ 193 | "linux" 194 | ], 195 | "engines": { 196 | "node": ">=12" 197 | } 198 | }, 199 | "node_modules/esbuild-linux-mips64le": { 200 | "version": "0.14.27", 201 | "resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.27.tgz", 202 | "integrity": "sha512-NolWP2uOvIJpbwpsDbwfeExZOY1bZNlWE/kVfkzLMsSgqeVcl5YMen/cedRe9mKnpfLli+i0uSp7N+fkKNU27A==", 203 | "cpu": [ 204 | "mips64el" 205 | ], 206 | "optional": true, 207 | "os": [ 208 | "linux" 209 | ], 210 | "engines": { 211 | "node": ">=12" 212 | } 213 | }, 214 | "node_modules/esbuild-linux-ppc64le": { 215 | "version": "0.14.27", 216 | "resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.27.tgz", 217 | "integrity": "sha512-/7dTjDvXMdRKmsSxKXeWyonuGgblnYDn0MI1xDC7J1VQXny8k1qgNp6VmrlsawwnsymSUUiThhkJsI+rx0taNA==", 218 | "cpu": [ 219 | "ppc64" 220 | ], 221 | "optional": true, 222 | "os": [ 223 | "linux" 224 | ], 225 | "engines": { 226 | "node": ">=12" 227 | } 228 | }, 229 | "node_modules/esbuild-linux-riscv64": { 230 | "version": "0.14.27", 231 | "resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.27.tgz", 232 | "integrity": "sha512-D+aFiUzOJG13RhrSmZgrcFaF4UUHpqj7XSKrIiCXIj1dkIkFqdrmqMSOtSs78dOtObWiOrFCDDzB24UyeEiNGg==", 233 | "cpu": [ 234 | "riscv64" 235 | ], 236 | "optional": true, 237 | "os": [ 238 | "linux" 239 | ], 240 | "engines": { 241 | "node": ">=12" 242 | } 243 | }, 244 | "node_modules/esbuild-linux-s390x": { 245 | "version": "0.14.27", 246 | "resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.27.tgz", 247 | "integrity": "sha512-CD/D4tj0U4UQjELkdNlZhQ8nDHU5rBn6NGp47Hiz0Y7/akAY5i0oGadhEIg0WCY/HYVXFb3CsSPPwaKcTOW3bg==", 248 | "cpu": [ 249 | "s390x" 250 | ], 251 | "optional": true, 252 | "os": [ 253 | "linux" 254 | ], 255 | "engines": { 256 | "node": ">=12" 257 | } 258 | }, 259 | "node_modules/esbuild-netbsd-64": { 260 | "version": "0.14.27", 261 | "resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.27.tgz", 262 | "integrity": "sha512-h3mAld69SrO1VoaMpYl3a5FNdGRE/Nqc+E8VtHOag4tyBwhCQXxtvDDOAKOUQexBGca0IuR6UayQ4ntSX5ij1Q==", 263 | "cpu": [ 264 | "x64" 265 | ], 266 | "optional": true, 267 | "os": [ 268 | "netbsd" 269 | ], 270 | "engines": { 271 | "node": ">=12" 272 | } 273 | }, 274 | "node_modules/esbuild-openbsd-64": { 275 | "version": "0.14.27", 276 | "resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.27.tgz", 277 | "integrity": "sha512-xwSje6qIZaDHXWoPpIgvL+7fC6WeubHHv18tusLYMwL+Z6bEa4Pbfs5IWDtQdHkArtfxEkIZz77944z8MgDxGw==", 278 | "cpu": [ 279 | "x64" 280 | ], 281 | "optional": true, 282 | "os": [ 283 | "openbsd" 284 | ], 285 | "engines": { 286 | "node": ">=12" 287 | } 288 | }, 289 | "node_modules/esbuild-sunos-64": { 290 | "version": "0.14.27", 291 | "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.27.tgz", 292 | "integrity": "sha512-/nBVpWIDjYiyMhuqIqbXXsxBc58cBVH9uztAOIfWShStxq9BNBik92oPQPJ57nzWXRNKQUEFWr4Q98utDWz7jg==", 293 | "cpu": [ 294 | "x64" 295 | ], 296 | "optional": true, 297 | "os": [ 298 | "sunos" 299 | ], 300 | "engines": { 301 | "node": ">=12" 302 | } 303 | }, 304 | "node_modules/esbuild-windows-32": { 305 | "version": "0.14.27", 306 | "resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.14.27.tgz", 307 | "integrity": "sha512-Q9/zEjhZJ4trtWhFWIZvS/7RUzzi8rvkoaS9oiizkHTTKd8UxFwn/Mm2OywsAfYymgUYm8+y2b+BKTNEFxUekw==", 308 | "cpu": [ 309 | "ia32" 310 | ], 311 | "optional": true, 312 | "os": [ 313 | "win32" 314 | ], 315 | "engines": { 316 | "node": ">=12" 317 | } 318 | }, 319 | "node_modules/esbuild-windows-64": { 320 | "version": "0.14.27", 321 | "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.27.tgz", 322 | "integrity": "sha512-b3y3vTSl5aEhWHK66ngtiS/c6byLf6y/ZBvODH1YkBM+MGtVL6jN38FdHUsZasCz9gFwYs/lJMVY9u7GL6wfYg==", 323 | "cpu": [ 324 | "x64" 325 | ], 326 | "optional": true, 327 | "os": [ 328 | "win32" 329 | ], 330 | "engines": { 331 | "node": ">=12" 332 | } 333 | }, 334 | "node_modules/esbuild-windows-arm64": { 335 | "version": "0.14.27", 336 | "resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.27.tgz", 337 | "integrity": "sha512-I/reTxr6TFMcR5qbIkwRGvldMIaiBu2+MP0LlD7sOlNXrfqIl9uNjsuxFPGEG4IRomjfQ5q8WT+xlF/ySVkqKg==", 338 | "cpu": [ 339 | "arm64" 340 | ], 341 | "optional": true, 342 | "os": [ 343 | "win32" 344 | ], 345 | "engines": { 346 | "node": ">=12" 347 | } 348 | } 349 | }, 350 | "dependencies": { 351 | "esbuild": { 352 | "version": "0.14.27", 353 | "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.14.27.tgz", 354 | "integrity": "sha512-MZQt5SywZS3hA9fXnMhR22dv0oPGh6QtjJRIYbgL1AeqAoQZE+Qn5ppGYQAoHv/vq827flj4tIJ79Mrdiwk46Q==", 355 | "requires": { 356 | "esbuild-android-64": "0.14.27", 357 | "esbuild-android-arm64": "0.14.27", 358 | "esbuild-darwin-64": "0.14.27", 359 | "esbuild-darwin-arm64": "0.14.27", 360 | "esbuild-freebsd-64": "0.14.27", 361 | "esbuild-freebsd-arm64": "0.14.27", 362 | "esbuild-linux-32": "0.14.27", 363 | "esbuild-linux-64": "0.14.27", 364 | "esbuild-linux-arm": "0.14.27", 365 | "esbuild-linux-arm64": "0.14.27", 366 | "esbuild-linux-mips64le": "0.14.27", 367 | "esbuild-linux-ppc64le": "0.14.27", 368 | "esbuild-linux-riscv64": "0.14.27", 369 | "esbuild-linux-s390x": "0.14.27", 370 | "esbuild-netbsd-64": "0.14.27", 371 | "esbuild-openbsd-64": "0.14.27", 372 | "esbuild-sunos-64": "0.14.27", 373 | "esbuild-windows-32": "0.14.27", 374 | "esbuild-windows-64": "0.14.27", 375 | "esbuild-windows-arm64": "0.14.27" 376 | } 377 | }, 378 | "esbuild-android-64": { 379 | "version": "0.14.27", 380 | "resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.14.27.tgz", 381 | "integrity": "sha512-LuEd4uPuj/16Y8j6kqy3Z2E9vNY9logfq8Tq+oTE2PZVuNs3M1kj5Qd4O95ee66yDGb3isaOCV7sOLDwtMfGaQ==", 382 | "optional": true 383 | }, 384 | "esbuild-android-arm64": { 385 | "version": "0.14.27", 386 | "resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.14.27.tgz", 387 | "integrity": "sha512-E8Ktwwa6vX8q7QeJmg8yepBYXaee50OdQS3BFtEHKrzbV45H4foMOeEE7uqdjGQZFBap5VAqo7pvjlyA92wznQ==", 388 | "optional": true 389 | }, 390 | "esbuild-darwin-64": { 391 | "version": "0.14.27", 392 | "resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.27.tgz", 393 | "integrity": "sha512-czw/kXl/1ZdenPWfw9jDc5iuIYxqUxgQ/Q+hRd4/3udyGGVI31r29LCViN2bAJgGvQkqyLGVcG03PJPEXQ5i2g==", 394 | "optional": true 395 | }, 396 | "esbuild-darwin-arm64": { 397 | "version": "0.14.27", 398 | "resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.27.tgz", 399 | "integrity": "sha512-BEsv2U2U4o672oV8+xpXNxN9bgqRCtddQC6WBh4YhXKDcSZcdNh7+6nS+DM2vu7qWIWNA4JbRG24LUUYXysimQ==", 400 | "optional": true 401 | }, 402 | "esbuild-freebsd-64": { 403 | "version": "0.14.27", 404 | "resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.27.tgz", 405 | "integrity": "sha512-7FeiFPGBo+ga+kOkDxtPmdPZdayrSzsV9pmfHxcyLKxu+3oTcajeZlOO1y9HW+t5aFZPiv7czOHM4KNd0tNwCA==", 406 | "optional": true 407 | }, 408 | "esbuild-freebsd-arm64": { 409 | "version": "0.14.27", 410 | "resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.27.tgz", 411 | "integrity": "sha512-8CK3++foRZJluOWXpllG5zwAVlxtv36NpHfsbWS7TYlD8S+QruXltKlXToc/5ZNzBK++l6rvRKELu/puCLc7jA==", 412 | "optional": true 413 | }, 414 | "esbuild-linux-32": { 415 | "version": "0.14.27", 416 | "resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.14.27.tgz", 417 | "integrity": "sha512-qhNYIcT+EsYSBClZ5QhLzFzV5iVsP1YsITqblSaztr3+ZJUI+GoK8aXHyzKd7/CKKuK93cxEMJPpfi1dfsOfdw==", 418 | "optional": true 419 | }, 420 | "esbuild-linux-64": { 421 | "version": "0.14.27", 422 | "resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.27.tgz", 423 | "integrity": "sha512-ESjck9+EsHoTaKWlFKJpPZRN26uiav5gkI16RuI8WBxUdLrrAlYuYSndxxKgEn1csd968BX/8yQZATYf/9+/qg==", 424 | "optional": true 425 | }, 426 | "esbuild-linux-arm": { 427 | "version": "0.14.27", 428 | "resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.14.27.tgz", 429 | "integrity": "sha512-JnnmgUBdqLQO9hoNZQqNHFWlNpSX82vzB3rYuCJMhtkuaWQEmQz6Lec1UIxJdC38ifEghNTBsF9bbe8dFilnCw==", 430 | "optional": true 431 | }, 432 | "esbuild-linux-arm64": { 433 | "version": "0.14.27", 434 | "resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.27.tgz", 435 | "integrity": "sha512-no6Mi17eV2tHlJnqBHRLekpZ2/VYx+NfGxKcBE/2xOMYwctsanCaXxw4zapvNrGE9X38vefVXLz6YCF8b1EHiQ==", 436 | "optional": true 437 | }, 438 | "esbuild-linux-mips64le": { 439 | "version": "0.14.27", 440 | "resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.27.tgz", 441 | "integrity": "sha512-NolWP2uOvIJpbwpsDbwfeExZOY1bZNlWE/kVfkzLMsSgqeVcl5YMen/cedRe9mKnpfLli+i0uSp7N+fkKNU27A==", 442 | "optional": true 443 | }, 444 | "esbuild-linux-ppc64le": { 445 | "version": "0.14.27", 446 | "resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.27.tgz", 447 | "integrity": "sha512-/7dTjDvXMdRKmsSxKXeWyonuGgblnYDn0MI1xDC7J1VQXny8k1qgNp6VmrlsawwnsymSUUiThhkJsI+rx0taNA==", 448 | "optional": true 449 | }, 450 | "esbuild-linux-riscv64": { 451 | "version": "0.14.27", 452 | "resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.27.tgz", 453 | "integrity": "sha512-D+aFiUzOJG13RhrSmZgrcFaF4UUHpqj7XSKrIiCXIj1dkIkFqdrmqMSOtSs78dOtObWiOrFCDDzB24UyeEiNGg==", 454 | "optional": true 455 | }, 456 | "esbuild-linux-s390x": { 457 | "version": "0.14.27", 458 | "resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.27.tgz", 459 | "integrity": "sha512-CD/D4tj0U4UQjELkdNlZhQ8nDHU5rBn6NGp47Hiz0Y7/akAY5i0oGadhEIg0WCY/HYVXFb3CsSPPwaKcTOW3bg==", 460 | "optional": true 461 | }, 462 | "esbuild-netbsd-64": { 463 | "version": "0.14.27", 464 | "resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.27.tgz", 465 | "integrity": "sha512-h3mAld69SrO1VoaMpYl3a5FNdGRE/Nqc+E8VtHOag4tyBwhCQXxtvDDOAKOUQexBGca0IuR6UayQ4ntSX5ij1Q==", 466 | "optional": true 467 | }, 468 | "esbuild-openbsd-64": { 469 | "version": "0.14.27", 470 | "resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.27.tgz", 471 | "integrity": "sha512-xwSje6qIZaDHXWoPpIgvL+7fC6WeubHHv18tusLYMwL+Z6bEa4Pbfs5IWDtQdHkArtfxEkIZz77944z8MgDxGw==", 472 | "optional": true 473 | }, 474 | "esbuild-sunos-64": { 475 | "version": "0.14.27", 476 | "resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.27.tgz", 477 | "integrity": "sha512-/nBVpWIDjYiyMhuqIqbXXsxBc58cBVH9uztAOIfWShStxq9BNBik92oPQPJ57nzWXRNKQUEFWr4Q98utDWz7jg==", 478 | "optional": true 479 | }, 480 | "esbuild-windows-32": { 481 | "version": "0.14.27", 482 | "resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.14.27.tgz", 483 | "integrity": "sha512-Q9/zEjhZJ4trtWhFWIZvS/7RUzzi8rvkoaS9oiizkHTTKd8UxFwn/Mm2OywsAfYymgUYm8+y2b+BKTNEFxUekw==", 484 | "optional": true 485 | }, 486 | "esbuild-windows-64": { 487 | "version": "0.14.27", 488 | "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.27.tgz", 489 | "integrity": "sha512-b3y3vTSl5aEhWHK66ngtiS/c6byLf6y/ZBvODH1YkBM+MGtVL6jN38FdHUsZasCz9gFwYs/lJMVY9u7GL6wfYg==", 490 | "optional": true 491 | }, 492 | "esbuild-windows-arm64": { 493 | "version": "0.14.27", 494 | "resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.27.tgz", 495 | "integrity": "sha512-I/reTxr6TFMcR5qbIkwRGvldMIaiBu2+MP0LlD7sOlNXrfqIl9uNjsuxFPGEG4IRomjfQ5q8WT+xlF/ySVkqKg==", 496 | "optional": true 497 | } 498 | } 499 | } 500 | --------------------------------------------------------------------------------