authenticate: encrypt & mac oauth2 callback state

- cryptutil: add hmac & tests
- cryptutil: rename cipher / encoders to be more clear
- cryptutil: simplify SecureEncoder interface
- cryptutil: renamed NewCipherFromBase64 to NewAEADCipherFromBase64
- cryptutil: move key & random generators to helpers

Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
Bobby DeSimone 2019-09-19 08:56:48 -07:00
parent 3a806c6dfc
commit 7c755d833f
No known key found for this signature in database
GPG key ID: AEE4CF12FE86D07E
26 changed files with 539 additions and 464 deletions

View file

@ -5,31 +5,13 @@ import (
"testing"
)
func TestMockCipher_Unmarshal(t *testing.T) {
func TestMockEncoder(t *testing.T) {
e := errors.New("err")
mc := MockCipher{
EncryptResponse: []byte("EncryptResponse"),
EncryptError: e,
DecryptResponse: []byte("DecryptResponse"),
DecryptError: e,
mc := MockEncoder{
MarshalResponse: "MarshalResponse",
MarshalError: e,
UnmarshalError: e,
}
b, err := mc.Encrypt([]byte("test"))
if string(b) != "EncryptResponse" {
t.Error("unexpected encrypt response")
}
if err != e {
t.Error("unexpected encrypt error")
}
b, err = mc.Decrypt([]byte("test"))
if string(b) != "DecryptResponse" {
t.Error("unexpected Decrypt response")
}
if err != e {
t.Error("unexpected Decrypt error")
}
s, err := mc.Marshal("test")
if err != e {
t.Error("unexpected Marshal error")