Function
writeCertFile
(cert []byte, path string)
Source from the content-addressed store, hash-verified
| 17 | ) |
| 18 | |
| 19 | func writeCertFile(cert []byte, path string) (err error) { |
| 20 | var f *os.File |
| 21 | f, err = os.Create(path) |
| 22 | if err != nil { |
| 23 | return fmt.Errorf("error opening pem file for writing: %w", err) |
| 24 | } |
| 25 | defer func() { |
| 26 | closeErr := f.Close() |
| 27 | if err == nil { |
| 28 | err = closeErr |
| 29 | } |
| 30 | }() |
| 31 | |
| 32 | err = pem.Encode(f, &pem.Block{ |
| 33 | Type: "CERTIFICATE", |
| 34 | Bytes: cert, |
| 35 | }) |
| 36 | if err != nil { |
| 37 | return fmt.Errorf("error encoding CA to pem: %w", err) |
| 38 | } |
| 39 | |
| 40 | log.Printf("created %v", path) |
| 41 | return nil |
| 42 | } |
| 43 | |
| 44 | func Main() error { |
| 45 | var args struct { |
Tested by
no test coverage detected