搜索插件、代码仓与 APP 分类

插件详情v3.0.0

crclib

一组循环冗余校验 (CRC) 常用程序,作为 Dart 转换器。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
17.6万
喜欢数
16
Pub 分数
140

安装插件

flutter pub add crclib

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

crclib 是一个 Dart 包,提供一组循环冗余校验(CRC)例程作为转换器,旨在实现高效的数据完整性验证。它支持多种 CRC 算法,并可无缝集成到跨 Android、iOS、Web、macOS、Windows 和 Linux 的 Flutter 应用中。该包非常适合用于文件传输、网络通信和嵌入式系统中的数据一致性验证。凭借极低的开销和简单的使用方式,crclib 使开发者能够轻松实现可靠的校验和验证。

适合场景

  • 文件传输中的数据完整性检查
  • 网络数据包验证
  • 嵌入式系统数据验证
  • 固件更新的校验和生成
  • 实时数据流完整性
  • 跨平台CRC计算

主要特点

  • 支持多种CRC算法
  • 轻量且快速的转换器
  • 跨平台兼容性
  • 简单的 API 集成
  • 内置测试用例
  • 可扩展的算法设计

适合对象

  • 需要可靠CRC校验的开发者
  • 需要数据一致性检查的应用程序
  • 具有完整性需求的跨平台项目
  • 固件和嵌入式软件开发
  • 网络协议实现

使用建议

  • 确保为用例选择正确的CRC算法
  • 在处理前验证输入数据格式
  • 不适合用于加密哈希
  • 对大型数据流的性能影响
  • 仅限CRC特定用途
  • 需要仔细处理字节数组

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Dart crclib

This is not an official Google product.

Generic CRC calculations as Dart converters and some common algorithms.

To calculate the CRC value of any message

The easiest way to use this library is to call convert on the instance of the desired CRC routine.

  Crc32Xz().convert(utf8.encode('123456789')) == 0xCBF43926

Another supported use case is as stream transformers.

  File(...).openRead().transform(Crc32Xz()).single.then(...)

Instead of using predefined classes, it is also possible to construct a customized CRC function with ParametricCrc class. For a list of known CRC routines, check out https://reveng.sourceforge.io/crc-catalogue/all.htm.

TODO:

  1. inputReflected and outputReflected can be different, see CRC-12/UMTS.
  2. Bit-level checksums (including non-multiple-of-8 checksums).

To flip bits to obtain desired CRC values

With CrcFlipper, one can call flipWithData or flipWithValue depending on whether they have access to the message, or only its calculated CRC value. The snippet below is taken from test/flipper_test.dart.

      var inputMessage =
          'flipping lowercases to uppercases like mama pig making hot pancakes '
          'for daddy pig in peppa pig cartoon';
      // Mark the lower/upper-case bit in each character.
      // 0x61 = 'a' = 0110 0001
      //                | <-- 5th bit, zero-indexed
      // 0x41 = 'A' = 0100 0001
      var positions = inputMessage.codeUnits
          .asMap()
          .entries
          .where((e) => e.value >= 0x61 && e.value < 0x61 + 26)
          .map((e) => e.key * 8 + 5)
          .toSet();
      var flipper = CrcFlipper(Crc64());
      var solution = flipper.flipWithData(inputMessage.codeUnits, positions,
          CrcValue(BigInt.parse('DEADBEEFCAFEBABE', radix: 16)))!;
      var tmp = List.of(inputMessage.codeUnits, growable: false);
      solution.forEach((bitPosition) {
        var mask = 1 << (bitPosition % 8);
        tmp[bitPosition ~/ 8] ^= mask;
      });
      var outputMessage = String.fromCharCodes(tmp);
      expect(
          outputMessage,
          'flIPpiNG LOWErcAsEs To uPpERcaseS LIkE mAmA Pig mAKInG hOT paNcAKEs '
          'For DAdDY pig in peppa pig cartoon');

The detailed algorithm is documented in flipping_algorithm.md.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目