aboutsummaryrefslogtreecommitdiff
path: root/account.go
diff options
context:
space:
mode:
Diffstat (limited to 'account.go')
-rw-r--r--account.go28
1 files changed, 11 insertions, 17 deletions
diff --git a/account.go b/account.go
index 8456ce7..a513d6e 100644
--- a/account.go
+++ b/account.go
@@ -8,19 +8,19 @@ import (
"io"
"strings"
- "gopkg.in/square/go-jose.v1"
+ "github.com/square/go-jose"
)
// KeySize is a default RSA key size
const KeySize = 2048
-// Account ...
-type Account struct {
+// Signer ...
+type Signer struct {
signer jose.Signer
thumb string
}
-func NewAccount(privKey crypto.PrivateKey) (*Account, error) {
+func NewSigner(privKey crypto.PrivateKey) (*Signer, error) {
thumb := func(alg string, pubKey crypto.PublicKey) (string, error) {
wk := &jose.JsonWebKey{Key: pubKey, Algorithm: alg}
t, err := wk.Thumbprint(crypto.SHA256)
@@ -36,7 +36,7 @@ func NewAccount(privKey crypto.PrivateKey) (*Account, error) {
if err != nil {
return nil, err
}
- return &Account{signer: s, thumb: t}, nil
+ return &Signer{signer: s, thumb: t}, nil
case *ecdsa.PrivateKey:
s, err := jose.NewSigner(jose.ES384, k)
if err != nil {
@@ -46,28 +46,22 @@ func NewAccount(privKey crypto.PrivateKey) (*Account, error) {
if err != nil {
return nil, err
}
- return &Account{signer: s, thumb: t}, nil
+ return &Signer{signer: s, thumb: t}, nil
default:
return nil, errKeyType
}
}
-// Signer describes a signing interface
-type Signer interface {
- Sign([]byte, jose.NonceSource) (io.Reader, error)
- KeyAuth(string) string
-}
-
// Sign implements Signer interface
-func (a Account) Sign(msg []byte, n jose.NonceSource) (io.Reader, error) {
- a.signer.SetNonceSource(n)
- obj, err := a.signer.Sign(msg)
+func (s Signer) Sign(msg []byte, n jose.NonceSource) (io.Reader, error) {
+ s.signer.SetNonceSource(n)
+ obj, err := s.signer.Sign(msg)
if err != nil {
return nil, err
}
return strings.NewReader(obj.FullSerialize()), nil
}
-func (a Account) KeyAuth(token string) string {
- return token + "." + a.thumb
+func (s Signer) KeyAuth(token string) string {
+ return token + "." + s.thumb
}