aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/aesxx/utils/test/basic.cmake
blob: aabd57b9348995b8e622332581749cb3999cd46f (plain) (blame)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
foreach(action encrypt decrypt)
    foreach(util block file bmp)
        set(exe "${action}_${util}")
        set(tgt "util_${exe}")
        add_test(NAME "${tgt}_help" COMMAND Python3::Interpreter
            "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
            run
            --pass-regex "usage: ${exe}\\.exe" "set algorithm"
            --fail-regex "usage error:"
            --
            "$<TARGET_FILE:${tgt}>" -h
        )
        add_test(NAME "${tgt}_no_args" COMMAND Python3::Interpreter
            "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
            run
            --exit-code 1
            --pass-regex
                "usage error: the option '--algorithm' is required"
                "usage: ${exe}\\.exe"
                "set algorithm"
            --
            "$<TARGET_FILE:${tgt}>"
        )
    endforeach()

    set(exe "${action}_block")
    set(tgt "util_${exe}")
    add_test(NAME "${tgt}_no_input" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --fail-regex ".+"
        --
        "$<TARGET_FILE:${tgt}>" -a aes256 -m ofb
    )
    add_test(NAME "${tgt}_only_key" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --fail-regex ".+"
        --
        "$<TARGET_FILE:${tgt}>" -a AES256 -m ECB 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
    )
    add_test(NAME "${tgt}_invalid_algorithm" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex "usage error:" "for option '--algorithm' is invalid"
        --
        "$<TARGET_FILE:${tgt}>" -a bar -m ecb
    )
    add_test(NAME "${tgt}_invalid_mode" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex "usage error:" "for option '--mode' is invalid"
        --
        "$<TARGET_FILE:${tgt}>" -a aes128 -m foo
    )
    add_test(NAME "${tgt}_no_iv" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex "usage error: an initialization vector is required"
        --
        "$<TARGET_FILE:${tgt}>" -a aes192 -m cbc 000102030405060708090a0b0c0d0e0f1011121314151617
    )
    add_test(NAME "${tgt}_invalid_key1" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex [=[AES error: Couldn't parse '0001020304050607' \(possibly not complete input\) as a 32-byte hex string]=]
        --
        "$<TARGET_FILE:${tgt}>" -a aes256 -m ecb 0001020304050607
    )
    add_test(NAME "${tgt}_invalid_key2" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex [=[AES error: Couldn't parse 'foobar' \(possibly not complete input\) as a 32-byte hex string]=]
        --
        "$<TARGET_FILE:${tgt}>" -a aes256 -m ecb foobar
    )
    add_test(NAME "${tgt}_invalid_iv1" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex [=[AES error: Couldn't parse '2222222222222222222222222222222' \(possibly not complete input\) as a 16-byte hex string]=]
        --
        "$<TARGET_FILE:${tgt}>" -a aes128 -m cbc 11111111111111111111111111111111 2222222222222222222222222222222
    )
    add_test(NAME "${tgt}_invalid_iv2" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex [=[AES error: Couldn't parse '222222222222222222222222222222222' \(possibly not complete input\) as a 16-byte hex string]=]
        --
        "$<TARGET_FILE:${tgt}>" -a aes128 -m cbc 11111111111111111111111111111111 222222222222222222222222222222222
    )
    add_test(NAME "${tgt}_invalid_block" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex [=[AES error: Couldn't parse '0' \(possibly not complete input\) as a 16-byte hex string]=]
        --
        "$<TARGET_FILE:${tgt}>" -a aes128 -m cbc 11111111111111111111111111111111 22222222222222222222222222222222 0
    )

    set(exe "${action}_file")
    set(tgt "util_${exe}")
    add_test(NAME "${tgt}_no_key" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex [=[the option '--key' is required but missing]=]
        --
        "$<TARGET_FILE:${tgt}>" -a aes128 -m ecb -i in.txt -o out.txt
    )
    add_test(NAME "${tgt}_no_files" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --exit-code 1
        --pass-regex [=[the option '--input' is required but missing]=]
        --
        "$<TARGET_FILE:${tgt}>" -a aes128 -m ecb -k 11111111111111111111111111111111
    )
    add_test(NAME "${tgt}_no_iv" COMMAND Python3::Interpreter
        "${CMAKE_SOURCE_DIR}/cmake/tools/ctest-driver.py"
        run
        --
        "$<TARGET_FILE:${tgt}>" -a aes128 -m cbc -k 11111111111111111111111111111111 -i in.txt -o out.txt
    )
endforeach()