Skip to content

Commit

Permalink
clang-format and include-what-you-use run (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwilson committed May 2, 2023
1 parent daa541a commit 57591d0
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 37 deletions.
11 changes: 4 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# SPDX-FileCopyrightText: 2022 stenc authors
# SPDX-License-Identifier: GPL-2.0-or-later

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

AC_CONFIG_HEADERS([config.h])
AC_CHECK_HEADER([sys/types.h])
AC_CHECK_HEADER([sys/machine.h])
AC_CONFIG_HEADERS([config.h])]
AC_CHECK_HEADERS
AC_CHECK_HEADERS([arpa/inet.h netinet/in.h])
# Checks for programs
AC_PROG_CXX

# Checks for header files.
AC_PROG_EGREP

AC_MSG_CHECKING(whether to output raw SCSI messages)
AC_ARG_WITH([scsi-debug],
[AS_HELP_STRING([--with-scsi-debug],[enable scsi communication debug])],
Expand Down
21 changes: 14 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,38 @@ GNU General Public License for more details.
#include <config.h>

#include <algorithm>
#include <array>
#include <cctype>
#include <charconv>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <string>
#include <system_error>
#include <vector>

#include <errno.h>
#include <getopt.h>
#include <string.h>
#include <sys/mtio.h>
#include <sys/stat.h>
#include <syslog.h>
#include <termios.h>

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
Expand Down Expand Up @@ -383,7 +390,7 @@ int main(int argc, char **argv)
std::optional<scsi::encrypt_mode> enc_mode;
std::optional<scsi::decrypt_mode> dec_mode;
std::optional<std::uint8_t> algorithm_index;
std::vector<uint8_t> key;
std::vector<std::uint8_t> key;
std::string key_name;
scsi::sde_rdmc rdmc {};
scsi::kadf kad_format {};
Expand Down
2 changes: 1 addition & 1 deletion src/scsiencrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ GNU General Public License for more details.
#include <iostream>
#include <sstream>
#include <string>
#include <system_error>
#include <type_traits>

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

#if defined(OS_LINUX)
#include <scsi/scsi.h>
#include <scsi/sg.h>
constexpr unsigned int SCSI_TIMEOUT {5000u};
#elif defined(OS_FREEBSD)
Expand Down
14 changes: 7 additions & 7 deletions src/scsiencrypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ GNU General Public License for more details.
#ifndef _SCSIENC_H
#define _SCSIENC_H

#include <config.h>

#include <array>
#include <bitset>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#include <stdexcept>
#include <utility>

#if HAVE_ARPA_INET_H
#include <arpa/inet.h>

#ifdef HAVE_SYS_MACHINE_H
#include <sys/machine.h>
#endif

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif

namespace scsi {
Expand Down
31 changes: 19 additions & 12 deletions tests/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include <memory>
#include <cstdint>
#include <map>
#include <optional>
#include <sstream>
#include <string>
#include <vector>

#include "config.h"
#include "main.cpp"

using namespace std::literals::string_literals;
Expand Down Expand Up @@ -58,7 +60,7 @@ TEST_CASE("Test SCSI inquiry output", "[output]")
TEST_CASE("SCSI get device encryption status output 1", "[output]")
{
std::map<std::uint8_t, std::string> algorithms {
{ 1, "AES-256-GCM-128"s },
{1, "AES-256-GCM-128"s},
};
const std::uint8_t page[] {
0x00, 0x20, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -69,14 +71,15 @@ Reading: Not decrypting\n\
Writing: Not encrypting\n\
Key instance counter: 0\n"s};
std::ostringstream oss;
print_device_status(oss, reinterpret_cast<const scsi::page_des&>(page), algorithms);
print_device_status(oss, reinterpret_cast<const scsi::page_des&>(page),
algorithms);
REQUIRE(oss.str() == expected_output);
}

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

TEST_CASE("Test SCSI get next block encryption status output 1", "[output]")
{
std::map<std::uint8_t, std::string> algorithms {
{ 1, "AES-256-GCM-128"s },
{1, "AES-256-GCM-128"s},
};
const std::uint8_t page[] {
0x00, 0x21, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -107,14 +111,15 @@ TEST_CASE("Test SCSI get next block encryption status output 1", "[output]")
const std::string expected_output {"\
Current block status: Not encrypted\n"s};
std::ostringstream oss;
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page), algorithms);
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page),
algorithms);
REQUIRE(oss.str() == expected_output);
}

TEST_CASE("Test SCSI get next block encryption status output 2", "[output]")
{
std::map<std::uint8_t, std::string> algorithms {
{ 1, "AES-256-GCM-128"s },
{1, "AES-256-GCM-128"s},
};
const std::uint8_t page[] {
0x00, 0x21, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -124,14 +129,15 @@ TEST_CASE("Test SCSI get next block encryption status output 2", "[output]")
const std::string expected_output {"\
Current block status: Encrypted and able to decrypt (AES-256-GCM-128)\n"s};
std::ostringstream oss;
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page), algorithms);
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page),
algorithms);
REQUIRE(oss.str() == expected_output);
}

TEST_CASE("Test SCSI get next block encryption status output 3", "[output]")
{
std::map<std::uint8_t, std::string> algorithms {
{ 1, "AES-256-GCM-128"s },
{1, "AES-256-GCM-128"s},
};
const std::uint8_t page[] {
0x00, 0x21, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand All @@ -142,7 +148,8 @@ TEST_CASE("Test SCSI get next block encryption status output 3", "[output]")
Current block status: Encrypted, key missing or invalid (AES-256-GCM-128)\n\
Current block key desc. (U-KAD): Hello world!\n"s};
std::ostringstream oss;
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page), algorithms);
print_block_status(oss, reinterpret_cast<const scsi::page_nbes&>(page),
algorithms);
REQUIRE(oss.str() == expected_output);
}

Expand Down
18 changes: 15 additions & 3 deletions tests/scsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"

#include "config.h"
#include "scsiencrypt.h"

#include <cstddef>
#include <cstdint>
#include <cstring>
#include <functional>
#include <memory>
#include <string>
#include <vector>

#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif

#include "scsiencrypt.h"

using namespace std::literals::string_literals;

Expand Down

0 comments on commit 57591d0

Please sign in to comment.