github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/auth/key/test/keys_test.go (about) 1 package test 2 3 import ( 4 "encoding/base64" 5 "testing" 6 7 crypto "github.com/libp2p/go-libp2p-core/crypto" 8 "github.com/qri-io/qri/auth/key" 9 ) 10 11 func TestFixtureKeys(t *testing.T) { 12 for i, e := range encoded { 13 data, err := base64.StdEncoding.DecodeString(e.B64PrivKey) 14 if err != nil { 15 t.Errorf("key index %d decoding error: %s", i, err) 16 continue 17 } 18 pk, err := crypto.UnmarshalPrivateKey(data) 19 if err != nil { 20 t.Errorf("key index %d unmarshaling error: %s", i, err) 21 continue 22 } 23 24 str := pk.Type().String() 25 if str != "RSA" && str != "Ed25519" { 26 t.Errorf("key index %d unexpected privKey type: %q", i, str) 27 } 28 29 str, err = key.IDFromPrivKey(pk) 30 if err != nil { 31 t.Errorf("key index %d unexpected error generating ID: %s", i, err) 32 continue 33 } 34 35 if str != e.B58PeerID { 36 t.Errorf("key index mismatch.\ncalculated: %q\nrecorded: %q", str, e.B58PeerID) 37 } 38 } 39 }