diff --git a/libs/jpg_bin.py b/libs/jpg_bin.py index ac50acb..4e62f22 100644 --- a/libs/jpg_bin.py +++ b/libs/jpg_bin.py @@ -49,8 +49,8 @@ class JpgBin: self.prev_mstr = "DUH!" self.prev_imgData = False - self.jpg_fp = JpgFingerprint() - self.picseal = None + self.jpg_fp = JpgFingerprint() + self.importSig = None # # check for JPG file type marker @@ -278,13 +278,12 @@ class JpgBin: ps_hdr_size = rec_hdr+len(JpgPicSeal.picseal_marker) remain_buf = self.data_len-(self.data_idx+ps_hdr_size) if (remain_buf > ps_hdr_size): - self.picseal = JpgPicSeal() - if (self.picseal.isPicSeal(self.data_buf[self.data_idx+rec_hdr:self.data_idx+ps_hdr_size])): + if (JpgPicSeal.isPicSeal(self.data_buf[self.data_idx+rec_hdr:self.data_idx+ps_hdr_size])): # # calculate size, check buffer, maybe read more bytes from file # buf = self.__getBuf() - retval = self.picseal.deserialize(buf) + self.importSig = JpgPicSeal.deserialize(buf) return True return False diff --git a/libs/jpg_bin_w.py b/libs/jpg_bin_w.py index 440fb0d..248ce01 100644 --- a/libs/jpg_bin_w.py +++ b/libs/jpg_bin_w.py @@ -18,10 +18,7 @@ class JpgBinWrite: # def writeJpgPicSealPub(self, crypto_sig, fp): self.__writeJpgHeader() - - ps = JpgPicSeal(crypto_sig) - ps.writePub(self.fhw) - + JpgPicSeal.writePub(self.fhw, crypto_sig) self.__writeJpgImg(fp) # @@ -29,10 +26,7 @@ class JpgBinWrite: # def writeJpgPicSealPvt(self, crypto_sig, fp): self.__writeJpgHeader() - - ps = JpgPicSeal(crypto_sig) - ps.writePvt(self.fhw) - + JpgPicSeal.writePvt(self.fhw, crypto_sig) self.__writeJpgImg(fp) diff --git a/libs/jpg_picseal.py b/libs/jpg_picseal.py index 813382a..6def956 100644 --- a/libs/jpg_picseal.py +++ b/libs/jpg_picseal.py @@ -23,19 +23,14 @@ class JpgPicSeal: pvt_marker = b'\x02' - def __init__(self, sig=None): - if (sig): - self.sig = sig - else: - self.sig = Signature() - self.sig_data = None - + def __init__(self): + pass # # READ # - def isPicSeal(self, buf): + def isPicSeal(buf): if (buf == JpgPicSeal.picseal_marker): return True return False @@ -43,26 +38,27 @@ class JpgPicSeal: # # [size:2|picseal:7|type:1|sig:512|key:550] == 1072 # - def deserialize(self, buf): + def deserialize(buf): + sig = Signature() retval = False # read type 0x01 is public key, 0x02 private key try: if (buf[9] == ord(JpgPicSeal.pub_marker)): - self.sig.importPubKey(buf[522:]) + sig.importPubKey(buf[522:]) print("*** *** ***") print("*** Public Key Import Sucessful") print("*** *** ***") else: - self.sig.importPvtKey(buf[522:]) + sig.importPvtKey(buf[522:]) print("*** *** ***") print("*** Private Key Import Sucessful") print("*** *** ***") - retval = True + return sig except Exception as ex: logging.debug(ex) - return retval + return None # @@ -79,23 +75,23 @@ class JpgPicSeal: # # - def serilize(self, fname): + def serilize(fname): pass # # input is the Crypto Sig class # - def writePub(self, fhw): - self.__writeData(fhw, self.sig.sig_data, self.sig.getPubKeyDER(), JpgPicSeal.pub_marker) + def writePub(fhw, sig): + JpgPicSeal.__writeData(fhw, sig.sig_data, sig.getPubKeyDER(), JpgPicSeal.pub_marker) # # input is the Crypto Sig class # - def writePvt(self, fhw): - self.__writeData(fhw, self.sig.sig_data, self.sig.getPvtKeyDER(), JpgPicSeal.pvt_marker) + def writePvt(fhw, sig): + JpgPicSeal.__writeData(fhw, sig.sig_data, sig.getPvtKeyDER(), JpgPicSeal.pvt_marker) # - def __writeData(self, fhw, sig_data, keyder, pubpvt): + def __writeData(fhw, sig_data, keyder, pubpvt): # must include 2 bytes for length too, plus 1 for the key type size = 3 size += len(JpgPicSeal.picseal_marker)