Switched to using bash arrays to hold split versions of key instead of temp files.
This commit is contained in:
parent
1eda87d5fb
commit
d48e5707c3
2 changed files with 26 additions and 41 deletions
41
asc2qr.sh
41
asc2qr.sh
|
@ -28,7 +28,7 @@
|
|||
|
||||
# Maximum chuck size to send to the QR encoder. QR version 40 supports
|
||||
# 2,953 bytes of storage.
|
||||
file_split_size=2800
|
||||
max_qr_bytes=2800
|
||||
|
||||
# Prefix string for the PNG images that are produced
|
||||
image_prefix="QR"
|
||||
|
@ -45,38 +45,27 @@ if [ ! -f ${asc_key} ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Create a temp file to use as a pattern for splitting the input key file.
|
||||
# This helps protect against file collisions in the current directory.
|
||||
export TMPDIR=""
|
||||
tmp_file=$(mktemp keyparts.XXXXXX)
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "failed to create temporary file"
|
||||
exit 1
|
||||
fi
|
||||
## Split the key file into usable chunks that the QR encoder can consume
|
||||
chunks=()
|
||||
while true; do
|
||||
s=$( head -c ${max_qr_bytes} )
|
||||
echo "$s"
|
||||
if [ ${#s} -gt 0 ]; then
|
||||
chunks+=("${s}")
|
||||
else
|
||||
break
|
||||
fi
|
||||
done <<< "$( cat ${asc_key} )"
|
||||
|
||||
# Split the key file into usable chunks that the QR encoder can consume
|
||||
split -b ${file_split_size} ${asc_key} "${tmp_file}."
|
||||
|
||||
# For each chunk, encode it into a qc image
|
||||
## For each chunk, encode it into a qr image
|
||||
index=1
|
||||
for file in ${tmp_file}.*; do
|
||||
for c in "${chunks[@]}"; do
|
||||
img="${image_prefix}${index}.png"
|
||||
echo "generating ${img}"
|
||||
cat ${file} | qrencode -o ${img}
|
||||
echo -n "${c}" | qrencode -o ${img}
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "failed to encode image"
|
||||
exit 2
|
||||
fi
|
||||
index=$((index+1))
|
||||
done
|
||||
|
||||
# Find the correct secure deletion utility (srm on Mac, shred on Linux)
|
||||
sec_del="srm"
|
||||
which ${sec_del} 2>&1 1>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
sec_del="shred --remove"
|
||||
fi
|
||||
|
||||
# Securely clean up temporary files
|
||||
${sec_del} ${tmp_file}
|
||||
${sec_del} ${tmp_file}.*
|
||||
|
|
22
qr2asc.sh
22
qr2asc.sh
|
@ -43,6 +43,7 @@ if [ $? -ne 0 ]; then
|
|||
fi
|
||||
|
||||
# For each image on the command line, decode it into text
|
||||
chunks=()
|
||||
index=1
|
||||
for img in "$@"; do
|
||||
if [ ! -f ${img} ]; then
|
||||
|
@ -51,24 +52,19 @@ for img in "$@"; do
|
|||
fi
|
||||
asc_key="${tmp_file}.${index}"
|
||||
echo "decoding ${img}"
|
||||
zbarimg --raw ${img} 2>/dev/null | perl -p -e 'chomp if eof' > ${asc_key}
|
||||
chunk=$( zbarimg --raw ${img} 2>/dev/null | perl -p -e 'chomp if eof' )
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "failed to decode QR image"
|
||||
exit 2
|
||||
fi
|
||||
chunks+=("${chunk}")
|
||||
index=$((index+1))
|
||||
done
|
||||
|
||||
asc_key=""
|
||||
for c in "${chunks[@]}"; do
|
||||
asc_key+="${c}"
|
||||
done
|
||||
|
||||
echo "creating ${output_key_name}"
|
||||
cat ${tmp_file}.* > ${output_key_name}
|
||||
|
||||
# Find the correct secure deletion utility (srm on Mac, shred on Linux)
|
||||
sec_del="srm"
|
||||
which ${sec_del} 2>&1 1>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
sec_del="shred --remove"
|
||||
fi
|
||||
|
||||
# Securely clean up temporary files
|
||||
${sec_del} ${tmp_file}
|
||||
${sec_del} ${tmp_file}.*
|
||||
echo "${asc_key}" > ${output_key_name}
|
||||
|
|
Loading…
Reference in a new issue