mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-28 12:56:31 -04:00
31 lines
849 B
Go
31 lines
849 B
Go
package core
|
|
|
|
import (
|
|
"github.com/rwinkhart/go-boilerplate/back"
|
|
"github.com/rwinkhart/libmutton/crypt"
|
|
)
|
|
|
|
// GetOldEntryData decrypts and returns old entry data (with all required lines present).
|
|
func GetOldEntryData(targetLocation string, field int) []string {
|
|
// ensure targetLocation exists
|
|
back.TargetIsFile(targetLocation, true, 2)
|
|
|
|
// read old entry data
|
|
unencryptedEntry := crypt.DecryptFileToSlice(targetLocation)
|
|
|
|
// return the old entry data with all required lines present
|
|
if field > 0 {
|
|
return ensureSliceLength(unencryptedEntry, field)
|
|
} else {
|
|
return unencryptedEntry
|
|
}
|
|
}
|
|
|
|
// ensureSliceLength is a utility function that ensures a slice is long enough to contain the specified index.
|
|
func ensureSliceLength(slice []string, index int) []string {
|
|
for len(slice) <= index {
|
|
slice = append(slice, "")
|
|
}
|
|
return slice
|
|
}
|