Giter Club home page Giter Club logo

pruefung's Introduction

pruefung

Checksums in pure Rust.

TravisCI Codecov Source Crate Documentation CargoMake Changelog SayThanks

THIS LIBRARY DOES NOT PROVIDE A STABLE API YET !

Usage

Add this crate to the Cargo.toml:

[dependencies]
pruefung = "^0.1.0"

Check out the Sums section to see the minimal required version you need depending on the algorithm you wish to use.

All the checksums are implemented using the same logic as the hashes crate of the RustCrypto project, implementing the digest::Digest, and the core::hasher::Hasher traits when possible (less than 64 bits in the output).

Then, to compute a hash, for instance a CRC32 (Ethernet standard):

extern crate pruefung;
use std::hash::Hasher;

let mut hasher = pruefung::crc32::CRC32();   // Instantiate a hasher
let data = b"Hello, world !";

hasher.write(data);                          // Feed the hasher
hasher.write("String data".as_bytes());      // (possibly multiple times)

let hash = hasher.finish();                  // Consume the hasher
println!("Result: {:x}", hash)               // print the result as native hex

Dependencies

The crate itself is no_std, but provides digest::Digest implementations for convenience and integration with the hashes crate. Those bindings can be scrapped off however by disabling the default features of the crates, adding the following line to yout Cargo.toml:

[dependencies.pruefung]
version = "^0.1.0"
default-features = false

Sums

Latest version of the crate implements the following checksums:

Algorithm since implemented as
Adler32 0.1.0 ::adler32::Adler32
BSD checksum 0.2.0 ::bsd::Bsd
CRC8 0.3.0 ::crc::crc8::Crc8
CRC16 0.3.0 ::crc::crc8::Crc16
CRC32 0.2.0 ::crc::crc32::Crc32
CRC32C 0.2.0 ::crc::crc32::Crc32c
CRC64 0.3.0 ::crc::crc64::Crc64
Fletcher16 0.1.0 ::fletcher16::Fletcher16
FNV0-32 0.2.0 ::fnv::fnv32::Fnv32z
FNV1-32 0.2.0 ::fnv::fnv32::Fnv32
FNV1a-32 0.2.0 ::fnv::fnv32::Fnv32a
FNV0-64 0.2.0 ::fnv::fnv64::Fnv64z
FNV1-64 0.2.0 ::fnv::fnv64::Fnv64
FNV1a-64 0.2.0 ::fnv::fnv64::Fnv64a
SysV checksum 0.1.0 ::sysv::SysV
UNIX checksum 0.2.0 ::unix::Unix

These checksums are NOT cryptographically secure. They should not be used for something else than data validation against accidental modifications: an attacker could easily forge a file to pass any of these checksums ! For secure checksums, look at the hashes implemented by the RustCrypto team.

Credits

Why pruefung ?

I was in Switzerland when I started this project. Yet, I don't really speak german. But a slug version of zyklische-redundanzprüfung seemed like a nice name, instead of another checksum, cksum, checksums, crc, etc. crate.

pruefung's People

Contributors

dependabot-preview[bot] avatar fmckeogh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

fmckeogh johnpeel

pruefung's Issues

Few questions about PR

Hello!

I’m working on a PR to add crc8, crc16 and crc64 algorithms and have a few questions.

  • Running cargo fmt resulted in a whole lot of changes. Would you prefer a second PR for that?
  • Would you be OK with adding a feature for choosing between precalculated and live generated tables? IE if a user is memory constrained then precalculated makes sense, if a user is space constrained then live makes sense
  • I plan on making the default be to use ANSI definitions of each algorithms constants, and allow both the selection of different standards and the use of custom polynomials, start values and final values. I’m not sure if both are necessary, as someone needing to use a non-ANSI version likely knows what constants they need.

Thanks!

makefile suggestions

cargo-make is really new so trying to help adoption of it and got few suggestions that might help a bit.
None of them are a must, but could improve things a bit.

  • tasks.audit - your task is exactly the same as in the default.toml, so I think you can remove your declaration. tasks defined in default.toml are automatically available so you can use it without redefining it.
    This would help keep your makefile small and simple.
  • tasks.coverage looks like tasks.coverage-tarpaulin so you can just put an alias
[tasks.coverage]
alias = "tasks.coverage-tarpaulin"

instead of redefining the task.

  • travis cache for cargo-make should be disabled otherwise you are not getting new task definitions and new features.
    For example with the version you are running, you are missing tasks.coverage-tarpaulin.
    You could keep the cache but always install cargo-make using the cargo install --force flag so the cache will be kept for other rust crates that are used.

  • you can merge multiple calls to cargo make to a single call.
    for example you have

  - cargo make audit
  - cargo make chandler

But you can define a task that has dependencies to both of these (letscall it after_script),

[tasks.after_script]
dependencies = ["audit", "chandler"]

and than just call: cargo make after_script.
this would help make your travis yml smaller and allow you to call that flow manually from your dev machine with a single command.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.