(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func TestEncodeDecodeRSAPrivateKey(t *testing.T) { |
| 31 | privateKey, err := rsa.GenerateKey(rand.Reader, 128) // make tests faster; small key size OK for testing |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | |
| 36 | // test save |
| 37 | savedBytes, err := PEMEncodePrivateKey(privateKey) |
| 38 | if err != nil { |
| 39 | t.Fatal("error saving private key:", err) |
| 40 | } |
| 41 | |
| 42 | // test load |
| 43 | loadedKey, err := PEMDecodePrivateKey(savedBytes) |
| 44 | if err != nil { |
| 45 | t.Error("error loading private key:", err) |
| 46 | } |
| 47 | |
| 48 | // test load (should fail) |
| 49 | _, err = PEMDecodePrivateKey(savedBytes[2:]) |
| 50 | if err == nil { |
| 51 | t.Error("loading private key should have failed") |
| 52 | } |
| 53 | |
| 54 | // verify loaded key is correct |
| 55 | if !privateKeysSame(privateKey, loadedKey) { |
| 56 | t.Error("Expected key bytes to be the same, but they weren't") |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | func TestSaveAndLoadECCPrivateKey(t *testing.T) { |
| 61 | privateKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader) |
nothing calls this directly
no test coverage detected
searching dependent graphs…