File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ package crypto
2
+
3
+ import (
4
+ "bytes"
5
+ "crypto/rand"
6
+ "testing"
7
+
8
+ "github.com/stretchr/testify/assert"
9
+ )
10
+
11
+ const (
12
+ testPublicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAOhB7/zzhC+HXDdGOdLwJln5NYwm6UNXx3chmQSVTG4\n "
13
+ testPrivateKey = `-----BEGIN OPENSSH PRIVATE KEY-----
14
+ b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtz
15
+ c2gtZWQyNTUxOQAAACADoQe/884Qvh1w3RjnS8CZZ+TWMJulDV8d3IZkElUxuAAA
16
+ AIggISIjICEiIwAAAAtzc2gtZWQyNTUxOQAAACADoQe/884Qvh1w3RjnS8CZZ+TW
17
+ MJulDV8d3IZkElUxuAAAAEAAAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0e
18
+ HwOhB7/zzhC+HXDdGOdLwJln5NYwm6UNXx3chmQSVTG4AAAAAAECAwQF
19
+ -----END OPENSSH PRIVATE KEY-----
20
+ `
21
+ )
22
+
23
+ func TestGeneratingEd25519Keypair (t * testing.T ) {
24
+ // Temp override the rand.Reader for deterministic testing.
25
+ oldReader := rand .Reader
26
+ defer func () {
27
+ rand .Reader = oldReader
28
+ }()
29
+
30
+ // Only 32 bytes needs to be provided to generate a ed25519 keypair.
31
+ // And another 32 bytes are required, which is included as random value
32
+ // in the OpenSSH format.
33
+ b := make ([]byte , 64 )
34
+ for i := 0 ; i < 64 ; i ++ {
35
+ b [i ] = byte (i )
36
+ }
37
+ rand .Reader = bytes .NewReader (b )
38
+
39
+ publicKey , privateKey , err := GenerateEd25519Keypair ()
40
+ assert .NoError (t , err )
41
+ assert .EqualValues (t , testPublicKey , string (publicKey ))
42
+ assert .EqualValues (t , testPrivateKey , string (privateKey ))
43
+ }
You can’t perform that action at this time.
0 commit comments