File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -190,6 +190,9 @@ func (s Signer) sign(buff []byte) ([]byte, error) {
190190 return ecdsaSignRaw (rand .Reader , & key , hashed [:])
191191 case "ed25519" :
192192 key := s .key .(ed25519.PrivateKey )
193+ if len (key ) != ed25519 .PrivateKeySize {
194+ return nil , fmt .Errorf ("key must be %d bytes long" , ed25519 .PrivateKeySize )
195+ }
193196 return ed25519 .Sign (key , buff ), nil
194197 default :
195198 return nil , fmt .Errorf ("sign: unknown algorithm \" %s\" " , s .alg )
Original file line number Diff line number Diff line change 11package httpsign
22
33import (
4+ "crypto/ed25519"
45 "crypto/rand"
56 "crypto/rsa"
67 "github.com/lestrrat-go/jwx/v2/jwa"
@@ -100,6 +101,18 @@ func TestSigner_sign(t *testing.T) {
100101 want : nil ,
101102 wantErr : true ,
102103 },
104+ {
105+ name : "ed25519 key not 64 bytes" ,
106+ fields : fields {
107+ key : ed25519 .PrivateKey (strings .Repeat ("a" , 63 )),
108+ alg : "ed25519" ,
109+ },
110+ args : args {
111+ buff : []byte ("abc" ),
112+ },
113+ want : nil ,
114+ wantErr : true ,
115+ },
103116 }
104117 for _ , tt := range tests {
105118 t .Run (tt .name , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments