summaryrefslogtreecommitdiff
path: root/keymanifest.py
blob: 25fa423a6086caf6c60d6b86f2146685ee88ab38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# vim: set filencoding=utf8
"""
Key Manifest

@author: Mike Crute (mcrute@gmail.com)
@organization: SoftGroup Interactive, Inc.
@date: May 05, 2010
"""

from keys import PublicKey


class KeyManifest(dict):
    """
    KeyManifest stores a list of public keys indexed by their
    comment field. This object acts like a dictionary and will
    return public key instances for getitems.
    """

    @classmethod
    def from_file(cls, filename):
        inst = cls()
        fp = open(filename)

        for line in fp:
            line = line.strip()
            if not line or line.startswith('#'):
                continue

            _, key, user = line.split()
            inst[user.strip()] = key.strip()

        return inst

    def __getitem__(self, key):
        return PublicKey.from_string(dict.__getitem__(self, key))