Skip to content

Commit

Permalink
Merge pull request #130 from mirage/update-readme
Browse files Browse the repository at this point in the history
Improve the README.md
  • Loading branch information
dinosaure authored Mar 20, 2022
2 parents 7dabdfd + 83c47cb commit 5edd0f3
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Digestif - Hash algorithms in C and OCaml
=========================================

[![Build Status](https://travis-ci.org/mirage/digestif.svg?branch=master)](https://travis-ci.org/mirage/digestif)

Digestif is a toolbox which implements hashes:

* MD5
Expand All @@ -23,12 +21,52 @@ implementation he wants to use. We provide 2 implementations:
Both are well-tested. However, OCaml implementation is slower than the C
implementation.

**Note**: The linking trick requires `digestif.c` or `digestif.ocaml` to be the first of your dependencies.
**Note**: The linking trick requires `digestif.c` or `digestif.ocaml` to be the
first of your dependencies.

Documentation: https://mirage.github.io/digestif/

Contact: Romain Calascibetta `<romain.calascibet ta@gmail.com>`

## Install & Usage

The library is available on [OPAM][]. You can install it via:
```sh
$ opem install digestif
```

This is a simple program which implements `sha1sum`:
```sh
$ cat >sha1sum.ml <<EOF
let sum ic =
let tmp = Bytes.create 0x1000 in
let rec go ctx = match input ic tmp 0 0x1000 with
| 0 -> Digestif.SHA1.get ctx
| len ->
let ctx = Digestif.SHA1.feed_bytes ctx ~off:0 ~len tmp in
go ctx
| exception End_of_file -> Digestif.SHA1.get ctx in
go Digestif.SHA1.empty
let () = match Sys.argv with
| [| _; filename; |] when Sys.file_exists filename ->
let ic = open_in filename in
let hash = sum ic in
close_in ic ; print_endline (Digestif.SHA1.to_hex hash)
| [| _ |] ->
let hash = sum stdin in
print_endline (Digestif.SHA1.to_hex hash)
| _ -> Format.eprintf "%s [<filename>]\n%!" Sys.argv.(0)
EOF
$ cat >dune <<EOF
(executable
(name sha1sum)
(libraries digestif))
EOF
$ dune exec ./sha1sum.exe -- sha1sum.ml
fe6e6639a817c23857b507e2d833ec776f23f327
```

## API

For each hash, we implement the same API which is referentially transparent.
Expand Down Expand Up @@ -74,7 +112,8 @@ This work is from the [nocrypto](https://github.com/mirleft/nocrypto) library
and the Vincent hanquez's work in
[ocaml-sha](https://github.com/vincenthz/ocaml-sha).

All credits appear in the begin of files and this library is motivated by two reasons:

* delete the dependancy with `nocrypto` if you don't use the encryption (and common) part
All credits appear in the begin of files and this library is motivated by two
reasons:
* delete the dependancy with `nocrypto` if you don't use the encryption (and
common) part
* aggregate all hashes functions in one library

0 comments on commit 5edd0f3

Please # to comment.