-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from aidantwoods/result-type
Result type
- Loading branch information
Showing
22 changed files
with
420 additions
and
513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package encoding | ||
|
||
import ( | ||
"encoding/hex" | ||
|
||
t "aidanwoods.dev/go-result" | ||
) | ||
|
||
// Encode hex | ||
func HexEncode(bytes []byte) string { | ||
return hex.EncodeToString(bytes) | ||
} | ||
|
||
// Decode hex | ||
func HexDecode(encoded string) t.Result[[]byte] { | ||
return t.NewResult(hex.DecodeString(encoded)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,17 @@ | ||
package hashing | ||
|
||
import ( | ||
"hash" | ||
|
||
t "aidanwoods.dev/go-result" | ||
"golang.org/x/crypto/blake2b" | ||
) | ||
|
||
// GenericHash The same as crypto_generichash as referred to in the Paseto spec | ||
func GenericHash(in, out, key []byte) { | ||
var blake hash.Hash | ||
var err error | ||
|
||
if blake, err = blake2b.New(len(out), key); err != nil { | ||
panic(err) | ||
} | ||
blake := t.NewResult(blake2b.New(len(out), key)). | ||
Expect("blake2 hasher construction should be provided with valid length inputs") | ||
|
||
if _, err = blake.Write(in); err != nil { | ||
panic(err) | ||
} | ||
t.NewResult(blake.Write(in)). | ||
Expect("writing into hasher should not fail") | ||
|
||
copy(out, blake.Sum(nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.