mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Make adjustments for easier CGO integration
This commit is contained in:
+3
-2
@@ -10,7 +10,8 @@ import (
|
||||
// GetOldEntryData decrypts and returns old entry data (with all required lines present).
|
||||
// This is a wrapper around the DecryptFileToSlice function that ensures all required lines are present in the returned slice.
|
||||
// This makes it ideal for editing entries, as it guarantees at least a baseline slice length.
|
||||
func GetOldEntryData(realPath string, field int) ([]string, error) {
|
||||
// Leave rcwPassword nil to use RCW demonization.
|
||||
func GetOldEntryData(realPath string, field int, rcwPassword []byte) ([]string, error) {
|
||||
// ensure realPath exists and is a file
|
||||
_, err := back.TargetIsFile(realPath, true)
|
||||
if err != nil {
|
||||
@@ -18,7 +19,7 @@ func GetOldEntryData(realPath string, field int) ([]string, error) {
|
||||
}
|
||||
|
||||
// read old entry data
|
||||
decryptedEntry, err := crypt.DecryptFileToSlice(realPath)
|
||||
decryptedEntry, err := crypt.DecryptFileToSlice(realPath, rcwPassword)
|
||||
if err != nil {
|
||||
return nil, errors.New("unable to decrypt entry: " + err.Error())
|
||||
}
|
||||
|
||||
+3
-2
@@ -19,8 +19,9 @@ import (
|
||||
|
||||
// WriteEntry writes entryData to an encrypted file at realPath.
|
||||
// If the entry contains an updated password, an age file is also created.
|
||||
func WriteEntry(realPath string, decSlice []string, passwordIsNew bool) error {
|
||||
err := os.WriteFile(realPath, crypt.EncryptBytes([]byte(strings.Join(decSlice, "\n"))), 0600)
|
||||
// Leave rcwPassword nil to use RCW demonization.
|
||||
func WriteEntry(realPath string, decSlice []string, passwordIsNew bool, rcwPassword []byte) error {
|
||||
err := os.WriteFile(realPath, crypt.EncryptBytes([]byte(strings.Join(decSlice, "\n")), rcwPassword), 0600)
|
||||
if err != nil {
|
||||
return errors.New("unable to write to file: " + err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user