/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: 2007-10-14 15:54:57 UTC
  • mto: This revision was merged to the branch mainline in revision 317.
  • Revision ID: daniel.schierbeck@gmail.com-20071014155457-m3ek29p4ima8ev7d
Added the new Window base class.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This program is free software; you can redistribute it and/or modify
2
 
# it under the terms of the GNU General Public License as published by
3
 
# the Free Software Foundation; either version 2 of the License, or
4
 
# (at your option) any later version.
5
 
 
6
 
# This program is distributed in the hope that it will be useful,
7
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9
 
# GNU General Public License for more details.
10
 
 
11
 
# You should have received a copy of the GNU General Public License
12
 
# along with this program; if not, write to the Free Software
13
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
 
 
15
 
__copyright__ = 'Copyright (C) 2008 Daniel Schierbeck'
16
 
__author__ = 'Daniel Schierbeck <daniel.schierbeck@gmail.com>'
17
 
 
18
 
import dbus
19
 
 
20
 
BUS_NAME = 'org.gnome.seahorse'
21
 
 
22
 
CRYPTO_INTERFACE = 'org.gnome.seahorse.CryptoService'
23
 
CRYPTO_PATH = '/org/gnome/seahorse/crypto'
24
 
 
25
 
OPENPGP_INTERFACE = 'org.gnome.seahorse.Keys'
26
 
OPENPGP_PATH = '/org/gnome/seahorse/keys/openpgp'
27
 
 
28
 
KEY_TYPE_OPENPGP = 'openpgp'
29
 
KEY_TYPE_SSH = 'ssh'
30
 
 
31
 
try:
32
 
    dbus.validate_bus_name(BUS_NAME)
33
 
except ValueError:
34
 
    # Seahorse isn't installed
35
 
    raise ImportError
36
 
except AttributeError:
37
 
    # Outdated version of DBus that doesn't have validate_bus_name
38
 
    raise ImportError
39
 
 
40
 
bus = dbus.SessionBus()
41
 
 
42
 
crypto = dbus.Interface(bus.get_object(BUS_NAME, CRYPTO_PATH), 
43
 
                        CRYPTO_INTERFACE)
44
 
openpgp = dbus.Interface(bus.get_object(BUS_NAME, OPENPGP_PATH),
45
 
                         OPENPGP_INTERFACE)
46
 
 
47
 
FLAG_VALID = 0x0001
48
 
FLAG_CAN_ENCRYPT = 0x0002
49
 
FLAG_CAN_SIGN = 0x0004
50
 
FLAG_EXPIRED = 0x0100
51
 
FLAG_REVOKED = 0x0200
52
 
FLAG_DISABLED = 0x0400
53
 
FLAG_TRUSTED = 0x1000
54
 
 
55
 
TRUST_NEVER = -1
56
 
TRUST_UNKNOWN = 0
57
 
TRUST_MARGINAL = 1
58
 
TRUST_FULL = 5
59
 
TRUST_ULTIMATE = 10
60
 
 
61
 
LOCATION_MISSING = 10
62
 
LOCATION_SEARCHING = 20
63
 
LOCATION_REMOTE = 50
64
 
LOCATION_LOCAL = 100
65
 
 
66
 
keyset = dict()
67
 
 
68
 
def verify(crypttext):
69
 
    (cleartext, key) = crypto.VerifyText(KEY_TYPE_OPENPGP, 1, crypttext)
70
 
 
71
 
    if key != "":
72
 
        if key not in keyset:
73
 
            keyset[key] = Key(key)
74
 
 
75
 
        return keyset[key]
76
 
 
77
 
class Key:
78
 
 
79
 
    def __init__(self, key):
80
 
        self.key = key
81
 
 
82
 
        (keys, unmatched) = openpgp.MatchKeys([self.get_id()], 0x00000010)
83
 
        self.available = (key in keys)
84
 
 
85
 
        if self.available:
86
 
            fields = openpgp.GetKeyFields(key, ['fingerprint', 'trust', 'flags', 'display-name', 'location'])
87
 
        else:
88
 
            fields = dict()
89
 
 
90
 
        self.fingerprint = fields.get('fingerprint', 'N/A')
91
 
        self.trust = fields.get('trust', TRUST_UNKNOWN)
92
 
        self.flags = fields.get('flags', 0)
93
 
        self.display_name = fields.get('display-name', '')
94
 
        self.location = fields.get('location', LOCATION_MISSING)
95
 
    
96
 
    def get_flags(self):
97
 
        return self.flags
98
 
 
99
 
    def get_display_name(self):
100
 
        return self.display_name
101
 
 
102
 
    def get_id(self):
103
 
        return self.key.split(':')[1][8:]
104
 
 
105
 
    def get_fingerprint(self):
106
 
        return self.fingerprint
107
 
 
108
 
    def get_trust(self):
109
 
        return self.trust
110
 
 
111
 
    def get_location(self):
112
 
        return self.location
113
 
 
114
 
    def is_available(self):
115
 
        return self.available
116
 
 
117
 
    def is_trusted(self):
118
 
        return self.flags & FLAG_TRUSTED != 0