MCPcopy Index your code
hub / github.com/golang/crypto / TestKeySignWithAlgorithmVerify

Function TestKeySignWithAlgorithmVerify

ssh/keys_test.go:127–168  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

125}
126
127func TestKeySignWithAlgorithmVerify(t *testing.T) {
128 for k, priv := range testSigners {
129 if algorithmSigner, ok := priv.(MultiAlgorithmSigner); !ok {
130 t.Errorf("Signers %q constructed by ssh package should always implement the MultiAlgorithmSigner interface: %T", k, priv)
131 } else {
132 pub := priv.PublicKey()
133 data := []byte("sign me")
134
135 signWithAlgTestCase := func(algorithm string, expectedAlg string) {
136 sig, err := algorithmSigner.SignWithAlgorithm(rand.Reader, data, algorithm)
137 if err != nil {
138 t.Fatalf("Sign(%T): %v", priv, err)
139 }
140 if sig.Format != expectedAlg {
141 t.Errorf("signature format did not match requested signature algorithm: %s != %s", sig.Format, expectedAlg)
142 }
143
144 if err := pub.Verify(data, sig); err != nil {
145 t.Errorf("publicKey.Verify(%T): %v", priv, err)
146 }
147 sig.Blob[5]++
148 if err := pub.Verify(data, sig); err == nil {
149 t.Errorf("publicKey.Verify on broken sig did not fail")
150 }
151 }
152
153 // Using the empty string as the algorithm name should result in the same signature format as the algorithm-free Sign method.
154 defaultSig, err := priv.Sign(rand.Reader, data)
155 if err != nil {
156 t.Fatalf("Sign(%T): %v", priv, err)
157 }
158 signWithAlgTestCase("", defaultSig.Format)
159
160 // RSA keys are the only ones which currently support more than one signing algorithm
161 if pub.Type() == KeyAlgoRSA {
162 for _, algorithm := range []string{KeyAlgoRSA, KeyAlgoRSASHA256, KeyAlgoRSASHA512} {
163 signWithAlgTestCase(algorithm, algorithm)
164 }
165 }
166 }
167 }
168}
169
170func TestKeySignWithShortSignature(t *testing.T) {
171 signer := testSigners["rsa"].(AlgorithmSigner)

Callers

nothing calls this directly

Calls 5

PublicKeyMethod · 0.65
SignWithAlgorithmMethod · 0.65
VerifyMethod · 0.65
SignMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…