(t *testing.T)
| 58 | } |
| 59 | |
| 60 | func TestSaveAndLoadECCPrivateKey(t *testing.T) { |
| 61 | privateKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader) |
| 62 | if err != nil { |
| 63 | t.Fatal(err) |
| 64 | } |
| 65 | |
| 66 | // test save |
| 67 | savedBytes, err := PEMEncodePrivateKey(privateKey) |
| 68 | if err != nil { |
| 69 | t.Fatal("error saving private key:", err) |
| 70 | } |
| 71 | |
| 72 | // test load |
| 73 | loadedKey, err := PEMDecodePrivateKey(savedBytes) |
| 74 | if err != nil { |
| 75 | t.Error("error loading private key:", err) |
| 76 | } |
| 77 | |
| 78 | // verify loaded key is correct |
| 79 | if !privateKeysSame(privateKey, loadedKey) { |
| 80 | t.Error("Expected key bytes to be the same, but they weren't") |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // privateKeysSame compares the bytes of a and b and returns true if they are the same. |
| 85 | func privateKeysSame(a, b crypto.PrivateKey) bool { |
nothing calls this directly
no test coverage detected
searching dependent graphs…