Skip to content

Commit 57591d0

Browse files
authored
clang-format and include-what-you-use run (#111)
1 parent daa541a commit 57591d0

File tree

6 files changed

+60
-37
lines changed

6 files changed

+60
-37
lines changed

configure.ac

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
# SPDX-FileCopyrightText: 2022 stenc authors
22
# SPDX-License-Identifier: GPL-2.0-or-later
33

4-
AC_INIT([stenc],[1.1.1])
4+
AC_INIT([stenc],[2.0.0])
55
AC_CONFIG_SRCDIR([src/main.cpp])
66
AM_INIT_AUTOMAKE([foreign subdir-objects])
77

8-
AC_CONFIG_HEADERS([config.h])
9-
AC_CHECK_HEADER([sys/types.h])
10-
AC_CHECK_HEADER([sys/machine.h])
8+
AC_CONFIG_HEADERS([config.h])]
9+
AC_CHECK_HEADERS
10+
AC_CHECK_HEADERS([arpa/inet.h netinet/in.h])
1111
# Checks for programs
1212
AC_PROG_CXX
1313

14-
# Checks for header files.
15-
AC_PROG_EGREP
16-
1714
AC_MSG_CHECKING(whether to output raw SCSI messages)
1815
AC_ARG_WITH([scsi-debug],
1916
[AS_HELP_STRING([--with-scsi-debug],[enable scsi communication debug])],

src/main.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,38 @@ GNU General Public License for more details.
2020
#include <config.h>
2121

2222
#include <algorithm>
23+
#include <array>
24+
#include <cctype>
2325
#include <charconv>
26+
#include <cstddef>
2427
#include <cstdint>
2528
#include <cstdlib>
2629
#include <fstream>
30+
#include <functional>
2731
#include <iomanip>
28-
#include <ios>
2932
#include <iostream>
3033
#include <limits>
3134
#include <map>
35+
#include <memory>
3236
#include <optional>
3337
#include <sstream>
38+
#include <stdexcept>
3439
#include <string>
40+
#include <system_error>
3541
#include <vector>
3642

43+
#include <errno.h>
3744
#include <getopt.h>
45+
#include <string.h>
3846
#include <sys/mtio.h>
39-
#include <sys/stat.h>
4047
#include <syslog.h>
4148
#include <termios.h>
4249

43-
#ifdef HAVE_STDLIB_H
44-
#include <stdlib.h>
50+
#if HAVE_ARPA_INET_H
51+
#include <arpa/inet.h>
4552
#endif
46-
#ifdef HAVE_STRING_H
47-
#include <string.h>
53+
#if HAVE_NETINET_IN_H
54+
#include <netinet/in.h>
4855
#endif
4956
#ifdef HAVE_UNISTD_H
5057
#include <unistd.h>
@@ -383,7 +390,7 @@ int main(int argc, char **argv)
383390
std::optional<scsi::encrypt_mode> enc_mode;
384391
std::optional<scsi::decrypt_mode> dec_mode;
385392
std::optional<std::uint8_t> algorithm_index;
386-
std::vector<uint8_t> key;
393+
std::vector<std::uint8_t> key;
387394
std::string key_name;
388395
scsi::sde_rdmc rdmc {};
389396
scsi::kadf kad_format {};

src/scsiencrypt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ GNU General Public License for more details.
2626
#include <iostream>
2727
#include <sstream>
2828
#include <string>
29+
#include <system_error>
2930
#include <type_traits>
3031

3132
#include <fcntl.h>
@@ -36,7 +37,6 @@ GNU General Public License for more details.
3637
#endif
3738

3839
#if defined(OS_LINUX)
39-
#include <scsi/scsi.h>
4040
#include <scsi/sg.h>
4141
constexpr unsigned int SCSI_TIMEOUT {5000u};
4242
#elif defined(OS_FREEBSD)

src/scsiencrypt.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ GNU General Public License for more details.
2020
#ifndef _SCSIENC_H
2121
#define _SCSIENC_H
2222

23+
#include <config.h>
24+
2325
#include <array>
24-
#include <bitset>
2526
#include <cstddef>
2627
#include <cstdint>
2728
#include <functional>
2829
#include <memory>
2930
#include <ostream>
3031
#include <string>
3132
#include <vector>
33+
#include <stdexcept>
34+
#include <utility>
3235

36+
#if HAVE_ARPA_INET_H
3337
#include <arpa/inet.h>
34-
35-
#ifdef HAVE_SYS_MACHINE_H
36-
#include <sys/machine.h>
3738
#endif
38-
39-
#ifdef HAVE_SYS_TYPES_H
40-
#include <sys/types.h>
39+
#if HAVE_NETINET_IN_H
40+
#include <netinet/in.h>
4141
#endif
4242

4343
namespace scsi {

tests/output.cpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#define CATCH_CONFIG_MAIN
66
#include "catch.hpp"
77

8-
#include <memory>
8+
#include <cstdint>
9+
#include <map>
10+
#include <optional>
911
#include <sstream>
1012
#include <string>
13+
#include <vector>
1114

12-
#include "config.h"
1315
#include "main.cpp"
1416

1517
using namespace std::literals::string_literals;
@@ -58,7 +60,7 @@ TEST_CASE("Test SCSI inquiry output", "[output]")
5860
TEST_CASE("SCSI get device encryption status output 1", "[output]")
5961
{
6062
std::map<std::uint8_t, std::string> algorithms {
61-
{ 1, "AES-256-GCM-128"s },
63+
{1, "AES-256-GCM-128"s},
6264
};
6365
const std::uint8_t page[] {
6466
0x00, 0x20, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -69,14 +71,15 @@ Reading: Not decrypting\n\
6971
Writing: Not encrypting\n\
7072
Key instance counter: 0\n"s};
7173
std::ostringstream oss;
72-
print_device_status(oss, reinterpret_cast<const scsi::page_des&>(page), algorithms);
74+
print_device_status(oss, reinterpret_cast<const scsi::page_des&>(page),
75+
algorithms);
7376
REQUIRE(oss.str() == expected_output);
7477
}
7578

7679
TEST_CASE("SCSI get device encryption status output 2", "[output]")
7780
{
7881
std::map<std::uint8_t, std::string> algorithms {
79-
{ 1, "AES-256-GCM-128"s },
82+
{1, "AES-256-GCM-128"s},
8083
};
8184
const std::uint8_t page[] {
8285
0x00, 0x20, 0x00, 0x24, 0x42, 0x02, 0x02, 0x01, 0x00, 0x00,
@@ -91,14 +94,15 @@ Writing: Encrypting (AES-256-GCM-128)\n\
9194
Key instance counter: 1\n\
9295
Drive key desc. (U-KAD): Hello world!\n"s};
9396
std::ostringstream oss;
94-
print_device_status(oss, reinterpret_cast<const scsi::page_des&>(page), algorithms);
97+
print_device_status(oss, reinterpret_cast<const scsi::page_des&>(page),
98+
algorithms);
9599
REQUIRE(oss.str() == expected_output);
96100
}
97101

98102
TEST_CASE("Test SCSI get next block encryption status output 1", "[output]")
99103
{
100104
std::map<std::uint8_t, std::string> algorithms {
101-
{ 1, "AES-256-GCM-128"s },
105+
{1, "AES-256-GCM-128"s},
102106
};
103107
const std::uint8_t page[] {
104108
0x00, 0x21, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00,
@@ -107,14 +111,15 @@ TEST_CASE("Test SCSI get next block encryption status output 1", "[output]")
107111
const std::string expected_output {"\
108112
Current block status: Not encrypted\n"s};
109113
std::ostringstream oss;
110-
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page), algorithms);
114+
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page),
115+
algorithms);
111116
REQUIRE(oss.str() == expected_output);
112117
}
113118

114119
TEST_CASE("Test SCSI get next block encryption status output 2", "[output]")
115120
{
116121
std::map<std::uint8_t, std::string> algorithms {
117-
{ 1, "AES-256-GCM-128"s },
122+
{1, "AES-256-GCM-128"s},
118123
};
119124
const std::uint8_t page[] {
120125
0x00, 0x21, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -124,14 +129,15 @@ TEST_CASE("Test SCSI get next block encryption status output 2", "[output]")
124129
const std::string expected_output {"\
125130
Current block status: Encrypted and able to decrypt (AES-256-GCM-128)\n"s};
126131
std::ostringstream oss;
127-
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page), algorithms);
132+
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page),
133+
algorithms);
128134
REQUIRE(oss.str() == expected_output);
129135
}
130136

