/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to seahorse.py

  • Committer: Daniel Schierbeck
  • Date: 2008-04-03 14:07:56 UTC
  • mto: (450.1.18 trunk)
  • mto: This revision was merged to the branch mainline in revision 458.
  • Revision ID: daniel.schierbeck@gmail.com-20080403140756-ru2uqoa9lkjagzsb
Fixed issue with empty keys.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
KEY_TYPE_SSH = 'ssh'
30
30
 
31
31
try:
32
 
    bus = dbus.SessionBus()
33
 
except dbus.exceptions.DBusException, e:
34
 
    get_name = getattr(e, 'get_dbus_name', None)
35
 
    if get_name is not None:
36
 
        name = get_name()
37
 
    else:
38
 
        name = getattr(e, '_dbus_error_name', None)
39
 
    # DBus sometimes fails like this, just treat it as if seahorse is not
40
 
    # available rather than crashing.
41
 
    if name == "org.freedesktop.DBus.Error.Spawn.ExecFailed":
42
 
        raise ImportError
43
 
    else:
44
 
        raise
45
 
 
46
 
if hasattr(bus, 'list_activatable_names'):
47
 
    bus_names = bus.list_activatable_names()
48
 
else:
49
 
    bus_object = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
50
 
    bus_names = bus_object.ListNames(dbus_interface='org.freedesktop.DBus')
51
 
 
52
 
if BUS_NAME not in bus_names:
 
32
    dbus.validate_bus_name(BUS_NAME)
 
33
except ValueError:
53
34
    raise ImportError
54
35
 
 
36
bus = dbus.SessionBus()
 
37
 
55
38
crypto = dbus.Interface(bus.get_object(BUS_NAME, CRYPTO_PATH), 
56
39
                        CRYPTO_INTERFACE)
57
40
openpgp = dbus.Interface(bus.get_object(BUS_NAME, OPENPGP_PATH),
76
59
LOCATION_REMOTE = 50
77
60
LOCATION_LOCAL = 100
78
61
 
79
 
keyset = dict()
 
62
def discover(*key_ids):
 
63
    return openpgp.DiscoverKeys(key_ids, 0)
80
64
 
81
65
def verify(crypttext):
82
66
    (cleartext, key) = crypto.VerifyText(KEY_TYPE_OPENPGP, 1, crypttext)
83
67
 
84
 
    if key != "":
85
 
        if key not in keyset:
86
 
            keyset[key] = Key(key)
87
 
 
88
 
        return (cleartext, keyset[key])
89
 
 
90
 
    return (cleartext, None)
91
 
 
 
68
    return Key(key)
92
69
 
93
70
class Key:
94
71
 
95
72
    def __init__(self, key):
96
73
        self.key = key
97
 
 
98
 
        (keys, unmatched) = openpgp.MatchKeys([self.get_id()], 0x00000010)
99
 
        self.available = (key in keys)
100
 
 
101
 
        if self.available:
102
 
            fields = openpgp.GetKeyFields(key, ['fingerprint', 'trust', 'flags', 'display-name', 'location'])
 
74
        self.fingerprint = None
 
75
        self.trust = None
 
76
        self.flags = None
 
77
        self.display_name = None
 
78
        self.location = None
 
79
 
 
80
        if self.is_available():
 
81
            discover(key)
 
82
 
 
83
    def get_field(self, field, default=None):
 
84
        (valid, value) = openpgp.GetKeyField(self.key, field)
 
85
 
 
86
        if valid:
 
87
            return value
103
88
        else:
104
 
            fields = dict()
105
 
 
106
 
        self.fingerprint = fields.get('fingerprint', 'N/A')
107
 
        self.trust = fields.get('trust', TRUST_UNKNOWN)
108
 
        self.flags = fields.get('flags', 0)
109
 
        self.display_name = fields.get('display-name', '')
110
 
        self.location = fields.get('location', LOCATION_MISSING)
 
89
            return default
111
90
    
112
91
    def get_flags(self):
 
92
        if self.flags is None:
 
93
            self.flags = self.get_field('flags', 0)
 
94
 
113
95
        return self.flags
114
96
 
115
97
    def get_display_name(self):
 
98
        if self.display_name is None:
 
99
            self.display_name = self.get_field('display-name')
 
100
 
116
101
        return self.display_name
117
102
 
118
103
    def get_id(self):
119
104
        return self.key.split(':')[1][8:]
120
105
 
121
106
    def get_fingerprint(self):
 
107
        if self.fingerprint is None:
 
108
            self.fingerprint = self.get_field('fingerprint')
 
109
 
122
110
        return self.fingerprint
123
111
 
124
112
    def get_trust(self):
 
113
        if self.trust is None:
 
114
            self.trust = self.get_field('trust', TRUST_UNKNOWN)
 
115
 
125
116
        return self.trust
126
117
 
127
118
    def get_location(self):
 
119
        if self.location is None:
 
120
            self.location = self.get_field('location', LOCATION_MISSING)
 
121
 
128
122
        return self.location
129
123
 
130
124
    def is_available(self):
131
 
        return self.available
 
125
        return self.key != ""
132
126
 
133
127
    def is_trusted(self):
134
 
        return self.flags & FLAG_TRUSTED != 0
 
128
        return self.get_flags() & FLAG_TRUSTED