Skip to content

Commit

Permalink
Make elm-verify-examples work
Browse files Browse the repository at this point in the history
  • Loading branch information
TSFoster committed Oct 30, 2019
1 parent d835dad commit 97f84ab
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elm-stuff
tests/elm-verify-examples.json
/elm-stuff
/tests/VerifyExamples/
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ import HmacSha1

canonicalString : String
canonicalString =
["application/json", "", "/account", "Wed, 02 Nov 2016 17:26:52 GMT"]
|> String.join ","
String.join ","
[ "application/json"
, ""
, "/account"
, "Wed, 02 Nov 2016 17:26:52 GMT"
]

HmacSha1.digest "verify-secret" canonicalString
|> HmacSha1.toBase64
|> HmacSha1.toBase64
--> Ok "nLet/JEZG9CRXHScwaQ/na4vsKQ="
```

Expand Down
30 changes: 11 additions & 19 deletions src/HmacSha1.elm
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ digest key message =
You can use this to map it to your own representations. I use it to convert it to
Base16 and Base64 string representations.
toBytes (digest "key" "message")
--> <80 bytes>
import Bytes
digest "key" "message"
|> toBytes
|> Bytes.width
--> 20
-}
toBytes : Digest -> Bytes
Expand All @@ -71,8 +75,7 @@ toBytes (Digest data) =
Byte representation as a list of integers.
toIntList (digest "key" "message")
|> toIntList
--> [32,136,223,116,213,242,20,107,72,20,108,175,73,101,55,126,157,11,227,164]
--> [32, 136, 223, 116, 213, 242, 20, 107, 72, 20, 108, 175, 73, 101, 55, 126, 157, 11, 227, 164]
-}
toIntList : Digest -> List Int
Expand All @@ -82,14 +85,9 @@ toIntList (Digest data) =

{-| Convert a Digest into a base64 String Result
case toBase64 (digest "key" "message") of
Ok base64String ->
"Base64 string: " ++ base64String
Err err ->
"Failed to convert the digest"
--> Base64 string: IIjfdNXyFGtIFGyvSWU3fp0L46Q=
toBase64 (digest "key" "message")
--> Ok "IIjfdNXyFGtIFGyvSWU3fp0L46Q="
-}
toBase64 : Digest -> Result String String
Expand All @@ -99,14 +97,8 @@ toBase64 (Digest data) =

{-| Convert a Digest into a base16 String Result
case toHex (digest "key" "message") of
Ok base16String ->
"Hex string: " ++ base16String
Err err ->
"Failed to convert the digest"
--> Hex string: 2088DF74D5F2146B48146CAF4965377E9D0BE3A4
toHex (digest "key" "message")
--> Ok "2088DF74D5F2146B48146CAF4965377E9D0BE3A4"
-}
toHex : Digest -> Result String String
Expand Down
4 changes: 4 additions & 0 deletions tests/elm-verify-examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": "../src",
"tests": ["./README.md", "HmacSha1"]
}

0 comments on commit 97f84ab

Please sign in to comment.