@@ -22,7 +22,7 @@ func TestX25519Keys(t *testing.T) {
2222
2323 cfg := struct {
2424 Priv * xtypes.X25519PrivateKey
25- Pub * xtypes.X25519PublicKey
25+ Pub * xtypes.X25519PubKey
2626 }{}
2727
2828 testProvider := cfgtest .New (types.ParamValues {
@@ -49,7 +49,7 @@ func TestX25519KeysHex(t *testing.T) {
4949
5050 cfg := struct {
5151 Priv * xtypes.X25519PrivateKey
52- Pub * xtypes.X25519PublicKey
52+ Pub * xtypes.X25519PubKey
5353 }{}
5454
5555 testProvider := cfgtest .New (types.ParamValues {
@@ -76,10 +76,10 @@ func TestX25519KeysBase64Raw(t *testing.T) {
7676
7777 cfg := struct {
7878 Priv * xtypes.X25519PrivateKey
79- Pub * xtypes.X25519PublicKey
79+ Pub * xtypes.X25519PubKey
8080 }{
8181 Priv : & xtypes.X25519PrivateKey {Base64Encoder : base64 .StdEncoding },
82- Pub : & xtypes.X25519PublicKey {Base64Encoder : base64 .StdEncoding },
82+ Pub : & xtypes.X25519PubKey {Base64Encoder : base64 .StdEncoding },
8383 }
8484
8585 testProvider := cfgtest .New (types.ParamValues {
@@ -106,10 +106,10 @@ func TestX25519KeysBase64PEM(t *testing.T) {
106106
107107 cfg := struct {
108108 Priv * xtypes.X25519PrivateKey
109- Pub * xtypes.X25519PublicKey
109+ Pub * xtypes.X25519PubKey
110110 }{
111111 Priv : & xtypes.X25519PrivateKey {Base64Encoder : base64 .StdEncoding },
112- Pub : & xtypes.X25519PublicKey {Base64Encoder : base64 .StdEncoding },
112+ Pub : & xtypes.X25519PubKey {Base64Encoder : base64 .StdEncoding },
113113 }
114114
115115 testProvider := cfgtest .New (types.ParamValues {
@@ -137,7 +137,7 @@ func TestX25519ValueValid(t *testing.T) {
137137 assert .Error (t , priv .ValueValid ("" ))
138138
139139 _ , pubPEM := generateTestX25519PubKey (t , nil )
140- pub := & xtypes.X25519PublicKey {}
140+ pub := & xtypes.X25519PubKey {}
141141
142142 assert .NoError (t , pub .ValueValid (pubPEM ))
143143 assert .NoError (t , pub .ValueValid (hex .EncodeToString (make ([]byte , 32 ))))
@@ -168,7 +168,10 @@ func generateTestX25519PubKey(t *testing.T, priv *ecdh.PrivateKey) (*ecdh.Public
168168 if priv != nil {
169169 pub = priv .PublicKey ()
170170 } else {
171- newPriv , _ := ecdh .X25519 ().GenerateKey (rand .Reader )
171+ newPriv , err := ecdh .X25519 ().GenerateKey (rand .Reader )
172+ if err != nil {
173+ t .Fatalf ("failed to generate X25519 private key: %v" , err )
174+ }
172175 pub = newPriv .PublicKey ()
173176 }
174177
@@ -182,3 +185,32 @@ func generateTestX25519PubKey(t *testing.T, priv *ecdh.PrivateKey) (*ecdh.Public
182185 }
183186 return pub , string (pem .EncodeToMemory (pemBlock ))
184187}
188+
189+ func TestX25519PubKey_GetDefaultValue (t * testing.T ) {
190+ pub , _ := generateTestX25519PubKey (t , nil )
191+ pubHex := hex .EncodeToString (pub .Bytes ())
192+
193+ t .Run ("nil default" , func (t * testing.T ) {
194+ xt := & xtypes.X25519PubKey {DefaultValue : nil }
195+ val , err := xt .GetDefaultValue ()
196+ assert .NoError (t , err )
197+ assert .Equal (t , "" , val )
198+ })
199+
200+ t .Run ("standard encoding (hex)" , func (t * testing.T ) {
201+ xt := & xtypes.X25519PubKey {DefaultValue : pub }
202+ val , err := xt .GetDefaultValue ()
203+ assert .NoError (t , err )
204+ assert .Equal (t , pubHex , val )
205+ })
206+
207+ t .Run ("with base64 encoder" , func (t * testing.T ) {
208+ xt := & xtypes.X25519PubKey {
209+ DefaultValue : pub ,
210+ Base64Encoder : base64 .StdEncoding ,
211+ }
212+ val , err := xt .GetDefaultValue ()
213+ assert .NoError (t , err )
214+ assert .Equal (t , base64 .StdEncoding .EncodeToString (pub .Bytes ()), val )
215+ })
216+ }
0 commit comments