131137
TEST_CASE("Test SCSI get next block encryption status output 3", "[output]")
132138
{
133139
std::map<std::uint8_t, std::string> algorithms {
134-
{ 1, "AES-256-GCM-128"s },
140+
{1, "AES-256-GCM-128"s},
135141
};
136142
const std::uint8_t page[] {
137143
0x00, 0x21, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -142,7 +148,8 @@ TEST_CASE("Test SCSI get next block encryption status output 3", "[output]")
142148
Current block status: Encrypted, key missing or invalid (AES-256-GCM-128)\n\
143149
Current block key desc. (U-KAD): Hello world!\n"s};
144150
std::ostringstream oss;
145-
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page), algorithms);
151+
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page),
152+
algorithms);
146153
REQUIRE(oss.str() == expected_output);
147154
}
148155

tests/scsi.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,22 @@
55
#define CATCH_CONFIG_MAIN
66
#include "catch.hpp"
77

8-
#include "config.h"
9-
#include "scsiencrypt.h"
10-
8+
#include <cstddef>
9+
#include <cstdint>
10+
#include <cstring>
11+
#include <functional>
12+
#include <memory>
13+
#include <string>
14+
#include <vector>
15+
16+
#if HAVE_ARPA_INET_H
1117
#include <arpa/inet.h>
18+
#endif
19+
#if HAVE_NETINET_IN_H
20+
#include <netinet/in.h>
21+
#endif
22+
23+
#include "scsiencrypt.h"
1224

1325
using namespace std::literals::string_literals;
1426

0 commit comments

Comments
 (0)