MOD: refactored picseal class to be static only
This commit is contained in:
parent
5edd399c82
commit
f8f7db0eb6
|
@ -49,8 +49,8 @@ class JpgBin:
|
||||||
self.prev_mstr = "DUH!"
|
self.prev_mstr = "DUH!"
|
||||||
self.prev_imgData = False
|
self.prev_imgData = False
|
||||||
|
|
||||||
self.jpg_fp = JpgFingerprint()
|
self.jpg_fp = JpgFingerprint()
|
||||||
self.picseal = None
|
self.importSig = None
|
||||||
|
|
||||||
#
|
#
|
||||||
# check for JPG file type marker
|
# check for JPG file type marker
|
||||||
|
@ -278,13 +278,12 @@ class JpgBin:
|
||||||
ps_hdr_size = rec_hdr+len(JpgPicSeal.picseal_marker)
|
ps_hdr_size = rec_hdr+len(JpgPicSeal.picseal_marker)
|
||||||
remain_buf = self.data_len-(self.data_idx+ps_hdr_size)
|
remain_buf = self.data_len-(self.data_idx+ps_hdr_size)
|
||||||
if (remain_buf > ps_hdr_size):
|
if (remain_buf > ps_hdr_size):
|
||||||
self.picseal = JpgPicSeal()
|
if (JpgPicSeal.isPicSeal(self.data_buf[self.data_idx+rec_hdr:self.data_idx+ps_hdr_size])):
|
||||||
if (self.picseal.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
|
# calculate size, check buffer, maybe read more bytes from file
|
||||||
#
|
#
|
||||||
buf = self.__getBuf()
|
buf = self.__getBuf()
|
||||||
retval = self.picseal.deserialize(buf)
|
self.importSig = JpgPicSeal.deserialize(buf)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,7 @@ class JpgBinWrite:
|
||||||
#
|
#
|
||||||
def writeJpgPicSealPub(self, crypto_sig, fp):
|
def writeJpgPicSealPub(self, crypto_sig, fp):
|
||||||
self.__writeJpgHeader()
|
self.__writeJpgHeader()
|
||||||
|
JpgPicSeal.writePub(self.fhw, crypto_sig)
|
||||||
ps = JpgPicSeal(crypto_sig)
|
|
||||||
ps.writePub(self.fhw)
|
|
||||||
|
|
||||||
self.__writeJpgImg(fp)
|
self.__writeJpgImg(fp)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -29,10 +26,7 @@ class JpgBinWrite:
|
||||||
#
|
#
|
||||||
def writeJpgPicSealPvt(self, crypto_sig, fp):
|
def writeJpgPicSealPvt(self, crypto_sig, fp):
|
||||||
self.__writeJpgHeader()
|
self.__writeJpgHeader()
|
||||||
|
JpgPicSeal.writePvt(self.fhw, crypto_sig)
|
||||||
ps = JpgPicSeal(crypto_sig)
|
|
||||||
ps.writePvt(self.fhw)
|
|
||||||
|
|
||||||
self.__writeJpgImg(fp)
|
self.__writeJpgImg(fp)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,19 +23,14 @@ class JpgPicSeal:
|
||||||
pvt_marker = b'\x02'
|
pvt_marker = b'\x02'
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, sig=None):
|
def __init__(self):
|
||||||
if (sig):
|
pass
|
||||||
self.sig = sig
|
|
||||||
else:
|
|
||||||
self.sig = Signature()
|
|
||||||
self.sig_data = None
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# READ
|
# READ
|
||||||
#
|
#
|
||||||
|
|
||||||
def isPicSeal(self, buf):
|
def isPicSeal(buf):
|
||||||
if (buf == JpgPicSeal.picseal_marker):
|
if (buf == JpgPicSeal.picseal_marker):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -43,26 +38,27 @@ class JpgPicSeal:
|
||||||
#
|
#
|
||||||
# [size:2|picseal:7|type:1|sig:512|key:550] == 1072
|
# [size:2|picseal:7|type:1|sig:512|key:550] == 1072
|
||||||
#
|
#
|
||||||
def deserialize(self, buf):
|
def deserialize(buf):
|
||||||
|
sig = Signature()
|
||||||
retval = False
|
retval = False
|
||||||
|
|
||||||
# read type 0x01 is public key, 0x02 private key
|
# read type 0x01 is public key, 0x02 private key
|
||||||
try:
|
try:
|
||||||
if (buf[9] == ord(JpgPicSeal.pub_marker)):
|
if (buf[9] == ord(JpgPicSeal.pub_marker)):
|
||||||
self.sig.importPubKey(buf[522:])
|
sig.importPubKey(buf[522:])
|
||||||
print("*** *** ***")
|
print("*** *** ***")
|
||||||
print("*** Public Key Import Sucessful")
|
print("*** Public Key Import Sucessful")
|
||||||
print("*** *** ***")
|
print("*** *** ***")
|
||||||
else:
|
else:
|
||||||
self.sig.importPvtKey(buf[522:])
|
sig.importPvtKey(buf[522:])
|
||||||
print("*** *** ***")
|
print("*** *** ***")
|
||||||
print("*** Private Key Import Sucessful")
|
print("*** Private Key Import Sucessful")
|
||||||
print("*** *** ***")
|
print("*** *** ***")
|
||||||
retval = True
|
return sig
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logging.debug(ex)
|
logging.debug(ex)
|
||||||
|
|
||||||
return retval
|
return None
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -79,23 +75,23 @@ class JpgPicSeal:
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
#
|
||||||
def serilize(self, fname):
|
def serilize(fname):
|
||||||
pass
|
pass
|
||||||
#
|
#
|
||||||
# input is the Crypto Sig class
|
# input is the Crypto Sig class
|
||||||
#
|
#
|
||||||
def writePub(self, fhw):
|
def writePub(fhw, sig):
|
||||||
self.__writeData(fhw, self.sig.sig_data, self.sig.getPubKeyDER(), JpgPicSeal.pub_marker)
|
JpgPicSeal.__writeData(fhw, sig.sig_data, sig.getPubKeyDER(), JpgPicSeal.pub_marker)
|
||||||
|
|
||||||
#
|
#
|
||||||
# input is the Crypto Sig class
|
# input is the Crypto Sig class
|
||||||
#
|
#
|
||||||
def writePvt(self, fhw):
|
def writePvt(fhw, sig):
|
||||||
self.__writeData(fhw, self.sig.sig_data, self.sig.getPvtKeyDER(), JpgPicSeal.pvt_marker)
|
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
|
# must include 2 bytes for length too, plus 1 for the key type
|
||||||
size = 3
|
size = 3
|
||||||
size += len(JpgPicSeal.picseal_marker)
|
size += len(JpgPicSeal.picseal_marker)
|
||||||
|
|
Loading…
Reference in New Issue