def close(self): """Close the MAR file, writing out the new index if required. Furthur modifications to the file are not allowed.""" if self.mode == "w": if self.rewrite_index: self._write_index() # Update file size self.fileobj.seek(0, 2) totalsize = self.fileobj.tell() self.fileobj.seek(8) self.fileobj.write(struct.pack(">Q", totalsize)) # Write additional info self.fileobj.seek(20) self.fileobj.write(struct.pack(">L", len(self.additional_info))) for info in self.additional_info: info.write(self.fileobj) self.fileobj.flush() if self.signatures: fileobj = open(self.name, 'rb') generate_signature(fileobj, self._update_signatures) for sig in self.signatures: # print sig._offset sig.write_signature(self.fileobj) self.fileobj.close() self.fileobj = None
def close(self): """Close the MAR file, writing out the new index if required. Furthur modifications to the file are not allowed.""" if self.mode == "w": if self.rewrite_index: self._write_index() # Update file size self.fileobj.seek(0, 2) totalsize = self.fileobj.tell() self.fileobj.seek(8) self.fileobj.write(struct.pack(">Q", totalsize)) # Write additional info self.fileobj.seek(20) self.fileobj.write(struct.pack(">L", len(self.additional_info))) for info in self.additional_info: info.write(self.fileobj) self.fileobj.flush() if self.signatures: curr_pos = self.fileobj.tell() generate_signature(self.fileobj, self._update_signatures) self.fileobj.seek(curr_pos) for sig in self.signatures: # print sig._offset sig.write_signature(self.fileobj) self.fileobj.close() self.fileobj = None
def verify_signatures(self): if not mardor.signing.crypto: log.warning("no crypto modules loaded to check signatures " "(did you install the cryptography module?)") raise IOError("Verification failed") if not self.signatures: log.info("no signatures to verify") return fp = self.fileobj for sig in self.signatures: sig.init_verifier() generate_signature(fp, self._update_signatures) for sig in self.signatures: if not sig.verify_signature(): raise IOError("Verification failed") else: log.info("Verification OK (%s)", sig.algo_name)