make initV1Directory publically accessible and usable
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dan Ballard 2021-09-29 11:38:03 -07:00
parent 20fcf8cf13
commit ee8f20b203
1 changed files with 15 additions and 7 deletions

View File

@ -39,15 +39,25 @@ func (ps *ProfileStoreV1) CheckPassword(checkpass string) bool {
return oldkey == ps.key
}
func initV1Directory(directory, password string) ([32]byte, [128]byte, error) {
// InitV1Directory generates a key and salt from a password, writes a SALT and VERSION file and returns the key and salt
func InitV1Directory(directory, password string) ([32]byte, [128]byte, error) {
os.Mkdir(directory, 0700)
key, salt, err := CreateKeySalt(password)
if err != nil {
log.Errorf("Could not create key for profile store from password: %v\n", err)
return [32]byte{}, [128]byte{}, err
}
ioutil.WriteFile(path.Join(directory, versionFile), []byte(version), 0600)
ioutil.WriteFile(path.Join(directory, saltFile), salt[:], 0600)
if err = ioutil.WriteFile(path.Join(directory, versionFile), []byte(version), 0600); err != nil {
log.Errorf("Could not write version file: %v", err)
return [32]byte{}, [128]byte{}, err
}
if err = ioutil.WriteFile(path.Join(directory, saltFile), salt[:], 0600); err != nil {
log.Errorf("Could not write salt file: %v", err)
return [32]byte{}, [128]byte{}, err
}
return key, salt, nil
}
@ -55,9 +65,7 @@ func initV1Directory(directory, password string) ([32]byte, [128]byte, error) {
// CreateProfileWriterStore creates a profile store backed by a filestore listening for events and saving them
// directory should be $appDir/profiles/$rand
func CreateProfileWriterStore(eventManager event.Manager, directory, password string, profile *model.Profile) *ProfileStoreV1 {
os.Mkdir(directory, 0700)
key, salt, err := initV1Directory(directory, password)
key, salt, err := InitV1Directory(directory, password)
if err != nil {
return nil
}
@ -136,7 +144,7 @@ func ReadProfile(directory string, key [32]byte, salt [128]byte) (*model.Profile
// UpgradeV0Profile takes a profile (presumably from a V0 store) and creates and writes a V1 store
func UpgradeV0Profile(profile *model.Profile, directory, password string) error {
key, salt, err := initV1Directory(directory, password)
key, salt, err := InitV1Directory(directory, password)
if err != nil {
return err
}