示例#1
0
文件: rpmdb.py 项目: kholia/pyrpm
    def readRpm(self, key, db, tags):
        pkg = RpmDBPackage(self.config, "dummy")
        pkg.reponame = "installed"
        pkg.key = key
        pkg.db = self
        data = db[key]
        try:
            val = unpack("I", key)[0]
        except struct.error:
            log.error("Invalid key %s in rpmdb", repr(key))
            return None

        if val == 0:
            return None

        try:
            (indexNo, storeSize) = unpack("!2I", data[0:8])
        except struct.error:
            log.error("Value for key %s in rpmdb is too short", repr(key))
            return None

        if len(data) < indexNo*16 + 8:
            log.error("Value for key %s in rpmdb is too short", repr(key))
            return None
        indexdata = unpack("!%sI" % (indexNo*4), data[8:indexNo*16+8])
        indexes = zip(indexdata[0::4], indexdata[1::4],
                      indexdata[2::4], indexdata[3::4])
        indexdata = {}
        for idx in indexes:
            if rpmtagname.has_key(idx[0]):
                indexdata[rpmtagname[idx[0]]] = idx
        pkg.indexdata = indexdata

        storedata = data[indexNo*16+8:]
        pkg["signature"] = {}

        # read the tags
        ok = self.readTags(pkg, tags, storedata)
        if not ok:
            return None

        # DON'T add epoch tag, we use pkg.getEpoch() to make it work properly
        #if not pkg.has_key("epoch"):
        #    pkg["epoch"] = [ 0 ]


        if pkg["name"] == "gpg-pubkey":
            return None  # FIXME
            try:
                keys = openpgp.parsePGPKeys(pkg["description"])
            except ValueError, e:
                log.error("Invalid key package %s: %s", pkg["name"], e)
                return None
            for k in keys:
                self.keyring.addKey(k)
            return None
示例#2
0
 def readPGPKeys(self):
     for url in self.key_urls:
         filename = self.nc.cache(url, 1)
         try:
             f = file(filename)
             key_data = f.read()
             f.close()
         except Exception, e:
             log.error("Error reading GPG key %s: %s", filename, e)
             continue
         try:
             key_data = openpgp.isolateASCIIArmor(key_data)
             keys = openpgp.parsePGPKeys(key_data)
         except Exception, e:
             log.error("Invalid GPG key %s: %s", url, e)
             continue
示例#3
0
 def readPGPKeys(self):
     for url in self.key_urls:
         filename = self.nc.cache(url, 1)
         try:
             f = file(filename)
             key_data = f.read()
             f.close()
         except Exception, e:
             log.error("Error reading GPG key %s: %s", filename, e)
             continue
         try:
             key_data = openpgp.isolateASCIIArmor(key_data)
             keys = openpgp.parsePGPKeys(key_data)
         except Exception, e:
             log.error("Invalid GPG key %s: %s", url, e)
             continue