Class: Keyring::KWalletKeyring

Inherits:
Keyring
  • Object
show all
Defined in:
lib/keyring-kwallet/KWalletKeyring.rb

Overview

A keyring implementation using KDE’s wallet.

Constant Summary collapse

@@open_wallets =

A set of opened wallets, will be closed when the application exits.

Set.new

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ KWalletKeyring

Returns a new instance of KWalletKeyring.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/keyring-kwallet/KWalletKeyring.rb', line 23

def initialize(params = {})
    super()
    params ||= {}
    @folder = params[:folder] || params["folder"] || $0
    @app_name = params[:app] || params["app"] || $0
    @net_handle = nil

    begin
        bus = DBus::SessionBus.instance
        kw_service = bus.service("org.kde.kwalletd")
        @kwallet = kw_service.object("/modules/kwalletd")
        @kwallet.default_iface = "org.kde.KWallet"
        @kwallet.introspect
    rescue => e
        STDERR.puts "Warning: #{e}"
        @kwallet = nil
    end
end

Instance Method Details

#delete_folderObject

Deletes the folder associated with this wallet.



70
71
72
73
# File 'lib/keyring-kwallet/KWalletKeyring.rb', line 70

def delete_folder
    open_wallet
    @kwallet.removeFolder(@net_handle, @folder, @app_name)
end

#get_password(service, user) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/keyring-kwallet/KWalletKeyring.rb', line 50

def get_password(service, user)
    open_wallet
    entry = "#{user}@#{service}"
    if @kwallet.hasEntry(@net_handle, @folder, entry, @app_name)[0]
        @kwallet.readPassword(@net_handle, @folder, entry, @app_name)[0]
    else
        nil
    end
end

#recommended?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/keyring-kwallet/KWalletKeyring.rb', line 46

def recommended?
    supported?
end

#set_password(service, user, password) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/keyring-kwallet/KWalletKeyring.rb', line 60

def set_password(service, user, password)
    open_wallet
    if password
        @kwallet.writePassword(@net_handle, @folder, "#{user}@#{service}", password, @app_name)
    else
        @kwallet.removeEntry(@net_handle, @folder, "#{user}@#{service}", @app_name)
    end
end

#supported?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/keyring-kwallet/KWalletKeyring.rb', line 42

def supported?
    @kwallet != nil
end