go.crypto/ssh: introduce PublicKey interface type.

Public functions affected:
-AgentKey.Key
-AgentClient.SignRequest
-ClientKeyring.Key
-MarshalPublicKey
-ParsePublicKey

R=agl, jpsugar, jmpittman
CC=golang-dev
https://golang.org/cl/13642043
This commit is contained in:
Han-Wen Nienhuys
2013-09-13 14:25:14 -04:00
committed by Adam Langley
parent 6a743c56c7
commit e62b2aead4
12 changed files with 448 additions and 439 deletions
+3 -3
View File
@@ -1,7 +1,6 @@
package test
import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"reflect"
@@ -124,6 +123,7 @@ AwEHoUQDQgAEi9Hdw6KvZcWxfg2IDhA7UkpDtzzt6ZqJXSsFdLd+Kx4S3Sx4cVO+
func TestMarshalParsePublicKey(t *testing.T) {
pub := getTestPublicKey(t)
authKeys := ssh.MarshalAuthorizedKey(pub)
actualFields := strings.Fields(string(authKeys))
if len(actualFields) == 0 {
@@ -170,7 +170,7 @@ func testAuthorizedKeys(t *testing.T, authKeys []byte, expected []authResult) {
}
func getTestPublicKey(t *testing.T) *rsa.PublicKey {
func getTestPublicKey(t *testing.T) ssh.PublicKey {
block, _ := pem.Decode([]byte(testClientPrivateKey))
if block == nil {
t.Fatalf("pem.Decode: %v", testClientPrivateKey)
@@ -180,7 +180,7 @@ func getTestPublicKey(t *testing.T) *rsa.PublicKey {
t.Fatalf("x509.ParsePKCS1PrivateKey: %v", err)
}
return &priv.PublicKey
return ssh.NewRSAPublicKey(&priv.PublicKey)
}
func TestAuth(t *testing.T) {
+4 -4
View File
@@ -71,7 +71,7 @@ func init() {
if err != nil {
panic("ParsePKCS1PrivateKey: " + err.Error())
}
serializedHostKey = ssh.MarshalPublicKey(&priv.PublicKey)
serializedHostKey = ssh.MarshalPublicKey(ssh.NewRSAPublicKey(&priv.PublicKey))
}
type server struct {
@@ -266,15 +266,15 @@ type keychain struct {
keys []interface{}
}
func (k *keychain) Key(i int) (interface{}, error) {
func (k *keychain) Key(i int) (ssh.PublicKey, error) {
if i < 0 || i >= len(k.keys) {
return nil, nil
}
switch key := k.keys[i].(type) {
case *rsa.PrivateKey:
return &key.PublicKey, nil
return ssh.NewRSAPublicKey(&key.PublicKey), nil
case *dsa.PrivateKey:
return &key.PublicKey, nil
return ssh.NewDSAPublicKey(&key.PublicKey), nil
}
panic("unknown key type")
}