MCPcopy
hub / github.com/jackc/pgx / writePrivateKey

Function writePrivateKey

testsetup/generate_certs.go:120–140  ·  view source on GitHub ↗
(path string, privateKey *rsa.PrivateKey)

Source from the content-addressed store, hash-verified

118}
119
120func writePrivateKey(path string, privateKey *rsa.PrivateKey) error {
121 file, err := os.Create(path)
122 if err != nil {
123 return fmt.Errorf("writePrivateKey: %w", err)
124 }
125
126 err = pem.Encode(file, &pem.Block{
127 Type: "RSA PRIVATE KEY",
128 Bytes: x509.MarshalPKCS1PrivateKey(privateKey),
129 })
130 if err != nil {
131 return fmt.Errorf("writePrivateKey: %w", err)
132 }
133
134 err = file.Close()
135 if err != nil {
136 return fmt.Errorf("writePrivateKey: %w", err)
137 }
138
139 return nil
140}
141
142func writeEncryptedPrivateKey(path string, privateKey *rsa.PrivateKey, password string) error {
143 file, err := os.Create(path)

Callers 1

mainFunction · 0.85

Calls 3

CreateMethod · 0.80
EncodeMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected