MCPcopy Index your code
hub / github.com/caddyserver/certmagic / TestSaveAndLoadECCPrivateKey

Function TestSaveAndLoadECCPrivateKey

crypto_test.go:60–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

58}
59
60func 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.
85func privateKeysSame(a, b crypto.PrivateKey) bool {

Callers

nothing calls this directly

Calls 5

PEMEncodePrivateKeyFunction · 0.85
PEMDecodePrivateKeyFunction · 0.85
privateKeysSameFunction · 0.85
ErrorMethod · 0.80
GenerateKeyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…