Add Username Function

This commit is contained in:
2024-10-09 07:41:51 -05:00
parent 365e343a95
commit 822b978034
5 changed files with 127 additions and 15 deletions

View File

@@ -8,13 +8,12 @@ import (
"os"
"strings"
"github.com/tobischo/gokeepasslib"
kp "github.com/tobischo/gokeepasslib"
)
type KeePassDB struct {
path string
db *gokeepasslib.Database
db *kp.Database
}
func NewKeePassDB(filename string, auth string) (*KeePassDB, error) {
@@ -44,6 +43,7 @@ func (db *KeePassDB) GetAllEntriesFromRoot() [][]string {
}
return res
}
func (db *KeePassDB) GetAllEntriesInGroup(group kp.Group) [][]string {
var res [][]string
for _, g := range group.Groups {
@@ -138,7 +138,7 @@ func (db *KeePassDB) GetEntryPassword(path []string) (string, error) {
func (db *KeePassDB) FindEntryFromRoot(path []string) (*kp.Entry, error) {
if len(path) < 2 {
return nil, errors.New("Invalid Path")
return nil, errors.New("invalid path")
}
groups := db.db.Content.Root.Groups
for _, g := range groups {
@@ -146,12 +146,12 @@ func (db *KeePassDB) FindEntryFromRoot(path []string) (*kp.Entry, error) {
return db.FindEntryInGroup(g, path[1:])
}
}
return nil, errors.New("Invalid Path")
return nil, errors.New("invalid path")
}
func (db *KeePassDB) FindEntryInGroup(group kp.Group, path []string) (*kp.Entry, error) {
if len(path) == 0 {
return nil, errors.New("Invalid Path")
return nil, errors.New("invalid path")
} else if len(path) == 1 {
// Looking for an entry in this group
for _, e := range group.Entries {
@@ -159,12 +159,12 @@ func (db *KeePassDB) FindEntryInGroup(group kp.Group, path []string) (*kp.Entry,
return &e, nil
}
}
return nil, errors.New("Invalid Path")
return nil, errors.New("invalid path")
}
for _, g := range group.Groups {
if g.Name == path[0] {
return db.FindEntryInGroup(g, path[1:])
}
}
return nil, errors.New("Invalid Path")
return nil, errors.New("invalid path")
}