crypto/tls: handle errors in generate_cert.go
I don't expect these to hit often, but we should still alert users if we fail to write the correct data to the file, or fail to close it. Change-Id: I33774e94108f7f18ed655ade8cca229b1993d4d2 Reviewed-on: https://go-review.googlesource.com/91456 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
0957fdb171
commit
137239b5b7
@ -146,16 +146,24 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("failed to open cert.pem for writing: %s", err)
|
||||
}
|
||||
pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
|
||||
certOut.Close()
|
||||
log.Print("written cert.pem\n")
|
||||
if err := pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes}); err != nil {
|
||||
log.Fatalf("failed to write data to cert.pem: %s", err)
|
||||
}
|
||||
if err := certOut.Close(); err != nil {
|
||||
log.Fatalf("error closing cert.pem: %s", err)
|
||||
}
|
||||
log.Print("wrote cert.pem\n")
|
||||
|
||||
keyOut, err := os.OpenFile("key.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
if err != nil {
|
||||
log.Print("failed to open key.pem for writing:", err)
|
||||
return
|
||||
}
|
||||
pem.Encode(keyOut, pemBlockForKey(priv))
|
||||
keyOut.Close()
|
||||
log.Print("written key.pem\n")
|
||||
if err := pem.Encode(keyOut, pemBlockForKey(priv)); err != nil {
|
||||
log.Fatalf("failed to write data to key.pem: %s", err)
|
||||
}
|
||||
if err := keyOut.Close(); err != nil {
|
||||
log.Fatalf("error closing key.pem: %s", err)
|
||||
}
|
||||
log.Print("wrote key.pem\n")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user