Imported Upstream version 2.6.1
[platform/upstream/cryptsetup.git] / tests / generators / generate-luks2-segment-missing-type.img.sh
1 #!/bin/bash
2
3 . lib.sh
4
5 #
6 # *** Description ***
7 #
8 # generate primary header with segment type field missing
9 #
10 # secondary header is corrupted on purpose as well
11 #
12
13 # $1 full target dir
14 # $2 full source luks2 image
15
16 function generate()
17 {
18         # remove mandatory encryption field
19         json_str=$(jq -c 'del(.segments."0".type)' $TMPDIR/json0)
20         test ${#json_str} -lt $((LUKS2_JSON_SIZE*512)) || exit 2
21
22         write_luks2_json "$json_str" $TMPDIR/json0
23
24         lib_mangle_json_hdr0_kill_hdr1
25 }
26
27 function check()
28 {
29         lib_hdr1_killed || exit 2
30
31         read_luks2_json0 $TGT_IMG $TMPDIR/json_res0
32         jq -c 'if .segments."0".type
33                then error("Unexpected value in result json") else empty end' $TMPDIR/json_res0 || exit 5
34 }
35
36 lib_prepare $@
37 generate
38 check
39 lib_cleanup