github.com/haraldrudell/parl@v0.4.176/parlca/ed25519-public_test.go (about) 1 /* 2 © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/) 3 ISC License 4 */ 5 6 package parlca 7 8 import ( 9 "strings" 10 "testing" 11 12 "github.com/haraldrudell/parl" 13 "github.com/haraldrudell/parl/perrors" 14 ) 15 16 func TestEd25519Public(t *testing.T) { 17 var publicKey parl.PublicKey 18 //var publicKeyDer parl.PublicKeyDer 19 var pemBytes parl.PemBytes 20 var keyPair parl.PrivateKey 21 var err error 22 23 expPem := "-----BEGIN PUBLIC KEY-----\n" 24 25 // get public key 26 if keyPair, err = NewEd25519(); err != nil { 27 t.Errorf("Error NewEd25519: %s", perrors.Short(err)) 28 t.FailNow() 29 } 30 publicKey = keyPair.PublicKey() 31 32 /* 33 // test DER 34 publicKeyDer = publicKey.DERe() 35 if len(publicKeyDer) != ed25519.PublicKeySize { 36 t.Errorf("Bad len public: %d exp %d", len(publicKeyDer), ed25519.PublicKeySize) 37 } 38 */ 39 // test PEM 40 pemBytes = publicKey.PEMe() 41 pemString := string(pemBytes) 42 43 // pem: "-----BEGIN PUBLIC KEY-----\ni1lp/BZZ8nyCjAe6c1Xj8DzP6Pnc8ApFXbgdrvrXDy0=\n-----END PUBLIC KEY-----\n" 44 //t.Logf("pem: %q", s) 45 46 if !strings.Contains(pemString, expPem) { 47 t.Errorf("bad pem string: %q", pemString) 48 } 49 }