Skip to content

Commit

Permalink
Addressed feedback on hex printing and mock -> test signer
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfeidau committed Aug 29, 2024
1 parent 6880862 commit 01baf75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions signature/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"crypto"
"crypto/sha256"
"crypto/x509"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -132,7 +131,7 @@ func Sign(_ context.Context, key Key, sf SignedFielder, opts ...Option) (*pipeli
return nil, fmt.Errorf("calculating key thumbprint: %w", err)
}

debug(options.logger, "Public Key Thumbprint (sha256): %s", hex.EncodeToString(fingerprint))
debug(options.logger, "Public Key Thumbprint (sha256): %x", fingerprint)
case crypto.Signer:
data, err := x509.MarshalPKIXPublicKey(key.Public())
if err != nil {
Expand Down Expand Up @@ -222,7 +221,7 @@ func Verify(ctx context.Context, s *pipeline.Signature, keySet any, sf SignedFie
return fmt.Errorf("calculating key thumbprint: %w", err)
}

debug(options.logger, "Public Key Thumbprint (sha256): %s", hex.EncodeToString(fingerprint))
debug(options.logger, "Public Key Thumbprint (sha256): %x", fingerprint)
}

keyOpt = jws.WithKeySet(keySet)
Expand Down
12 changes: 6 additions & 6 deletions signature/sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,20 @@ func TestSignVerify(t *testing.T) {
}
}

var _ crypto.Signer = MockCryptoSigner{}
var _ crypto.Signer = testECDSASigner{}

type MockCryptoSigner struct {
type testECDSASigner struct {
privateKey crypto.PrivateKey
publickKey crypto.PublicKey
}

func (m MockCryptoSigner) Public() crypto.PublicKey { return m.publickKey }
func (m testECDSASigner) Public() crypto.PublicKey { return m.publickKey }

func (m MockCryptoSigner) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
func (m testECDSASigner) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
return ecdsa.SignASN1(rand, m.privateKey.(*ecdsa.PrivateKey), digest)
}

func (m MockCryptoSigner) Algorithm() jwa.KeyAlgorithm {
func (m testECDSASigner) Algorithm() jwa.KeyAlgorithm {
return jwa.ES256
}

Expand Down Expand Up @@ -237,7 +237,7 @@ func TestSignVerifyCryptoSigner(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

sKey := MockCryptoSigner{
sKey := testECDSASigner{
privateKey: privateKey,
publickKey: publicKey,
}
Expand Down

0 comments on commit 01baf75

Please sign in to comment.