checking in for tests
This commit is contained in:
parent
1f6cfd5883
commit
07c38ce23e
4
TODO
4
TODO
@ -2,6 +2,8 @@
|
|||||||
-- compat with kwalletmanager
|
-- compat with kwalletmanager
|
||||||
--- Will require conversion to different struct model.
|
--- Will require conversion to different struct model.
|
||||||
|
|
||||||
- walletCheck on all items' operations?
|
- walletCheck on all items' and folders' operations?
|
||||||
|
|
||||||
|
- close Dbus.Conn
|
||||||
|
|
||||||
- TESTS
|
- TESTS
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
func NewBlob(f *Folder, keyName string, recursion *RecurseOpts) (blob *Blob, err error) {
|
func NewBlob(f *Folder, keyName string, recursion *RecurseOpts) (blob *Blob, err error) {
|
||||||
|
|
||||||
if !f.isInit {
|
if !f.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitFolder
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ func NewBlob(f *Folder, keyName string, recursion *RecurseOpts) (blob *Blob, err
|
|||||||
folder: f,
|
folder: f,
|
||||||
isInit: false,
|
isInit: false,
|
||||||
}
|
}
|
||||||
|
blob.isInit = true
|
||||||
|
|
||||||
if blob.Recurse.AllWalletItems || blob.Recurse.Blobs {
|
if blob.Recurse.AllWalletItems || blob.Recurse.Blobs {
|
||||||
if err = blob.Update(); err != nil {
|
if err = blob.Update(); err != nil {
|
||||||
@ -65,11 +66,16 @@ func (b *Blob) SetValue(newValue []byte) (err error) {
|
|||||||
// Update fetches a Blob's Blob.Value.
|
// Update fetches a Blob's Blob.Value.
|
||||||
func (b *Blob) Update() (err error) {
|
func (b *Blob) Update() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var v dbus.Variant
|
var v dbus.Variant
|
||||||
|
|
||||||
if err = b.Dbus.Call(
|
if call = b.Dbus.Call(
|
||||||
DbusWMReadEntry, 0, b.folder.wallet.handle, b.folder.Name, b.Name, b.folder.wallet.wm.AppID,
|
DbusWMReadEntry, 0, b.folder.wallet.handle, b.folder.Name, b.Name, b.folder.wallet.wm.AppID,
|
||||||
).Store(&v); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&v); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1,20 @@
|
|||||||
package gokwallet
|
package gokwallet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewBlob(t *testing.T) {
|
||||||
|
|
||||||
|
var err error
|
||||||
|
var f *Folder
|
||||||
|
var b *Blob
|
||||||
|
|
||||||
|
if _, _, f, err = getTestEnv(t); err != nil {
|
||||||
|
t.Fatalf("failure getting test env: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// if b, err = NewBlob(f)
|
||||||
|
_ = f
|
||||||
|
_ = b
|
||||||
|
}
|
||||||
|
15
consts_test.go
Normal file
15
consts_test.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package gokwallet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Strings.
|
||||||
|
const (
|
||||||
|
appIdTest string = "GoKwallet_Test"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
walletTest uuid.UUID = uuid.New()
|
||||||
|
folderTest uuid.UUID = uuid.New()
|
||||||
|
)
|
29
errs.go
29
errs.go
@ -11,14 +11,17 @@ var (
|
|||||||
this would lead to a Wallet missing a handler).
|
this would lead to a Wallet missing a handler).
|
||||||
It is intended as a safety check (so that you don't accidentally delete a wallet with e.g. a handler of 0 when
|
It is intended as a safety check (so that you don't accidentally delete a wallet with e.g. a handler of 0 when
|
||||||
trying to delete a different wallet).
|
trying to delete a different wallet).
|
||||||
|
It's mostly a placeholder for more specific errors.
|
||||||
*/
|
*/
|
||||||
ErrNotInitialized error = errors.New("object not properly initialized")
|
ErrNotInitialized error = errors.New("object not properly initialized")
|
||||||
/*
|
/*
|
||||||
ErrOperationFailed is a generic failure message that will occur of a Dbus operation returns non-success.
|
ErrOperationFailed is a generic failure message that will occur of a Dbus operation returns non-success.
|
||||||
|
It is a placeholder for more specific messages.
|
||||||
*/
|
*/
|
||||||
ErrOperationFailed error = errors.New("a Dbus operation has failed to execute successfully")
|
ErrOperationFailed error = errors.New("a Dbus operation has failed to execute successfully")
|
||||||
/*
|
/*
|
||||||
ErrNoCreate is triggered if attempting to create an item (Folder, Password, etc.) but it fails.
|
ErrNoCreate is triggered if attempting to create an item (Folder, Password, etc.) but it fails.
|
||||||
|
It is a placeholder for more specific messages.
|
||||||
*/
|
*/
|
||||||
ErrNoCreate error = errors.New("failed to create an object")
|
ErrNoCreate error = errors.New("failed to create an object")
|
||||||
// ErrNoDisconnect can occur if trying to disconnect a Wallet from a WalletManager/application and a failure occurs.
|
// ErrNoDisconnect can occur if trying to disconnect a Wallet from a WalletManager/application and a failure occurs.
|
||||||
@ -26,3 +29,29 @@ var (
|
|||||||
// ErrInvalidMap will get triggered if a populated map[string]string (even an empty one) is expected but a nil is received.
|
// ErrInvalidMap will get triggered if a populated map[string]string (even an empty one) is expected but a nil is received.
|
||||||
ErrInvalidMap error = errors.New("invalid map; cannot be nil")
|
ErrInvalidMap error = errors.New("invalid map; cannot be nil")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Dbus Operation failures.
|
||||||
|
var (
|
||||||
|
// ErrDbusOpfailNoHandle returns when attempting to open a Wallet and assign to Wallet.handle but received a nil handle.
|
||||||
|
ErrDbusOpfailNoHandle error = errors.New("a wallet handler request returned nil")
|
||||||
|
// ErrDbusOpfailRemoveFolder occurs when attempting to delete/remove a Folder from a Wallet but it did not complete successfully.
|
||||||
|
ErrDbusOpfailRemoveFolder error = errors.New("failed to remove/delete a Folder from a Wallet")
|
||||||
|
)
|
||||||
|
|
||||||
|
// Initialization errors. They are more "detailed" ErrNotInitialized errors.
|
||||||
|
var (
|
||||||
|
// ErrInitWM occurs if a WalletManager is not initialized properly.
|
||||||
|
ErrInitWM error = errors.New("a WalletManager was not properly initialized")
|
||||||
|
// ErrInitWallet occurs if a Wallet is not initialized properly.
|
||||||
|
ErrInitWallet error = errors.New("a Wallet was not properly initialized")
|
||||||
|
// ErrInitFolder occurs if a Folder is not initialized properly.
|
||||||
|
ErrInitFolder error = errors.New("a Folder was not properly initialized")
|
||||||
|
// ErrInitBlob occurs if a Blob is not initialized properly.
|
||||||
|
ErrInitBlob error = errors.New("a Blob was not properly initialized")
|
||||||
|
// ErrInitMap occurs if a Map is not initialized properly.
|
||||||
|
ErrInitMap error = errors.New("a Map was not properly initialized")
|
||||||
|
// ErrInitPassword occurs if a Password is not initialized properly.
|
||||||
|
ErrInitPassword error = errors.New("a Password was not properly initialized")
|
||||||
|
// ErrInitUnknownItem occurs if an UnknownItem is not initialized properly.
|
||||||
|
ErrInitUnknownItem error = errors.New("an UnknownItem was not properly initialized")
|
||||||
|
)
|
||||||
|
130
folder_funcs.go
130
folder_funcs.go
@ -12,7 +12,7 @@ import (
|
|||||||
func NewFolder(w *Wallet, name string, recursion *RecurseOpts) (folder *Folder, err error) {
|
func NewFolder(w *Wallet, name string, recursion *RecurseOpts) (folder *Folder, err error) {
|
||||||
|
|
||||||
if !w.isInit {
|
if !w.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitWallet
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +29,8 @@ func NewFolder(w *Wallet, name string, recursion *RecurseOpts) (folder *Folder,
|
|||||||
isInit: false,
|
isInit: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
folder.isInit = true
|
||||||
|
|
||||||
if folder.Recurse.AllWalletItems ||
|
if folder.Recurse.AllWalletItems ||
|
||||||
folder.Recurse.Passwords ||
|
folder.Recurse.Passwords ||
|
||||||
folder.Recurse.Maps ||
|
folder.Recurse.Maps ||
|
||||||
@ -62,9 +64,15 @@ func (f *Folder) Delete() (err error) {
|
|||||||
// HasEntry specifies if a Folder has an entry (WalletItem item) by the give entryName.
|
// HasEntry specifies if a Folder has an entry (WalletItem item) by the give entryName.
|
||||||
func (f *Folder) HasEntry(entryName string) (hasEntry bool, err error) {
|
func (f *Folder) HasEntry(entryName string) (hasEntry bool, err error) {
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
var call *dbus.Call
|
||||||
|
|
||||||
|
if call = f.Dbus.Call(
|
||||||
DbusWMHasEntry, 0, f.wallet.handle, f.Name, entryName, f.wallet.wm.AppID,
|
DbusWMHasEntry, 0, f.wallet.handle, f.Name, entryName, f.wallet.wm.AppID,
|
||||||
).Store(&hasEntry); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&hasEntry); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,9 +86,15 @@ func (f *Folder) HasEntry(entryName string) (hasEntry bool, err error) {
|
|||||||
*/
|
*/
|
||||||
func (f *Folder) KeyNotExist(entryName string) (doesNotExist bool, err error) {
|
func (f *Folder) KeyNotExist(entryName string) (doesNotExist bool, err error) {
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
var call *dbus.Call
|
||||||
|
|
||||||
|
if call = f.Dbus.Call(
|
||||||
DbusWMKeyNotExist, 0, f.wallet.Name, f.Name, entryName,
|
DbusWMKeyNotExist, 0, f.wallet.Name, f.Name, entryName,
|
||||||
).Store(&doesNotExist); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&doesNotExist); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,9 +104,15 @@ func (f *Folder) KeyNotExist(entryName string) (doesNotExist bool, err error) {
|
|||||||
// ListEntries lists all entries (WalletItem items) in a Folder (regardless of type) by name.
|
// ListEntries lists all entries (WalletItem items) in a Folder (regardless of type) by name.
|
||||||
func (f *Folder) ListEntries() (entryNames []string, err error) {
|
func (f *Folder) ListEntries() (entryNames []string, err error) {
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
var call *dbus.Call
|
||||||
|
|
||||||
|
if call = f.Dbus.Call(
|
||||||
DbusWMEntryList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
DbusWMEntryList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
||||||
).Store(&entryNames); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&entryNames); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,11 +122,16 @@ func (f *Folder) ListEntries() (entryNames []string, err error) {
|
|||||||
// RemoveEntry removes a WalletItem from a Folder given its entryName (key).
|
// RemoveEntry removes a WalletItem from a Folder given its entryName (key).
|
||||||
func (f *Folder) RemoveEntry(entryName string) (err error) {
|
func (f *Folder) RemoveEntry(entryName string) (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMRemoveEntry, 0, f.wallet.handle, f.Name, entryName, f.wallet.wm.AppID,
|
DbusWMRemoveEntry, 0, f.wallet.handle, f.Name, entryName, f.wallet.wm.AppID,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,11 +143,16 @@ func (f *Folder) RemoveEntry(entryName string) (err error) {
|
|||||||
// RenameEntry renames a WalletItem in a Folder from entryName to newEntryName.
|
// RenameEntry renames a WalletItem in a Folder from entryName to newEntryName.
|
||||||
func (f *Folder) RenameEntry(entryName, newEntryName string) (err error) {
|
func (f *Folder) RenameEntry(entryName, newEntryName string) (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMRenameEntry, 0, f.wallet.handle, f.Name, entryName, newEntryName, f.wallet.wm.AppID,
|
DbusWMRenameEntry, 0, f.wallet.handle, f.Name, entryName, newEntryName, f.wallet.wm.AppID,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,19 +201,24 @@ func (f *Folder) Update() (err error) {
|
|||||||
// UpdateBlobs updates (populates) a Folder's Folder.BinaryData.
|
// UpdateBlobs updates (populates) a Folder's Folder.BinaryData.
|
||||||
func (f *Folder) UpdateBlobs() (err error) {
|
func (f *Folder) UpdateBlobs() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var mapKeys []string
|
var mapKeys []string
|
||||||
var isBlob bool
|
var isBlob bool
|
||||||
var variant dbus.Variant
|
var variant dbus.Variant
|
||||||
var errs []error = make([]error, 0)
|
var errs []error = make([]error, 0)
|
||||||
|
|
||||||
if !f.isInit {
|
if !f.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitFolder
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMEntriesList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
DbusWMEntriesList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
||||||
).Store(&variant); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&variant); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,13 +253,18 @@ func (f *Folder) UpdateBlobs() (err error) {
|
|||||||
// UpdateMaps updates (populates) a Folder's Folder.Maps.
|
// UpdateMaps updates (populates) a Folder's Folder.Maps.
|
||||||
func (f *Folder) UpdateMaps() (err error) {
|
func (f *Folder) UpdateMaps() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var mapKeys []string
|
var mapKeys []string
|
||||||
var variant dbus.Variant
|
var variant dbus.Variant
|
||||||
var errs []error = make([]error, 0)
|
var errs []error = make([]error, 0)
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMMapList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
DbusWMMapList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
||||||
).Store(&variant); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&variant); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,18 +290,23 @@ func (f *Folder) UpdateMaps() (err error) {
|
|||||||
// UpdatePasswords updates (populates) a Folder's Folder.Passwords.
|
// UpdatePasswords updates (populates) a Folder's Folder.Passwords.
|
||||||
func (f *Folder) UpdatePasswords() (err error) {
|
func (f *Folder) UpdatePasswords() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var mapKeys []string
|
var mapKeys []string
|
||||||
var variant dbus.Variant
|
var variant dbus.Variant
|
||||||
var errs []error = make([]error, 0)
|
var errs []error = make([]error, 0)
|
||||||
|
|
||||||
if !f.isInit {
|
if !f.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitFolder
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMPasswordList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
DbusWMPasswordList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
||||||
).Store(&variant); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&variant); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,19 +332,24 @@ func (f *Folder) UpdatePasswords() (err error) {
|
|||||||
// UpdateUnknowns updates (populates) a Folder's Folder.Unknown.
|
// UpdateUnknowns updates (populates) a Folder's Folder.Unknown.
|
||||||
func (f *Folder) UpdateUnknowns() (err error) {
|
func (f *Folder) UpdateUnknowns() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var mapKeys []string
|
var mapKeys []string
|
||||||
var isUnknown bool
|
var isUnknown bool
|
||||||
var variant dbus.Variant
|
var variant dbus.Variant
|
||||||
var errs []error = make([]error, 0)
|
var errs []error = make([]error, 0)
|
||||||
|
|
||||||
if !f.isInit {
|
if !f.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitFolder
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMEntriesList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
DbusWMEntriesList, 0, f.wallet.handle, f.Name, f.wallet.wm.AppID,
|
||||||
).Store(&variant); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&variant); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,6 +402,7 @@ func (f *Folder) WriteBlob(entryName string, entryValue []byte) (b *Blob, err er
|
|||||||
*/
|
*/
|
||||||
func (f *Folder) WriteEntry(entryName string, entryType kwalletdEnumType, entryValue []byte) (err error) {
|
func (f *Folder) WriteEntry(entryName string, entryType kwalletdEnumType, entryValue []byte) (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
|
|
||||||
if entryType == KwalletdEnumTypeUnused {
|
if entryType == KwalletdEnumTypeUnused {
|
||||||
@ -359,9 +410,13 @@ func (f *Folder) WriteEntry(entryName string, entryType kwalletdEnumType, entryV
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMWriteEntry, 0, f.wallet.handle, f.Name, entryName, entryValue, int32(entryType), f.wallet.wm.AppID,
|
DbusWMWriteEntry, 0, f.wallet.handle, f.Name, entryName, entryValue, int32(entryType), f.wallet.wm.AppID,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,6 +428,7 @@ func (f *Folder) WriteEntry(entryName string, entryType kwalletdEnumType, entryV
|
|||||||
// WriteMap adds or replaces a Map to/in a Folder.
|
// WriteMap adds or replaces a Map to/in a Folder.
|
||||||
func (f *Folder) WriteMap(entryName string, entryValue map[string]string) (m *Map, err error) {
|
func (f *Folder) WriteMap(entryName string, entryValue map[string]string) (m *Map, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
var b []byte
|
var b []byte
|
||||||
|
|
||||||
@ -380,9 +436,13 @@ func (f *Folder) WriteMap(entryName string, entryValue map[string]string) (m *Ma
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMWriteMap, 0, f.wallet.handle, f.Name, entryName, b, f.wallet.wm.AppID,
|
DbusWMWriteMap, 0, f.wallet.handle, f.Name, entryName, b, f.wallet.wm.AppID,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -398,11 +458,16 @@ func (f *Folder) WriteMap(entryName string, entryValue map[string]string) (m *Ma
|
|||||||
// WritePassword adds or replaces a Password to/in a Folder.
|
// WritePassword adds or replaces a Password to/in a Folder.
|
||||||
func (f *Folder) WritePassword(entryName, entryValue string) (p *Password, err error) {
|
func (f *Folder) WritePassword(entryName, entryValue string) (p *Password, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMWritePassword, 0, f.wallet.handle, f.Name, entryName, entryValue, f.wallet.wm.AppID,
|
DbusWMWritePassword, 0, f.wallet.handle, f.Name, entryName, entryValue, f.wallet.wm.AppID,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,11 +497,16 @@ func (f *Folder) WriteUnknown(entryName string, entryValue []byte) (u *UnknownIt
|
|||||||
// isType checks if a certain key keyName is of type typeCheck (via KwalletdEnumType*).
|
// isType checks if a certain key keyName is of type typeCheck (via KwalletdEnumType*).
|
||||||
func (f *Folder) isType(keyName string, typeCheck kwalletdEnumType) (isOfType bool, err error) {
|
func (f *Folder) isType(keyName string, typeCheck kwalletdEnumType) (isOfType bool, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var entryType int32
|
var entryType int32
|
||||||
|
|
||||||
if err = f.Dbus.Call(
|
if call = f.Dbus.Call(
|
||||||
DbusWMEntryType, 0, f.wallet.handle, f.Name, keyName, f.wallet.wm.AppID,
|
DbusWMEntryType, 0, f.wallet.handle, f.Name, keyName, f.wallet.wm.AppID,
|
||||||
).Store(&entryType); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&entryType); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
go.mod
5
go.mod
@ -2,4 +2,7 @@ module r00t2.io/gokwallet
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require github.com/godbus/dbus/v5 v5.0.6
|
require (
|
||||||
|
github.com/godbus/dbus/v5 v5.0.6
|
||||||
|
github.com/google/uuid v1.3.0
|
||||||
|
)
|
||||||
|
2
go.sum
2
go.sum
@ -1,2 +1,4 @@
|
|||||||
github.com/godbus/dbus/v5 v5.0.6 h1:mkgN1ofwASrYnJ5W6U/BxG15eXXXjirgZc7CLqkcaro=
|
github.com/godbus/dbus/v5 v5.0.6 h1:mkgN1ofwASrYnJ5W6U/BxG15eXXXjirgZc7CLqkcaro=
|
||||||
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
17
map_funcs.go
17
map_funcs.go
@ -1,5 +1,9 @@
|
|||||||
package gokwallet
|
package gokwallet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/godbus/dbus/v5"
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewMap returns a Map. It requires a RecurseOpts
|
NewMap returns a Map. It requires a RecurseOpts
|
||||||
(you can use DefaultRecurseOpts, call NewRecurseOpts, or provide your own RecurseOpts struct).
|
(you can use DefaultRecurseOpts, call NewRecurseOpts, or provide your own RecurseOpts struct).
|
||||||
@ -8,7 +12,7 @@ package gokwallet
|
|||||||
func NewMap(f *Folder, keyName string, recursion *RecurseOpts) (m *Map, err error) {
|
func NewMap(f *Folder, keyName string, recursion *RecurseOpts) (m *Map, err error) {
|
||||||
|
|
||||||
if !f.isInit {
|
if !f.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitFolder
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,6 +27,8 @@ func NewMap(f *Folder, keyName string, recursion *RecurseOpts) (m *Map, err erro
|
|||||||
isInit: false,
|
isInit: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.isInit = true
|
||||||
|
|
||||||
if m.Recurse.AllWalletItems || m.Recurse.Maps {
|
if m.Recurse.AllWalletItems || m.Recurse.Maps {
|
||||||
if err = m.Update(); err != nil {
|
if err = m.Update(); err != nil {
|
||||||
return
|
return
|
||||||
@ -61,11 +67,16 @@ func (m *Map) SetValue(newValue map[string]string) (err error) {
|
|||||||
// Update fetches a Map's Map.Value.
|
// Update fetches a Map's Map.Value.
|
||||||
func (m *Map) Update() (err error) {
|
func (m *Map) Update() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var b []byte
|
var b []byte
|
||||||
|
|
||||||
if err = m.Dbus.Call(
|
if call = m.Dbus.Call(
|
||||||
DbusWMReadMap, 0, m.folder.wallet.handle, m.folder.Name, m.Name, m.folder.wallet.wm.AppID,
|
DbusWMReadMap, 0, m.folder.wallet.handle, m.folder.Name, m.Name, m.folder.wallet.wm.AppID,
|
||||||
).Store(&b); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&b); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ func (e *MultiError) Error() (errStr string) {
|
|||||||
|
|
||||||
for idx, err := range e.Errors {
|
for idx, err := range e.Errors {
|
||||||
if (idx + 1) < numErrs {
|
if (idx + 1) < numErrs {
|
||||||
errStr += fmt.Sprintf(err.Error(), e.ErrorSep)
|
errStr += fmt.Sprintf("%v%v", err.Error(), e.ErrorSep)
|
||||||
} else {
|
} else {
|
||||||
errStr += err.Error()
|
errStr += err.Error()
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package gokwallet
|
package gokwallet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/godbus/dbus/v5"
|
||||||
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
NewPassword returns a Password. It requires a RecurseOpts
|
NewPassword returns a Password. It requires a RecurseOpts
|
||||||
(you can use DefaultRecurseOpts, call NewRecurseOpts, or provide your own RecurseOpts struct).
|
(you can use DefaultRecurseOpts, call NewRecurseOpts, or provide your own RecurseOpts struct).
|
||||||
@ -8,7 +12,7 @@ package gokwallet
|
|||||||
func NewPassword(f *Folder, keyName string, recursion *RecurseOpts) (password *Password, err error) {
|
func NewPassword(f *Folder, keyName string, recursion *RecurseOpts) (password *Password, err error) {
|
||||||
|
|
||||||
if !f.isInit {
|
if !f.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitFolder
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,6 +27,8 @@ func NewPassword(f *Folder, keyName string, recursion *RecurseOpts) (password *P
|
|||||||
isInit: false,
|
isInit: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
password.isInit = true
|
||||||
|
|
||||||
if password.Recurse.AllWalletItems || password.Recurse.Passwords {
|
if password.Recurse.AllWalletItems || password.Recurse.Passwords {
|
||||||
if err = password.Update(); err != nil {
|
if err = password.Update(); err != nil {
|
||||||
return
|
return
|
||||||
@ -61,11 +67,16 @@ func (p *Password) SetValue(newValue string) (err error) {
|
|||||||
// Update fetches a Password's Password.Value.
|
// Update fetches a Password's Password.Value.
|
||||||
func (p *Password) Update() (err error) {
|
func (p *Password) Update() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var b []byte
|
var b []byte
|
||||||
|
|
||||||
if err = p.Dbus.Call(
|
if call = p.Dbus.Call(
|
||||||
DbusWMReadPassword, 0, p.folder.wallet.handle, p.folder.Name, p.Name, p.folder.wallet.wm.AppID,
|
DbusWMReadPassword, 0, p.folder.wallet.handle, p.folder.Name, p.Name, p.folder.wallet.wm.AppID,
|
||||||
).Store(&b); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&b); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
types.go
4
types.go
@ -86,8 +86,10 @@ type Wallet struct {
|
|||||||
wm *WalletManager
|
wm *WalletManager
|
||||||
// handle is this Wallet's handler number.
|
// handle is this Wallet's handler number.
|
||||||
handle int32
|
handle int32
|
||||||
// isInit flags whether this is "properly" set up (i.e. has a handle).
|
// isInit flags whether this is "properly" set up.
|
||||||
isInit bool
|
isInit bool
|
||||||
|
// hasHandle specifies if this Wallet's Wallet.handle has been explicitly set yet.
|
||||||
|
hasHandle bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Folder contains secret object collections of Password, Map, Blob, and UnknownItem objects.
|
// Folder contains secret object collections of Password, Map, Blob, and UnknownItem objects.
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
func NewUnknownItem(f *Folder, keyName string, recursion *RecurseOpts) (unknown *UnknownItem, err error) {
|
func NewUnknownItem(f *Folder, keyName string, recursion *RecurseOpts) (unknown *UnknownItem, err error) {
|
||||||
|
|
||||||
if !f.isInit {
|
if !f.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitFolder
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +27,8 @@ func NewUnknownItem(f *Folder, keyName string, recursion *RecurseOpts) (unknown
|
|||||||
isInit: false,
|
isInit: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unknown.isInit = true
|
||||||
|
|
||||||
if unknown.Recurse.AllWalletItems || unknown.Recurse.UnknownItems {
|
if unknown.Recurse.AllWalletItems || unknown.Recurse.UnknownItems {
|
||||||
if err = unknown.Update(); err != nil {
|
if err = unknown.Update(); err != nil {
|
||||||
return
|
return
|
||||||
@ -65,11 +67,16 @@ func (u *UnknownItem) SetValue(newValue []byte) (err error) {
|
|||||||
// Update fetches an UnknownItem's UnknownItem.Value.
|
// Update fetches an UnknownItem's UnknownItem.Value.
|
||||||
func (u *UnknownItem) Update() (err error) {
|
func (u *UnknownItem) Update() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var v dbus.Variant
|
var v dbus.Variant
|
||||||
|
|
||||||
if err = u.Dbus.Call(
|
if call = u.Dbus.Call(
|
||||||
DbusWMReadEntry, 0, u.folder.wallet.handle, u.folder.Name, u.Name, u.folder.wallet.wm.AppID,
|
DbusWMReadEntry, 0, u.folder.wallet.handle, u.folder.Name, u.Name, u.folder.wallet.wm.AppID,
|
||||||
).Store(&v); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&v); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1,29 @@
|
|||||||
package gokwallet
|
package gokwallet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getTestEnv(t *testing.T) (wm *WalletManager, w *Wallet, f *Folder, err error) {
|
||||||
|
|
||||||
|
var r *RecurseOpts = DefaultRecurseOpts
|
||||||
|
|
||||||
|
r.AllWalletItems = true
|
||||||
|
|
||||||
|
if wm, err = NewWalletManager(r, appIdTest); err != nil {
|
||||||
|
t.Errorf("failure when getting WalletManager '%v': %v", appIdTest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if w, err = NewWallet(wm, walletTest.String(), wm.Recurse); err != nil {
|
||||||
|
t.Errorf("failure when getting Wallet '%v:%v': %v", appIdTest, walletTest.String(), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if f, err = NewFolder(w, folderTest.String(), w.Recurse); err != nil {
|
||||||
|
t.Errorf("failure when getting Folder '%v:%v:%v': %v", appIdTest, walletTest.String(), folderTest.String(), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
158
wallet_funcs.go
158
wallet_funcs.go
@ -12,7 +12,7 @@ import (
|
|||||||
func NewWallet(wm *WalletManager, name string, recursion *RecurseOpts) (wallet *Wallet, err error) {
|
func NewWallet(wm *WalletManager, name string, recursion *RecurseOpts) (wallet *Wallet, err error) {
|
||||||
|
|
||||||
if !wm.isInit {
|
if !wm.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitWM
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,6 +26,8 @@ func NewWallet(wm *WalletManager, name string, recursion *RecurseOpts) (wallet *
|
|||||||
isInit: false,
|
isInit: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wallet.isInit = true
|
||||||
|
|
||||||
// TODO: remove this and leave to caller, since it might use PamOpen instead? Fail back to it?
|
// TODO: remove this and leave to caller, since it might use PamOpen instead? Fail back to it?
|
||||||
if err = wallet.walletCheck(); err != nil {
|
if err = wallet.walletCheck(); err != nil {
|
||||||
return
|
return
|
||||||
@ -45,15 +47,20 @@ func NewWallet(wm *WalletManager, name string, recursion *RecurseOpts) (wallet *
|
|||||||
// Disconnect disconnects this Wallet from its parent WalletManager.
|
// Disconnect disconnects this Wallet from its parent WalletManager.
|
||||||
func (w *Wallet) Disconnect() (err error) {
|
func (w *Wallet) Disconnect() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMDisconnectApp, 0, w.Name, w.wm.AppID,
|
DbusWMDisconnectApp, 0, w.Name, w.wm.AppID,
|
||||||
).Store(&ok); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&ok); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,15 +74,20 @@ func (w *Wallet) Disconnect() (err error) {
|
|||||||
// DisconnectApplication disconnects this Wallet from a specified WalletManager/application (see Wallet.Connections).
|
// DisconnectApplication disconnects this Wallet from a specified WalletManager/application (see Wallet.Connections).
|
||||||
func (w *Wallet) DisconnectApplication(appName string) (err error) {
|
func (w *Wallet) DisconnectApplication(appName string) (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMDisconnectApp, 0, appName, w.wm.AppID,
|
DbusWMDisconnectApp, 0, appName, w.wm.AppID,
|
||||||
).Store(&ok); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&ok); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +100,8 @@ func (w *Wallet) DisconnectApplication(appName string) (err error) {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
ChangePassword will change (or set) the password for a Wallet.
|
ChangePassword will change (or set) the password for a Wallet.
|
||||||
Note that this *must* be done via the windowing layer.
|
Note that this *must* be done via the windowing/graphical layer.
|
||||||
|
There is no way to change a Wallet's password via the Dbus API.
|
||||||
*/
|
*/
|
||||||
func (w *Wallet) ChangePassword() (err error) {
|
func (w *Wallet) ChangePassword() (err error) {
|
||||||
|
|
||||||
@ -98,11 +111,12 @@ func (w *Wallet) ChangePassword() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
call = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMChangePassword, 0, w.Name, DefaultWindowID, w.wm.AppID,
|
DbusWMChangePassword, 0, w.Name, DefaultWindowID, w.wm.AppID,
|
||||||
)
|
); call.Err != nil {
|
||||||
|
|
||||||
err = call.Err
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -110,6 +124,7 @@ func (w *Wallet) ChangePassword() (err error) {
|
|||||||
// Close closes a Wallet.
|
// Close closes a Wallet.
|
||||||
func (w *Wallet) Close() (err error) {
|
func (w *Wallet) Close() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
@ -117,9 +132,13 @@ func (w *Wallet) Close() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Using a handler allows us to close access for this particular parent WalletManager.
|
// Using a handler allows us to close access for this particular parent WalletManager.
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMClose, 0, w.handle, false, w.wm.AppID,
|
DbusWMClose, 0, w.handle, false, w.wm.AppID,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,13 +150,19 @@ func (w *Wallet) Close() (err error) {
|
|||||||
// Connections lists the application names for connections to ("users of") this Wallet.
|
// Connections lists the application names for connections to ("users of") this Wallet.
|
||||||
func (w *Wallet) Connections() (connList []string, err error) {
|
func (w *Wallet) Connections() (connList []string, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMUsers, 0, w.Name,
|
DbusWMUsers, 0, w.Name,
|
||||||
).Store(&connList); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&connList); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,15 +172,20 @@ func (w *Wallet) Connections() (connList []string, err error) {
|
|||||||
// CreateFolder creates a new Folder in a Wallet.
|
// CreateFolder creates a new Folder in a Wallet.
|
||||||
func (w *Wallet) CreateFolder(name string) (err error) {
|
func (w *Wallet) CreateFolder(name string) (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMCreateFolder, 0, w.handle, name, w.wm.AppID,
|
DbusWMCreateFolder, 0, w.handle, name, w.wm.AppID,
|
||||||
).Store(&ok); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&ok); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,15 +199,20 @@ func (w *Wallet) CreateFolder(name string) (err error) {
|
|||||||
// Delete deletes a Wallet.
|
// Delete deletes a Wallet.
|
||||||
func (w *Wallet) Delete() (err error) {
|
func (w *Wallet) Delete() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMDeleteWallet, 0, w.Name,
|
DbusWMDeleteWallet, 0, w.Name,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,13 +226,18 @@ func (w *Wallet) Delete() (err error) {
|
|||||||
// FolderExists indicates if a Folder exists in a Wallet or not.
|
// FolderExists indicates if a Folder exists in a Wallet or not.
|
||||||
func (w *Wallet) FolderExists(folderName string) (exists bool, err error) {
|
func (w *Wallet) FolderExists(folderName string) (exists bool, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var notExists bool
|
var notExists bool
|
||||||
|
|
||||||
// We don't need a walletcheck here since we don't need a handle.
|
// We don't need a walletcheck here since we don't need a handle.
|
||||||
|
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMFolderNotExist, 0, w.Name, folderName,
|
DbusWMFolderNotExist, 0, w.Name, folderName,
|
||||||
).Store(¬Exists); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(¬Exists); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +252,7 @@ func (w *Wallet) FolderExists(folderName string) (exists bool, err error) {
|
|||||||
*/
|
*/
|
||||||
func (w *Wallet) ForceClose() (err error) {
|
func (w *Wallet) ForceClose() (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
@ -219,9 +260,13 @@ func (w *Wallet) ForceClose() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Using a handler allows us to close access for this particular parent WalletManager.
|
// Using a handler allows us to close access for this particular parent WalletManager.
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMClose, 0, w.handle, true, w.wm.AppID,
|
DbusWMClose, 0, w.handle, true, w.wm.AppID,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,13 +278,19 @@ func (w *Wallet) ForceClose() (err error) {
|
|||||||
// HasFolder indicates if a Wallet has a Folder in it named folderName.
|
// HasFolder indicates if a Wallet has a Folder in it named folderName.
|
||||||
func (w *Wallet) HasFolder(folderName string) (hasFolder bool, err error) {
|
func (w *Wallet) HasFolder(folderName string) (hasFolder bool, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMHasFolder, 0, w.handle, folderName, w.wm.AppID,
|
DbusWMHasFolder, 0, w.handle, folderName, w.wm.AppID,
|
||||||
).Store(&hasFolder); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&hasFolder); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,12 +300,22 @@ func (w *Wallet) HasFolder(folderName string) (hasFolder bool, err error) {
|
|||||||
// IsOpen returns whether a Wallet is open ("unlocked") or not (as well as updates Wallet.IsOpen).
|
// IsOpen returns whether a Wallet is open ("unlocked") or not (as well as updates Wallet.IsOpen).
|
||||||
func (w *Wallet) IsOpen() (isOpen bool, err error) {
|
func (w *Wallet) IsOpen() (isOpen bool, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
|
|
||||||
// We don't call walletcheck here because this method is called by a walletcheck.
|
// We don't call walletcheck here because this method is called by a walletcheck.
|
||||||
|
if !w.isInit {
|
||||||
|
err = ErrInitWallet
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// We can call the same method with w.handle instead of w.Name. We don't have a handler yet though.
|
// We can call the same method with w.handle instead of w.Name. We don't have a handler yet though.
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMIsOpen, 0, w.Name,
|
DbusWMIsOpen, 0, w.Name,
|
||||||
).Store(&w.IsUnlocked); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&w.IsUnlocked); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,13 +327,19 @@ func (w *Wallet) IsOpen() (isOpen bool, err error) {
|
|||||||
// ListFolders lists all Folder names in a Wallet.
|
// ListFolders lists all Folder names in a Wallet.
|
||||||
func (w *Wallet) ListFolders() (folderList []string, err error) {
|
func (w *Wallet) ListFolders() (folderList []string, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMFolderList, 0, w.handle, w.wm.AppID,
|
DbusWMFolderList, 0, w.handle, w.wm.AppID,
|
||||||
).Store(&folderList); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&folderList); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,27 +352,35 @@ func (w *Wallet) ListFolders() (folderList []string, err error) {
|
|||||||
*/
|
*/
|
||||||
func (w *Wallet) Open() (err error) {
|
func (w *Wallet) Open() (err error) {
|
||||||
|
|
||||||
var handler *int32
|
var call *dbus.Call
|
||||||
|
var handler *int32 = new(int32)
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
// We don't call walletcheck here because this method is called by a walletcheck.
|
||||||
|
if !w.isInit {
|
||||||
|
err = ErrInitWallet
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !w.IsUnlocked {
|
if !w.IsUnlocked || !w.hasHandle {
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMOpen, 0,
|
DbusWMOpen, 0, w.Name, DefaultWindowID, w.wm.AppID,
|
||||||
).Store(handler); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(handler); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if handler == nil {
|
if handler == nil {
|
||||||
err = ErrOperationFailed
|
err = ErrDbusOpfailNoHandle
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
w.handle = *handler
|
w.handle = *handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.hasHandle = true
|
||||||
w.IsUnlocked = true
|
w.IsUnlocked = true
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -317,20 +392,25 @@ func (w *Wallet) Open() (err error) {
|
|||||||
*/
|
*/
|
||||||
func (w *Wallet) RemoveFolder(folderName string) (err error) {
|
func (w *Wallet) RemoveFolder(folderName string) (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var success bool
|
var success bool
|
||||||
|
|
||||||
if err = w.walletCheck(); err != nil {
|
if err = w.walletCheck(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = w.Dbus.Call(
|
if call = w.Dbus.Call(
|
||||||
DbusWMRemoveFolder, 0, w.handle, folderName, w.wm.AppID,
|
DbusWMRemoveFolder, 0, w.handle, folderName, w.wm.AppID,
|
||||||
).Store(&success); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&success); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
err = ErrOperationFailed
|
err = ErrDbusOpfailRemoveFolder
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,7 +453,7 @@ func (w *Wallet) Update() (err error) {
|
|||||||
func (w *Wallet) walletCheck() (err error) {
|
func (w *Wallet) walletCheck() (err error) {
|
||||||
|
|
||||||
if !w.isInit {
|
if !w.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitWallet
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +461,7 @@ func (w *Wallet) walletCheck() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !w.IsUnlocked {
|
if !w.IsUnlocked || !w.hasHandle {
|
||||||
if err = w.Open(); err != nil {
|
if err = w.Open(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -80,17 +80,23 @@ func NewWalletManagerFiles(recursion *RecurseOpts, appId string, filePaths ...st
|
|||||||
for the specified Wallet - not just this WalletManager.
|
for the specified Wallet - not just this WalletManager.
|
||||||
*/
|
*/
|
||||||
func (wm *WalletManager) CloseWallet(walletName string) (err error) {
|
func (wm *WalletManager) CloseWallet(walletName string) (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
|
|
||||||
if !wm.isInit {
|
if !wm.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitWM
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using a handler allows us to close access for this particular parent WalletManager.
|
// Using a handler allows us to close access for this particular parent WalletManager.
|
||||||
if err = wm.Dbus.Call(
|
if call = wm.Dbus.Call(
|
||||||
DbusWMClose, 0, walletName, false,
|
DbusWMClose, 0, walletName, false,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,17 +112,22 @@ func (wm *WalletManager) CloseWallet(walletName string) (err error) {
|
|||||||
*/
|
*/
|
||||||
func (wm *WalletManager) ForceCloseWallet(walletName string) (err error) {
|
func (wm *WalletManager) ForceCloseWallet(walletName string) (err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var rslt int32
|
var rslt int32
|
||||||
|
|
||||||
if !wm.isInit {
|
if !wm.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitWM
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using a handler allows us to close access for this particular parent WalletManager.
|
// Using a handler allows us to close access for this particular parent WalletManager.
|
||||||
if err = wm.Dbus.Call(
|
if call = wm.Dbus.Call(
|
||||||
DbusWMClose, 0, walletName, false,
|
DbusWMClose, 0, walletName, false,
|
||||||
).Store(&rslt); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&rslt); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,20 +136,25 @@ func (wm *WalletManager) ForceCloseWallet(walletName string) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// CloseAllWallets closes all Wallet objects. They do *not* need to be part of WalletManager.Wallets.
|
/*
|
||||||
|
CloseAllWallets closes all Wallet objects. They do *not* need to be part of WalletManager.Wallets.
|
||||||
|
"All wallets" really means *all* wallets.
|
||||||
|
*/
|
||||||
func (wm *WalletManager) CloseAllWallets() (err error) {
|
func (wm *WalletManager) CloseAllWallets() (err error) {
|
||||||
|
|
||||||
var call *dbus.Call
|
var call *dbus.Call
|
||||||
|
|
||||||
if !wm.isInit {
|
if !wm.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitWM
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
call = wm.Dbus.Call(
|
if call = wm.Dbus.Call(
|
||||||
DbusWMCloseAllWallets, 0,
|
DbusWMCloseAllWallets, 0,
|
||||||
)
|
); call.Err != nil {
|
||||||
err = call.Err
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -146,14 +162,20 @@ func (wm *WalletManager) CloseAllWallets() (err error) {
|
|||||||
// IsEnabled returns whether KWallet is enabled or not (and also updates WalletManager.Enabled).
|
// IsEnabled returns whether KWallet is enabled or not (and also updates WalletManager.Enabled).
|
||||||
func (wm *WalletManager) IsEnabled() (enabled bool, err error) {
|
func (wm *WalletManager) IsEnabled() (enabled bool, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
|
|
||||||
if !wm.isInit {
|
if !wm.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitWM
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = wm.Dbus.Call(
|
if call = wm.Dbus.Call(
|
||||||
DbusWMIsEnabled, 0,
|
DbusWMIsEnabled, 0,
|
||||||
).Store(&wm.Enabled); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&wm.Enabled); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,11 +187,21 @@ func (wm *WalletManager) IsEnabled() (enabled bool, err error) {
|
|||||||
// LocalWallet returns the "local" wallet (and updates WalletManager.Local).
|
// LocalWallet returns the "local" wallet (and updates WalletManager.Local).
|
||||||
func (wm *WalletManager) LocalWallet() (w *Wallet, err error) {
|
func (wm *WalletManager) LocalWallet() (w *Wallet, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var wn string
|
var wn string
|
||||||
|
|
||||||
if err = wm.Dbus.Call(
|
if !wm.isInit {
|
||||||
|
err = ErrInitWM
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if call = wm.Dbus.Call(
|
||||||
DbusWMLocalWallet, 0,
|
DbusWMLocalWallet, 0,
|
||||||
).Store(&wn); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&wn); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,11 +217,21 @@ func (wm *WalletManager) LocalWallet() (w *Wallet, err error) {
|
|||||||
// NetworkWallet returns the "network" wallet (and updates WalletManager.Network).
|
// NetworkWallet returns the "network" wallet (and updates WalletManager.Network).
|
||||||
func (wm *WalletManager) NetworkWallet() (w *Wallet, err error) {
|
func (wm *WalletManager) NetworkWallet() (w *Wallet, err error) {
|
||||||
|
|
||||||
|
var call *dbus.Call
|
||||||
var wn string
|
var wn string
|
||||||
|
|
||||||
if err = wm.Dbus.Call(
|
if !wm.isInit {
|
||||||
|
err = ErrInitWM
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if call = wm.Dbus.Call(
|
||||||
DbusWMNetWallet, 0,
|
DbusWMNetWallet, 0,
|
||||||
).Store(&wn); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&wn); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,9 +247,15 @@ func (wm *WalletManager) NetworkWallet() (w *Wallet, err error) {
|
|||||||
// WalletNames returns a list of existing Wallet names.
|
// WalletNames returns a list of existing Wallet names.
|
||||||
func (wm *WalletManager) WalletNames() (wallets []string, err error) {
|
func (wm *WalletManager) WalletNames() (wallets []string, err error) {
|
||||||
|
|
||||||
if err = wm.Dbus.Call(
|
var call *dbus.Call
|
||||||
|
|
||||||
|
if call = wm.Dbus.Call(
|
||||||
DbusWMWallets, 0,
|
DbusWMWallets, 0,
|
||||||
).Store(&wallets); err != nil {
|
); call.Err != nil {
|
||||||
|
err = call.Err
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = call.Store(&wallets); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +269,7 @@ func (wm *WalletManager) Update() (err error) {
|
|||||||
var errs []error = make([]error, 0)
|
var errs []error = make([]error, 0)
|
||||||
|
|
||||||
if !wm.isInit {
|
if !wm.isInit {
|
||||||
err = ErrNotInitialized
|
err = ErrInitWM
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,6 +316,10 @@ func newWM(appId string, recursion *RecurseOpts, filePaths ...string) (wm *Walle
|
|||||||
|
|
||||||
wm.isInit = true
|
wm.isInit = true
|
||||||
|
|
||||||
|
if _, err = wm.IsEnabled(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if wm.Recurse.All || wm.Recurse.Wallets {
|
if wm.Recurse.All || wm.Recurse.Wallets {
|
||||||
if err = wm.Update(); err != nil {
|
if err = wm.Update(); err != nil {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user