Skip to content

Commit 2c43bfa

Browse files
committed
Include the b2sum for the original data in the generated PDF file.
This aids in verification 1) after creation, that a PDF was created which can be successfully restored --> see new paperbackup-verify.sh script 2) after restoration, by running b2sum on the restored data, that the restoration has indeed produced the exact same data as had been in the original file
1 parent 492101e commit 2c43bfa

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

paperbackup-verify.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/bash
2+
3+
# USAGE: paperbackup-verify.sh backup.pdf
4+
# where backup.pdf should be the pdf created with paperbackup.py
5+
6+
RESTOREPROG=$(dirname $0)/paperrestore.sh
7+
8+
rPDF=$( $RESTOREPROG $1 )
9+
10+
bPDF=$(echo "$rPDF" | b2sum | cut -d ' ' -f 1 )
11+
bEmbedded=$(pdftotext $1 - | grep b2sum -A2 | tail -2 | tr -d '\n')
12+
13+
if [ "x$bPDF" == "x$bEmbedded" ]; then
14+
echo "b2sums MATCH :-)"
15+
echo
16+
exit 0
17+
else
18+
echo "Creating diff:"
19+
echo "$rPDF" | diff ${1%.*} -
20+
diffret=$?
21+
echo
22+
if [ $diffret -ne 0 ]; then
23+
echo "diff and b2sums do NOT match!"
24+
echo "restored b2sum from PDF: " $bPDF
25+
echo "original b2sum embedded: " $bEmbedded
26+
echo
27+
exit 11
28+
else
29+
echo "diff matches but b2sum is missing."
30+
echo
31+
exit 1
32+
fi
33+
fi

paperbackup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import qrencode
3636
from tempfile import mkstemp
3737
from datetime import datetime
38+
from shutil import which
3839
from PIL import Image
3940
from pyx import *
4041

@@ -171,6 +172,9 @@ def finish_page(pdf, canv, pageno):
171172

172173
chksumlines.append(line)
173174

175+
# we also want a checksum which the restored file should match
176+
b2sum = hashlib.blake2b(bytes(ascdata, 'utf8')).hexdigest()
177+
174178
# add some documentation around the plaintest
175179
outlines=[]
176180
coldoc=" "*splitat
@@ -179,6 +183,10 @@ def finish_page(pdf, canv, pageno):
179183
outlines.extend(chksumlines)
180184
outlines.append("")
181185
outlines.append("")
186+
outlines.append("b2sum of input file (split over 2 lines):")
187+
outlines.append("%s"%b2sum[:64])
188+
outlines.append("%s"%b2sum[64:])
189+
outlines.append("")
182190
outlines.append("")
183191
outlines.append("--")
184192
outlines.append("Created with paperbackup.py")
@@ -216,3 +224,16 @@ def finish_page(pdf, canv, pageno):
216224

217225
os.remove(temp_text_path)
218226
os.remove(temp_barcode_path)
227+
228+
verify_prog = which("paperbackup-verify.sh")
229+
if not verify_prog:
230+
verify_prog = which("paperbackup-verify")
231+
if not verify_prog:
232+
verify_prog = which(os.path.join(os.path.dirname(sys.argv[0]), "paperbackup-verify.sh"))
233+
if not verify_prog:
234+
print("\n NOTE: Could not find 'paperbackup-verify' program which should have been")
235+
print( " installed together with {}! ".format(sys.argv[0]))
236+
verify_prog = "paperbackup-verify"
237+
print("\n !!!!!!!!!")
238+
print(" ATTENTION: Running '{} {}.pdf' NOW is STRONGLY advised to".format(verify_prog, just_filename))
239+
print(" !!!!!!!!! verify that zbarimg can read back the generated qr codes!\n")

0 commit comments

Comments
 (0)