picseal_pub/picseal.py

97 lines
2.5 KiB
Python

#
#
#
import argparse
import logging
from libs.jpg_proc import JpgProc
printall = False
printmeta = False
printimage = False
write_picseal = False
# hash the image binary data only (not metadata)
# create new pub keys, sign hash
# export signature & public key to a new image file
def processImage(image_fn):
jpg_proc = JpgProc()
jpg_proc.process(image_fn)
if (write_picseal):
jpg_proc.hash()
print("Writing PicSeal JPG files...")
jpg_proc.writePicSealJpg()
printImageInfo(jpg_proc.jpg)
#
def printImageInfo(jpg_bin):
if (printall):
print( str(jpg_bin) )
if (printimage):
print( jpg_bin.printMarkerImg())
if (printmeta):
print( jpg_bin.printMarkerMeta())
def main():
parseArgs()
def parseArgs():
print
print("***** ***** ***** *****")
print(" ** Pic * Seal ** ")
print("***** ***** ***** *****\n")
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file', required=False, help="source image file")
parser.add_argument('-v', '--verbose', action='store_true', help="will set logging level to INFO")
parser.add_argument('-vv', '--vverbose', action='store_true', help="will set logging level to DEBUG")
parser.add_argument('-l', '--logging', action='store_true', help="will supercede the -v option and send all logging to a file, logging.DEBUG")
parser.add_argument('-pm', '--printmeta', action='store_true', help="print the metadata markers")
parser.add_argument('-pi', '--printimage', action='store_true', help="print the image markers")
parser.add_argument('-pa', '--printall', action='store_true', help="print all markers")
parser.add_argument('-w', '--write', action='store_true', help="write picseal files")
args = parser.parse_args()
if (args.logging):
logging.basicConfig(filename='dbfp.log', level=logging.DEBUG)
if (args.verbose):
logging.basicConfig(level=logging.INFO)
elif (args.vverbose):
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.CRITICAL)
if (args.printall):
global printall
printall = True
if (args.printmeta):
global printmeta
printmeta = True
if (args.printimage):
global printimage
printimage = True
if (args.write):
global write_picseal
write_picseal = True
if (args.file):
processImage(args.file)
else:
print('***** ***** ***** *****')
print('ERROR: missing image file')
print(' picseal.py -f <image_file>')
print('***** ***** ***** *****')
if __name__ == "__main__":
main()
print