1 from tempfile import mkdtemp
3 from shutil import rmtree
7 class KeyError(Exception):
8 def __init__(self, key, *args):
9 Exception.__init__(self)
13 return ''+self.key+' :'+' '.join(self.args)
17 self.dbdir = mkdtemp(prefix='oscrpmdb')
19 rpm.addMacro('_dbpath', self.dbdir)
20 self.ts = rpm.TransactionSet()
26 def readkeys(self, keys=[]):
27 rpm.addMacro('_dbpath', self.dbdir)
34 if not len(self.imported):
35 raise KeyError('', "no key imported")
37 rpm.delMacro("_dbpath")
47 def readkey(self, file):
48 if file in self.imported:
53 if line and line[0:14] == "-----BEGIN PGP":
55 while line and line != "\n":
58 raise KeyError(file, "not a pgp public key")
60 raise KeyError(file, "not a pgp public key")
65 if line[0:12] == "-----END PGP":
71 if not line or line[0:12] != "-----END PGP":
72 raise KeyError(file, "not a pgp public key")
74 bkey = base64.b64decode(key)
76 r = self.ts.pgpImportPubkey(bkey)
78 raise KeyError(file, "failed to import pubkey")
79 self.imported[file] = 1
82 fd = os.open(pkg, os.O_RDONLY)
83 hdr = self.ts.hdrFromFdno(fd)
86 if __name__ == "__main__":
90 for arg in sys.argv[1:]:
91 if arg[-4:] == '.rpm':
98 checker.readkeys(keyfiles)