Giter Club home page Giter Club logo

Comments (8)

Ulrar avatar Ulrar commented on August 20, 2024

That's a good question. Also it would be nice, for those of us who don't speak crypto, to provide an example or two as to how this is supposed to be used, because even looking at the test file I have no idea as to how hmac is supposed to be called. Thanks !

from digestif.

dinosaure avatar dinosaure commented on August 20, 2024

Hi, you are true and I really would like to fix it but it's much more about build-system than this project. However, I think, from previous improvements needed by ocaml-git, it's possible now to generate a documentation.

About hmac, signature is:

val hmac: key:buffer -> buffer -> t

For any hash algorithm with Bytes.t as input and output or Bigstring.t as input and output. That means, if you want to generate a keyed-hash (SHA1), you should write:

# let hash = Digestif.SHA1.Bytes.hmac ~key:(Bytes.of_string "my-key") (Bytes.of_string "my-message");;
- Bytes.t

Then, you can use Digestif.SHA1.Bytes.to_hex to have the hexadecimal representation of your hash. Finally, you can define a short-cut on top of your program like: module SHA1 = Digestif.SHA1.Bytes precisely because Bytes.t and Bigstring.t are incompatible.

from digestif.

Ulrar avatar Ulrar commented on August 20, 2024

I see, and I assume that to check you just re-sign the message and then use compare on both signatures ? What are init, get and feed used for, just for my own curiosity ?
Thanks !

from digestif.

dinosaure avatar dinosaure commented on August 20, 2024

init, get and feed are a couple of functions which need (or create) a state to be used in an imperative context. In other words, digest : buffer -> t (which produces a hash of your buffer) is implemented like this:

module SHA1 = Digestif.SHA1.Bytes

let digest content =
  let state = SHA1.init () in
  SHA1.feed state content;
  SHA1.get state

This implementation is useful when you want to compute a data flow (and feed state with each chunk of your flow). Then, you just need to use get to ... get the final hash.

from digestif.

dinosaure avatar dinosaure commented on August 20, 2024

Updated by #39

from digestif.

Ulrar avatar Ulrar commented on August 20, 2024

Sorry, me again. Seems like this changed, and the doc in the README went away.
Is there any info about how to use the new version anywhere ? Thanks
Your site seems to be down

Digestif.SHA256.digest_bytes (Bytes.of_string s) |> Digestif.SHA256.to_hex

Error: Required module 'Digestif' is unavailable

from digestif.

dinosaure avatar dinosaure commented on August 20, 2024

See #49

from digestif.

dinosaure avatar dinosaure commented on August 20, 2024

The documentation exists here: https://mirage.github.io/digestif

from digestif.

Related Issues (20)

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.