romariolopezc/elm-hmac-sha1/3.0.0

NOTE: the latest version is 3.0.1

Renamed to rlopzc/elm-hmac-sha1. It is published under that name, and new versions come out there.

Versions published as romariolopezc/elm-hmac-sha1 still install under that name. 6 versions of 7 come from the new location (see their notes). 1 version could not be recovered and cannot be installed.

Rerouted (cache, verified). The original is gone. This copy comes from a Lamdera package cache made before it went. The Lamdera package server serves a copy recovered from a Lamdera package cache.

What we checked: Rebuilt from the unpacked sources in a Lamdera package cache (3 copies agree), which Elm only writes after the published SHA-1 checked out; elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip is our own, so its SHA-1 is not the published one.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/romariolopezc/elm-hmac-sha1/zipball/3.0.0/

HmacSha1

Computes a Hash-based Message Authentication Code (HMAC) using the SHA-1 hash function

type Digest

An HMAC-SHA1 digest.

fromString : Key -> String -> Digest

Pass a Key and your message as a String to compute a Digest

import HmacSha1.Key as Key


"The quick brown fox jumps over the lazy dog"
    |> fromString (Key.fromString "key")
    |> toHex
--> "de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9"


"The quick brown fox jumps over the lazy dog"
    |> fromString (Key.fromString "key")
    |> toBase64
--> "3nybhbi3iqa8ino29wqQcBydtNk="
fromBytes : Key -> Bytes -> Digest

Pass a Key and your message in Bytes to compute a Digest

import HmacSha1.Key as Key
import Bytes.Encode


Bytes.Encode.sequence []
    |> Bytes.Encode.encode
    |> fromBytes (Key.fromString "")
    |> toBase64
--> "+9sdGxiqbAgyS31ktx+3Y3BpDh0="

Representation

toBytes : Digest -> Bytes

Convert a Digest into elm/bytes Bytes. You can use this to map it to your own representations. I use it to convert it to Base16 and Base64 string representations.

import Bytes
import HmacSha1.Key as Key


fromString (Key.fromString "key") "message"
    |> toBytes
    |> Bytes.width
--> 20
toByteValues : Digest -> List Int

Convert a Digest into a List of Integers. Each Integer is in the range 0-255, and represents one byte. Can be useful for passing digest on to other packages that make use of this convention.

import HmacSha1.Key as Key


fromString (Key.fromString "key") "message"
    |> toByteValues
--> [32, 136, 223, 116, 213, 242, 20, 107, 72, 20, 108, 175, 73, 101, 55, 126, 157, 11, 227, 164]
toHex : Digest -> String

Convert a Digest into a base16 String

import HmacSha1.Key as Key


fromString (Key.fromString "key") "message"
    |> toHex
--> "2088df74d5f2146b48146caf4965377e9d0be3a4"
toBase64 : Digest -> String

Convert a Digest into a base64 String

import HmacSha1.Key as Key


fromString (Key.fromString "key") "message"
    |> toBase64
--> "IIjfdNXyFGtIFGyvSWU3fp0L46Q="