3 from tempfile import mkdtemp
5 from shutil import rmtree
9 class KeyError(Exception):
10 def __init__(self, key, *args):
11 Exception.__init__(self)
15 return ''+self.key+' :'+' '.join(self.args)
19 self.dbdir = mkdtemp(prefix='oscrpmdb')
21 rpm.addMacro('_dbpath', self.dbdir)
22 self.ts = rpm.TransactionSet()
28 def readkeys(self, keys=[]):
29 rpm.addMacro('_dbpath', self.dbdir)
33 rpm.delMacro("_dbpath")
43 def readkey(self, file):
44 if file in self.imported:
49 if line and line[0:14] == "-----BEGIN PGP":
51 while line and line != "\n":
54 raise KeyError(file, "not a pgp public key")
56 raise KeyError(file, "not a pgp public key")
61 if line[0:12] == "-----END PGP":
67 if not line or line[0:12] != "-----END PGP":
68 raise KeyError(file, "not a pgp public key")
70 bkey = base64.b64decode(key)
72 r = self.ts.pgpImportPubkey(bkey)
74 raise KeyError(file, "failed to import pubkey")
75 self.imported[file] = 1
78 fd = os.open(pkg, os.O_RDONLY)
79 hdr = self.ts.hdrFromFdno(fd)
82 if __name__ == "__main__":
86 for arg in sys.argv[1:]:
87 if arg[-4:] == '.rpm':
94 checker.readkeys(keyfiles)