@@ -726,3 +726,49 @@ func TestNewSignerWithAlgos(t *testing.T) {
726
726
t .Error ("signer with algos created with restricted algorithms" )
727
727
}
728
728
}
729
+
730
+ func TestCryptoPublicKey (t * testing.T ) {
731
+ for _ , priv := range testSigners {
732
+ p1 := priv .PublicKey ()
733
+ key , ok := p1 .(CryptoPublicKey )
734
+ if ! ok {
735
+ continue
736
+ }
737
+ p2 , err := NewPublicKey (key .CryptoPublicKey ())
738
+ if err != nil {
739
+ t .Fatalf ("NewPublicKey(CryptoPublicKey) failed for %s, got: %v" , p1 .Type (), err )
740
+ }
741
+ if ! reflect .DeepEqual (p1 , p2 ) {
742
+ t .Errorf ("got %#v in NewPublicKey, want %#v" , p2 , p1 )
743
+ }
744
+ }
745
+ for _ , d := range testdata .SKData {
746
+ p1 , _ , _ , _ , err := ParseAuthorizedKey (d .PubKey )
747
+ if err != nil {
748
+ t .Fatalf ("parseAuthorizedKey returned error: %v" , err )
749
+ }
750
+ k1 , ok := p1 .(CryptoPublicKey )
751
+ if ! ok {
752
+ t .Fatalf ("%T does not implement CryptoPublicKey" , p1 )
753
+ }
754
+
755
+ var p2 PublicKey
756
+ switch pub := k1 .CryptoPublicKey ().(type ) {
757
+ case * ecdsa.PublicKey :
758
+ p2 = & skECDSAPublicKey {
759
+ application : "ssh:" ,
760
+ PublicKey : * pub ,
761
+ }
762
+ case ed25519.PublicKey :
763
+ p2 = & skEd25519PublicKey {
764
+ application : "ssh:" ,
765
+ PublicKey : pub ,
766
+ }
767
+ default :
768
+ t .Fatalf ("unexpected type %T from CryptoPublicKey()" , pub )
769
+ }
770
+ if ! reflect .DeepEqual (p1 , p2 ) {
771
+ t .Errorf ("got %#v, want %#v" , p2 , p1 )
772
+ }
773
+ }
774
+ }
0 commit comments