blot/
lib.rs

1// Copyright 2018 Arnau Siches
2//
3// Licensed under the MIT license <LICENSE or http://opensource.org/licenses/MIT>.
4// This file may not be copied, modified, or distributed except according to
5// those terms.
6
7//! Blot library
8//!
9//! **blot** computes the checksum for the given blob of data following the
10//! [Objecthash] algorithm adapted to work with [Multihash] hints.
11//!
12//! [Objecthash]: https://github.com/benlaurie/objecthash
13//! [Multihash]: https://github.com/multiformats/multihash
14//!
15//! blot foundation is the trait [`Blot`]. By default all Rust's primitives
16//! are implemented (See [`core`]). If you need more flexibility, either implement it for your
17//! types or use [`value::Value`].
18//!
19//! [`Blot`] requires a hashing function implementing the [`Multihash`] trait. The `default` feature
20//! enables SHA1, SHA2, SHA3 and Blake2.
21//!
22//! # Example: primitives
23//!
24//! ```
25//! use blot::core::Blot;
26//! use blot::multihash::Sha3256;
27//!
28//! println!("{}", "foo".digest(Sha3256));
29//! println!("{}", 1.digest(Sha3256));
30//! println!("{}", vec![1, 2, 3].digest(Sha3256));
31//! ```
32//!
33//! # Example: mixed collections
34//!
35//! Mixed collections require a type able to describe them consistently, like the [`value::Value`]
36//! enum.
37//!
38//! ```
39//! #[macro_use]
40//! extern crate blot;
41//! use blot::core::Blot;
42//! use blot::multihash::Sha3256;
43//! use blot::value::Value;
44//!
45//! fn main() {
46//!     let value: Value<Sha3256> = set!{"foo", "bar", list![1, 1.0], set!{}};
47//!
48//!     println!("{}", value.digest(Sha3256));
49//! }
50//! ```
51
52#[cfg(feature = "blot_json")]
53#[macro_use]
54extern crate lazy_static;
55#[cfg(feature = "blot_json")]
56extern crate regex;
57#[cfg(feature = "blot_json")]
58extern crate serde;
59#[cfg(feature = "blot_json")]
60extern crate serde_json;
61
62extern crate hex;
63
64#[cfg(feature = "blake2")]
65extern crate blake2 as crypto_blake2;
66#[cfg(feature = "sha-1")]
67extern crate sha1 as crypto_sha1;
68#[cfg(feature = "sha2")]
69extern crate sha2 as crypto_sha2;
70#[cfg(feature = "sha3")]
71extern crate sha3 as crypto_sha3;
72
73pub mod core;
74pub mod multihash;
75pub mod seal;
76pub mod tag;
77pub mod uvar;
78pub mod value;
79
80#[cfg(feature = "blot_json")]
81pub mod json;
82
83pub use core::Blot;
84pub use multihash::Multihash;