Skip to content

Commit

Permalink
Stop storing name and directory in container
Browse files Browse the repository at this point in the history
  • Loading branch information
tteeoo committed Sep 12, 2020
1 parent cc82d6b commit f54f7b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions lib/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (

// Container represents a password-containing file
type Container struct {
Name string
name string
Master [3]string
Data string
Dir string
dir string
}

// GetPath returns the path where the container is stored
func (c *Container) GetPath() string {
return c.Dir + "/" + c.Name + ".cont.json"
return c.dir + "/" + c.name + ".cont.json"
}

// Write saves the container to its file
Expand Down Expand Up @@ -47,6 +47,8 @@ func OpenContainer(name, dir string) (*Container, error) {
if err != nil {
return &Container{}, err
}
cont.dir = dir
cont.name = name

return &cont, nil
}
Expand Down Expand Up @@ -83,8 +85,8 @@ func (c *Container) ChangePassword(password, newPassword string) (*Container, er
}

return &Container{
Name: c.Name,
Dir: c.Dir,
name: c.name,
dir: c.dir,
Master: [3]string{bEncode(hash), bEncode(salt), bEncode(encSalt)},
Data: bEncode(encData),
}, nil
Expand Down Expand Up @@ -112,8 +114,8 @@ func NewContainer(name, dir, password string) (*Container, error) {
}

return &Container{
Name: name,
Dir: dir,
name: name,
dir: dir,
Master: [3]string{bEncode(hash), bEncode(salt), bEncode(encSalt)},
Data: bEncode(emptyData),
}, nil
Expand Down Expand Up @@ -160,7 +162,7 @@ func (c *Container) GetData(password string) (map[string]string, error) {
return data, nil
}

return nil, errors.New("invalid password for container '" + c.Name + "'")
return nil, errors.New("invalid password for container '" + c.name + "'")
}

// SetData encrypts the given data with the password and ensures it is the correct password, then it sets the containers .Data
Expand Down Expand Up @@ -200,5 +202,5 @@ func (c *Container) SetData(newData map[string]string, password string) error {
return nil
}

return errors.New("invalid password for container '" + c.Name + "'")
return errors.New("invalid password for container '" + c.name + "'")
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func main() {
os.Exit(0)

case "-V", "--version":
fmt.Println("sest version 0.1.7")
fmt.Println("sest version 0.1.8")

case "-h", "--help":
fmt.Println("sest: secure strings\n\n" +
Expand Down

0 comments on commit f54f7b3

Please sign in to comment.