@@ -10,7 +10,9 @@ package ssh
10
10
11
11
import (
12
12
"crypto/rand"
13
+ "errors"
13
14
"fmt"
15
+ "io"
14
16
15
17
"golang.org/x/crypto/ssh/testdata"
16
18
)
21
23
testPublicKeys map [string ]PublicKey
22
24
)
23
25
26
+ type testAlgoSigner struct {
27
+ signer Signer
28
+ algo string
29
+ }
30
+
31
+ func (tas * testAlgoSigner ) SignWithAlgorithm (rand io.Reader , data []byte , algorithm string ) (* Signature , error ) {
32
+ if as , ok := tas .signer .(AlgorithmSigner ); ok {
33
+ if algorithm == "" {
34
+ algorithm = tas .algo
35
+ }
36
+ return as .SignWithAlgorithm (rand , data , algorithm )
37
+ }
38
+ return nil , errors .New ("not an AlgorithmSigner" )
39
+ }
40
+
41
+ func (tas * testAlgoSigner ) Sign (rand io.Reader , data []byte ) (* Signature , error ) {
42
+ if as , ok := tas .signer .(AlgorithmSigner ); ok {
43
+ return as .SignWithAlgorithm (rand , data , tas .algo )
44
+ }
45
+ return nil , errors .New ("not an AlgorithmSigner" )
46
+ }
47
+
48
+ func (tas * testAlgoSigner ) PublicKey () PublicKey {
49
+ return tas .signer .PublicKey ()
50
+ }
51
+
24
52
func init () {
25
53
var err error
26
54
@@ -40,6 +68,13 @@ func init() {
40
68
testPublicKeys [t ] = testSigners [t ].PublicKey ()
41
69
}
42
70
71
+ // Create rsa-sha2-256 and rsa-sha2-512 signers
72
+ for _ , t := range []string {"rsa-sha2-256" , "rsa-sha2-512" } {
73
+ testPrivateKeys [t ] = testPrivateKeys ["rsa" ]
74
+ testSigners [t ] = & testAlgoSigner {signer : testSigners ["rsa" ], algo : t }
75
+ testPublicKeys [t ] = testSigners [t ].PublicKey ()
76
+ }
77
+
43
78
// Create a cert and sign it for use in tests.
44
79
testCert := & Certificate {
45
80
Nonce : []byte {}, // To pass reflect.DeepEqual after marshal & parse, this must be non-nil
0 commit comments