"Fossies" - the Fresh Open Source Software Archive

Member "cryptsetup-2.4.3/tests/generators/generate-luks2-invalid-checksum-hdr1.img.sh" (24 Jul 2021, 732 Bytes) of package /linux/misc/cryptsetup-2.4.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 
    3 . lib.sh
    4 
    5 #
    6 # *** Description ***
    7 #
    8 # generate header with bad checksum in secondary binary header
    9 #
   10 
   11 # $1 full target dir
   12 # $2 full source luks2 image
   13 
   14 function prepare()
   15 {
   16     cp $SRC_IMG $TGT_IMG
   17     test -d $TMPDIR || mkdir $TMPDIR
   18     read_luks2_bin_hdr1 $TGT_IMG $TMPDIR/hdr1
   19 }
   20 
   21 function generate()
   22 {
   23     chks=$(echo "Arbitrary chosen string: D'oh!" | calc_sha256_checksum_stdin)
   24     write_checksum $chks $TMPDIR/hdr1
   25     write_luks2_bin_hdr1 $TMPDIR/hdr1 $TGT_IMG
   26 }
   27 
   28 function check()
   29 {
   30     chks_res=$(read_sha256_checksum $TMPDIR/hdr1)
   31     test "$chks" = "$chks_res" || exit 2
   32 }
   33 
   34 function cleanup()
   35 {
   36     rm -f $TMPDIR/*
   37     rm -fd $TMPDIR
   38 }
   39 
   40 test $# -eq 2 || exit 1
   41 
   42 TGT_IMG=$1/$(test_img_name $0)
   43 SRC_IMG=$2
   44 
   45 prepare
   46 generate
   47 check
   48 cleanup