File: test_plaintext.sh

package info (click to toggle)
libzc 0.4.3-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 872 kB
  • sloc: ansic: 7,407; sh: 327; python: 171; makefile: 99
file content (67 lines) | stat: -rwxr-xr-x 1,976 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash

# Copyright (C) 2012-2018 Marc Ferland
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

ZIP=$(which zip)
CMD="libtool --mode=execute ../yazc/yazc"

create_dummy_files() {
    for i in $(seq 0 2)
    do
        dd if=/dev/urandom of=file_${i} bs=$(($RANDOM * 10)) count=1 &>/dev/null
    done
}

create_zip_files() {
    FILES="file_0 file_1 file_2"
    zip -e -P ${PW} ${E} ${FILES} &>/dev/null
    zip ${P} ${FILES} &>/dev/null
}

cleanup() {
    rm -f file_[0-9] [ep]_archive_*
}

if [ ! -f "${ZIP}" ]; then
    echo >&2 "error: zip not found!"
    exit 1
fi

while true; do
    PW=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $(($RANDOM % 10 + 1)) | head -n 1)
    E="e_archive_${PW}.zip"
    P="p_archive_${PW}.zip"

    cleanup
    create_dummy_files
    create_zip_files

    EINFO=$(${CMD} info ${E} | grep file_0 | sed 's/\ \+/ /g')
    PINFO=$(${CMD} info ${P} | grep file_0 | sed 's/\ \+/ /g')
    POFF1=$(echo ${PINFO} | cut -d' ' -f4)
    POFF2=$(echo ${PINFO} | cut -d' ' -f5)
    COFF1=$(echo ${EINFO} | cut -d' ' -f4)
    COFF2=$(echo ${EINFO} | cut -d' ' -f5)
    CBEGN=$(echo ${EINFO} | cut -d' ' -f3)

    echo libtool exe ../yazc/yazc plaintext ${P}:${POFF1}:${POFF2} ${E}:${COFF1}:${COFF2}:${CBEGN}
    if ! libtool exe ../yazc/yazc plaintext ${P}:${POFF1}:${POFF2} ${E}:${COFF1}:${COFF2}:${CBEGN}; then
	echo >&2 "ERROR"
	exit 1
    fi
done

exit 0