File is a wrapper around Data that reads a local encrypted file and returns its cleartext data in an []byte
(path, format string)
| 18 | // File is a wrapper around Data that reads a local encrypted |
| 19 | // file and returns its cleartext data in an []byte |
| 20 | func File(path, format string) (cleartext []byte, err error) { |
| 21 | // Read the file into an []byte |
| 22 | encryptedData, err := os.ReadFile(path) |
| 23 | if err != nil { |
| 24 | return nil, fmt.Errorf("Failed to read %q: %w", path, err) |
| 25 | } |
| 26 | |
| 27 | // uses same logic as cli. |
| 28 | formatFmt := FormatForPathOrString(path, format) |
| 29 | return DataWithFormat(encryptedData, formatFmt) |
| 30 | } |
| 31 | |
| 32 | // DataWithFormat is a helper that takes encrypted data, and a format enum value, |
| 33 | // decrypts the data and returns its cleartext in an []byte. |