From 57f3ce0eaa73014a45f04d3ff6c9009cc5718cdd Mon Sep 17 00:00:00 2001 From: Dolf Schimmel Date: Sat, 22 Dec 2018 00:08:54 +0100 Subject: [PATCH 1/2] Ensure we set the conn on key in Keys() --- agent/conn.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/conn.go b/agent/conn.go index 81b94d2..f93eab2 100644 --- a/agent/conn.go +++ b/agent/conn.go @@ -217,7 +217,7 @@ func (conn *Conn) Keys() ([]Key, error) { } for i, key := range keyList { - key.conn = conn + keyList[i].conn = conn if keyList[i].publicKey, err = conn.readKey(key.Keygrip); err != nil { return nil, err } From c0c90dde467c4a9d85e03c30c5c9385427027723 Mon Sep 17 00:00:00 2001 From: Dolf Schimmel Date: Sun, 23 Dec 2018 18:17:19 +0100 Subject: [PATCH 2/2] Use pointer receiver for methods --- agent/key.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/agent/key.go b/agent/key.go index 38ed34d..e98fb16 100644 --- a/agent/key.go +++ b/agent/key.go @@ -49,7 +49,7 @@ type Key struct { } // Public returns this key's public key. -func (key Key) Public() crypto.PublicKey { +func (key *Key) Public() crypto.PublicKey { return key.publicKey } @@ -58,7 +58,7 @@ func (key Key) Public() crypto.PublicKey { // opts must have type *OAEPOptions and OAEP decryption is done. // // This function is basically a copy of rsa.Decrypt(). -func (key Key) Decrypt(rand io.Reader, ciphertext []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error) { +func (key *Key) Decrypt(rand io.Reader, ciphertext []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error) { switch pub := key.publicKey.(type) { case *rsa.PublicKey: priv := &internalrsa.PrivateKey{ @@ -105,7 +105,7 @@ func (key Key) Decrypt(rand io.Reader, ciphertext []byte, opts crypto.DecrypterO // will be used. // // This function is basically a copy of rsa.Sign(). -func (key Key) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { +func (key *Key) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signature []byte, err error) { switch pub := key.publicKey.(type) { case *rsa.PublicKey: priv := &internalrsa.PrivateKey{ @@ -126,7 +126,7 @@ func (key Key) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) (signatu } } -func (key Key) decrypt(c *big.Int) (*big.Int, error) { +func (key *Key) decrypt(c *big.Int) (*big.Int, error) { encCipherText, err := encodeRSACipherText(c.Bytes()) if err != nil { return nil, err @@ -175,7 +175,7 @@ func (key Key) decrypt(c *big.Int) (*big.Int, error) { return (&big.Int{}).SetBytes(plaintext), nil } -func (key Key) signPKCS1v15(msg []byte, opts crypto.SignerOpts) ([]byte, error) { +func (key *Key) signPKCS1v15(msg []byte, opts crypto.SignerOpts) ([]byte, error) { var hashType string switch opts.HashFunc() { case crypto.MD5: