2021-12-20 04:02:48 -05:00
|
|
|
package gokwallet
|
|
|
|
|
|
|
|
/*
|
|
|
|
NewPassword returns a Password. It requires a RecurseOpts
|
|
|
|
(you can use DefaultRecurseOpts, call NewRecurseOpts, or provide your own RecurseOpts struct).
|
|
|
|
It also requires a Folder.
|
|
|
|
*/
|
|
|
|
func NewPassword(f *Folder, keyName string, recursion *RecurseOpts) (password *Password, err error) {
|
|
|
|
|
|
|
|
if !f.isInit {
|
|
|
|
err = ErrNotInitialized
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
password = &Password{
|
|
|
|
DbusObject: f.DbusObject,
|
|
|
|
Name: keyName,
|
|
|
|
// Value: "",
|
|
|
|
Recurse: recursion,
|
|
|
|
wm: f.wallet.wm,
|
|
|
|
wallet: f.wallet,
|
|
|
|
folder: f,
|
|
|
|
isInit: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
if password.Recurse.AllWalletItems || password.Recurse.Passwords {
|
|
|
|
if err = password.Update(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
password.isInit = true
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-23 04:21:21 -05:00
|
|
|
// Delete will delete this Password from its parent Folder. You may want to run Folder.UpdatePasswords to update the existing map of Password items.
|
|
|
|
func (p *Password) Delete() (err error) {
|
|
|
|
|
|
|
|
if err = p.folder.RemoveEntry(p.Name); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p = nil
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetValue will replace this Password's Password.Value.
|
|
|
|
func (p *Password) SetValue(newValue string) (err error) {
|
|
|
|
|
|
|
|
if _, err = p.folder.WritePassword(p.Name, newValue); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Value = newValue
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-20 04:02:48 -05:00
|
|
|
// Update fetches a Password's Password.Value.
|
|
|
|
func (p *Password) Update() (err error) {
|
|
|
|
|
2021-12-22 03:20:08 -05:00
|
|
|
var b []byte
|
|
|
|
|
|
|
|
if err = p.Dbus.Call(
|
|
|
|
DbusWMReadPassword, 0, p.folder.wallet.handle, p.folder.Name, p.Name, p.folder.wallet.wm.AppID,
|
|
|
|
).Store(&b); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
p.Value = string(b)
|
2021-12-20 04:02:48 -05:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// isWalletItem is needed for interface membership.
|
|
|
|
func (p *Password) isWalletItem() (isWalletItem bool) {
|
|
|
|
|
|
|
|
isWalletItem = true
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|