clang-format run (#77)
* pull updated template .clang-format with `clang-format-14 --style=llvm --dump-config`, move to base directory so it is shared between `src` and `tests` * tweak to match existing style a little (e.g. K&R style for function braces) * run on all sources
This commit is contained in:
@@ -1,118 +0,0 @@
|
||||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -2
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: MultiLine
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Attach
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakInheritanceList: BeforeColon
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: true
|
||||
ColumnLimit: 80
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
ContinuationIndentWidth: 4
|
||||
Cpp11BracedListStyle: true
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: true
|
||||
ForEachMacros:
|
||||
- foreach
|
||||
- Q_FOREACH
|
||||
- BOOST_FOREACH
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
|
||||
Priority: 2
|
||||
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
|
||||
Priority: 3
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 2
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 2
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakAssignment: 2
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakTemplateDeclaration: 10
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
ReflowComments: true
|
||||
SortIncludes: true
|
||||
SortUsingDeclarations: true
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: false
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp11
|
||||
TabWidth: 8
|
||||
UseTab: Never
|
||||
...
|
||||
|
||||
@@ -19,9 +19,11 @@ TEST_CASE("Test key_from_hex_chars", "[output]")
|
||||
REQUIRE(key_from_hex_chars("ab cd"s) == std::nullopt);
|
||||
REQUIRE(key_from_hex_chars("a"s) == std::vector<std::uint8_t> {0x0a});
|
||||
REQUIRE(key_from_hex_chars("0123456789abcdef"s) ==
|
||||
std::vector<std::uint8_t> {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef});
|
||||
std::vector<std::uint8_t> {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd,
|
||||
0xef});
|
||||
REQUIRE(key_from_hex_chars("0123456789ABCDEF"s) ==
|
||||
std::vector<std::uint8_t> {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef});
|
||||
std::vector<std::uint8_t> {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd,
|
||||
0xef});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,18 +35,14 @@ TEST_CASE("Test key_from_hex_chars", "[output]")
|
||||
TEST_CASE("Test SCSI inquiry output", "[output]")
|
||||
{
|
||||
const uint8_t response[] {
|
||||
0x01, 0x80, 0x00, 0x02, 0x5b, 0x00, 0x00, 0x02,
|
||||
0x41, 0x43, 0x4d, 0x45, 0x20, 0x20, 0x20, 0x20,
|
||||
0x55, 0x6c, 0x74, 0x72, 0x69, 0x75, 0x6d, 0x2d,
|
||||
0x31, 0x30, 0x30, 0x30, 0x20, 0x20, 0x20, 0x20,
|
||||
0x31, 0x32, 0x33, 0x34, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x80, 0x00, 0x02, 0x5b, 0x00, 0x00, 0x02, 0x41, 0x43, 0x4d, 0x45,
|
||||
0x20, 0x20, 0x20, 0x20, 0x55, 0x6c, 0x74, 0x72, 0x69, 0x75, 0x6d, 0x2d,
|
||||
0x31, 0x30, 0x30, 0x30, 0x20, 0x20, 0x20, 0x20, 0x31, 0x32, 0x33, 0x34,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
// note: fixed width strings in output
|
||||
const std::string expected_output {"\
|
||||
@@ -52,16 +50,16 @@ Vendor: ACME \n\
|
||||
Product ID: Ultrium-1000 \n\
|
||||
Product Revision: 1234\n"s};
|
||||
std::ostringstream oss;
|
||||
print_device_inquiry(oss, reinterpret_cast<const scsi::inquiry_data&>(response));
|
||||
print_device_inquiry(oss,
|
||||
reinterpret_cast<const scsi::inquiry_data&>(response));
|
||||
REQUIRE(oss.str() == expected_output);
|
||||
}
|
||||
|
||||
TEST_CASE("SCSI get device encryption status output 1", "[output]")
|
||||
{
|
||||
const uint8_t page[] {
|
||||
0x00, 0x20, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x20, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
const std::string expected_output {"\
|
||||
Drive Encryption: off\n\
|
||||
@@ -77,11 +75,10 @@ Key Instance Counter: 0\n"s};
|
||||
TEST_CASE("SCSI get device encryption status output 2", "[output]")
|
||||
{
|
||||
const uint8_t page[] {
|
||||
0x00, 0x20, 0x00, 0x24, 0x42, 0x02, 0x02, 0x01,
|
||||
0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x0c, 0x48, 0x65, 0x6c, 0x6c,
|
||||
0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
|
||||
0x00, 0x20, 0x00, 0x24, 0x42, 0x02, 0x02, 0x01, 0x00, 0x00,
|
||||
0x00, 0x01, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x48, 0x65,
|
||||
0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
|
||||
};
|
||||
const std::string expected_output {"\
|
||||
Drive Encryption: on\n\
|
||||
@@ -99,8 +96,8 @@ Drive Key Desc.(uKAD): Hello world!\n"s};
|
||||
TEST_CASE("Test SCSI get next block encryption status output 1", "[output]")
|
||||
{
|
||||
const uint8_t page[] {
|
||||
0x00, 0x21, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x00, 0x21, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
};
|
||||
const std::string expected_output {"\
|
||||
Volume Encryption: Not encrypted\n"s};
|
||||
@@ -112,10 +109,9 @@ Volume Encryption: Not encrypted\n"s};
|
||||
TEST_CASE("Test SCSI get next block encryption status output 2", "[output]")
|
||||
{
|
||||
const uint8_t page[] {
|
||||
0x00, 0x21, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00,
|
||||
0x00, 0x01, 0x00, 0x0c, 0x48, 0x65, 0x6c, 0x6c,
|
||||
0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
|
||||
0x00, 0x21, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0x48, 0x65,
|
||||
0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
|
||||
};
|
||||
const std::string expected_output {"\
|
||||
Volume Encryption: Encrypted and able to decrypt\n\
|
||||
@@ -128,15 +124,12 @@ Volume Algorithm: 1\n"s};
|
||||
TEST_CASE("Test SCSI get data encryption capabilities output", "[output]")
|
||||
{
|
||||
const std::uint8_t page[] {
|
||||
0x00, 0x10, 0x00, 0x3c, 0x09, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x14,
|
||||
0x8a, 0x8c, 0x00, 0x20, 0x00, 0x3c, 0x00, 0x20,
|
||||
0xed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x00, 0x14, 0x02, 0x00, 0x00, 0x14,
|
||||
0x8a, 0x8f, 0x00, 0x20, 0x00, 0x3c, 0x00, 0x20,
|
||||
0xd9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x00, 0x10,
|
||||
0x00, 0x10, 0x00, 0x3c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x14,
|
||||
0x8a, 0x8c, 0x00, 0x20, 0x00, 0x3c, 0x00, 0x20, 0xed, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x14, 0x02, 0x00, 0x00, 0x14,
|
||||
0x8a, 0x8f, 0x00, 0x20, 0x00, 0x3c, 0x00, 0x20, 0xd9, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10,
|
||||
};
|
||||
const std::string expected_output {"\
|
||||
Supported algorithms:\n\
|
||||
|
||||
104
tests/scsi.cpp
104
tests/scsi.cpp
@@ -18,6 +18,7 @@ using namespace std::literals::string_literals;
|
||||
TEST_CASE("Disable encryption command", "[scsi]")
|
||||
{
|
||||
const std::uint8_t expected[] {
|
||||
// clang-format off
|
||||
0x00, 0x10, // page code
|
||||
0x00, 0x10, // page length
|
||||
0x40, // scope
|
||||
@@ -28,14 +29,15 @@ TEST_CASE("Disable encryption command", "[scsi]")
|
||||
0x00, // key format
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved [8]
|
||||
0x00, 0x00 // key length
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
std::vector<std::uint8_t> key {};
|
||||
std::string key_name {};
|
||||
|
||||
auto page_buffer {scsi::make_sde(scsi::encrypt_mode::off, scsi::decrypt_mode::off,
|
||||
1u, key, key_name, scsi::sde_rdmc::algorithm_default,
|
||||
false)};
|
||||
auto page_buffer {scsi::make_sde(scsi::encrypt_mode::off,
|
||||
scsi::decrypt_mode::off, 1u, key, key_name,
|
||||
scsi::sde_rdmc::algorithm_default, false)};
|
||||
auto& page {reinterpret_cast<const scsi::page_sde&>(*page_buffer.get())};
|
||||
REQUIRE(sizeof(scsi::page_header) + ntohs(page.length) == sizeof(expected));
|
||||
REQUIRE(std::memcmp(&page, expected, sizeof(expected)) == 0);
|
||||
@@ -44,6 +46,7 @@ TEST_CASE("Disable encryption command", "[scsi]")
|
||||
TEST_CASE("Enable encryption command", "[scsi]")
|
||||
{
|
||||
const std::uint8_t expected[] {
|
||||
// clang-format off
|
||||
0x00, 0x10, // page code
|
||||
0x00, 0x30, // page length
|
||||
0x40, // scope
|
||||
@@ -58,19 +61,19 @@ TEST_CASE("Enable encryption command", "[scsi]")
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
std::vector<std::uint8_t> key {
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA,
|
||||
0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
|
||||
0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
};
|
||||
std::string key_name {};
|
||||
|
||||
auto page_buffer {scsi::make_sde(scsi::encrypt_mode::on, scsi::decrypt_mode::on,
|
||||
1u, key, key_name, scsi::sde_rdmc::algorithm_default,
|
||||
false)};
|
||||
auto page_buffer {scsi::make_sde(scsi::encrypt_mode::on,
|
||||
scsi::decrypt_mode::on, 1u, key, key_name,
|
||||
scsi::sde_rdmc::algorithm_default, false)};
|
||||
auto& page {reinterpret_cast<const scsi::page_sde&>(*page_buffer.get())};
|
||||
REQUIRE(sizeof(scsi::page_header) + ntohs(page.length) == sizeof(expected));
|
||||
REQUIRE(std::memcmp(&page, expected, sizeof(expected)) == 0);
|
||||
@@ -79,6 +82,7 @@ TEST_CASE("Enable encryption command", "[scsi]")
|
||||
TEST_CASE("Enable encryption command with options", "[scsi]")
|
||||
{
|
||||
const std::uint8_t expected[] {
|
||||
// clang-format off
|
||||
0x00, 0x10, // page code
|
||||
0x00, 0x30, // page length
|
||||
0x40, // scope
|
||||
@@ -93,19 +97,19 @@ TEST_CASE("Enable encryption command with options", "[scsi]")
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
std::vector<std::uint8_t> key {
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA,
|
||||
0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
|
||||
0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
};
|
||||
std::string key_name {};
|
||||
|
||||
auto page_buffer {scsi::make_sde(scsi::encrypt_mode::on, scsi::decrypt_mode::on,
|
||||
1u, key, key_name, scsi::sde_rdmc::enabled,
|
||||
true)};
|
||||
auto page_buffer {scsi::make_sde(scsi::encrypt_mode::on,
|
||||
scsi::decrypt_mode::on, 1u, key, key_name,
|
||||
scsi::sde_rdmc::enabled, true)};
|
||||
auto& page {reinterpret_cast<const scsi::page_sde&>(*page_buffer.get())};
|
||||
REQUIRE(sizeof(scsi::page_header) + ntohs(page.length) == sizeof(expected));
|
||||
REQUIRE(std::memcmp(&page, expected, sizeof(expected)) == 0);
|
||||
@@ -114,6 +118,7 @@ TEST_CASE("Enable encryption command with options", "[scsi]")
|
||||
TEST_CASE("Enable encryption command with key name", "[scsi]")
|
||||
{
|
||||
const std::uint8_t expected[] {
|
||||
// clang-format off
|
||||
0x00, 0x10, // page code
|
||||
0x00, 0x40, // page length
|
||||
0x40, // scope
|
||||
@@ -133,20 +138,19 @@ TEST_CASE("Enable encryption command with key name", "[scsi]")
|
||||
0x00, // authenticated
|
||||
0x00, 0x0c, // length
|
||||
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
std::vector<std::uint8_t> key {
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
|
||||
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA,
|
||||
0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
|
||||
0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
|
||||
};
|
||||
std::string key_name {"Hello world!"s};
|
||||
|
||||
auto page_buffer {scsi::make_sde(scsi::encrypt_mode::on, scsi::decrypt_mode::on,
|
||||
1u, key, key_name,
|
||||
scsi::sde_rdmc::algorithm_default,
|
||||
false)};
|
||||
auto page_buffer {scsi::make_sde(scsi::encrypt_mode::on,
|
||||
scsi::decrypt_mode::on, 1u, key, key_name,
|
||||
scsi::sde_rdmc::algorithm_default, false)};
|
||||
auto& page {reinterpret_cast<const scsi::page_sde&>(*page_buffer.get())};
|
||||
REQUIRE(sizeof(scsi::page_header) + ntohs(page.length) == sizeof(expected));
|
||||
REQUIRE(std::memcmp(&page, expected, sizeof(expected)) == 0);
|
||||
@@ -163,6 +167,7 @@ TEST_CASE("Enable encryption command with key name", "[scsi]")
|
||||
TEST_CASE("Interpret device encryption status page", "[scsi]")
|
||||
{
|
||||
const std::uint8_t buffer[] {
|
||||
// clang-format off
|
||||
0x00, 0x20, // page code
|
||||
0x00, 0x24, // length
|
||||
0x42, // nexus = 2h, key scope = 2h
|
||||
@@ -180,21 +185,22 @@ TEST_CASE("Interpret device encryption status page", "[scsi]")
|
||||
0x01, // authenticated
|
||||
0x00, 0x0c, // length
|
||||
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
auto& page_des {reinterpret_cast<const scsi::page_des&>(buffer)};
|
||||
REQUIRE(ntohs(page_des.page_code) == 0x20u);
|
||||
REQUIRE(ntohs(page_des.length) == 36u);
|
||||
REQUIRE((page_des.scope & scsi::page_des::scope_it_nexus_mask)
|
||||
>> scsi::page_des::scope_it_nexus_pos == std::byte {2u});
|
||||
REQUIRE((page_des.scope & scsi::page_des::scope_encryption_mask)
|
||||
>> scsi::page_des::scope_encryption_pos == std::byte {2u});
|
||||
REQUIRE((page_des.scope & scsi::page_des::scope_it_nexus_mask) ==
|
||||
std::byte {2u} << scsi::page_des::scope_it_nexus_pos);
|
||||
REQUIRE((page_des.scope & scsi::page_des::scope_encryption_mask) ==
|
||||
std::byte {2u} << scsi::page_des::scope_encryption_pos);
|
||||
REQUIRE(page_des.encryption_mode == scsi::encrypt_mode::on);
|
||||
REQUIRE(page_des.decryption_mode == scsi::decrypt_mode::on);
|
||||
REQUIRE(page_des.algorithm_index == 1u);
|
||||
REQUIRE(ntohl(page_des.key_instance_counter) == 1u);
|
||||
REQUIRE((page_des.flags & scsi::page_des::flags_parameters_control_mask)
|
||||
== std::byte {1u} << scsi::page_des::flags_parameters_control_pos);
|
||||
REQUIRE((page_des.flags & scsi::page_des::flags_parameters_control_mask) ==
|
||||
std::byte {1u} << scsi::page_des::flags_parameters_control_pos);
|
||||
REQUIRE((page_des.flags & scsi::page_des::flags_vcelb_mask) ==
|
||||
scsi::page_des::flags_vcelb_mask);
|
||||
REQUIRE((page_des.flags & scsi::page_des::flags_ceems_mask) == std::byte {});
|
||||
@@ -202,14 +208,17 @@ TEST_CASE("Interpret device encryption status page", "[scsi]")
|
||||
|
||||
auto kads = read_page_kads(page_des);
|
||||
REQUIRE(kads.size() == 1u);
|
||||
REQUIRE((kads[0]->flags & scsi::kad::flags_authenticated_mask) == std::byte {1u});
|
||||
REQUIRE((kads[0]->flags & scsi::kad::flags_authenticated_mask) ==
|
||||
std::byte {1u});
|
||||
REQUIRE(ntohs(kads[0]->length) == std::strlen("Hello world!"));
|
||||
REQUIRE(std::memcmp(kads[0]->descriptor, "Hello world!", ntohs(kads[0]->length)) == 0);
|
||||
REQUIRE(std::memcmp(kads[0]->descriptor, "Hello world!",
|
||||
ntohs(kads[0]->length)) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Interpret next block encryption status page", "[scsi]")
|
||||
{
|
||||
const std::uint8_t buffer[] {
|
||||
// clang-format off
|
||||
0x00, 0x21, // page code
|
||||
0x00, 0x1c, // length
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
@@ -222,28 +231,34 @@ TEST_CASE("Interpret next block encryption status page", "[scsi]")
|
||||
0x01, // authenticated
|
||||
0x00, 0x0c, // length
|
||||
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21,
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
auto& page_nbes {reinterpret_cast<const scsi::page_nbes&>(buffer)};
|
||||
REQUIRE(ntohs(page_nbes.page_code) == 0x21u);
|
||||
REQUIRE(ntohs(page_nbes.length) == 28u);
|
||||
REQUIRE((page_nbes.status & scsi::page_nbes::status_compression_mask) == std::byte {});
|
||||
REQUIRE((page_nbes.status & scsi::page_nbes::status_encryption_mask)
|
||||
== std::byte {5u} << scsi::page_nbes::status_encryption_pos);
|
||||
REQUIRE((page_nbes.status & scsi::page_nbes::status_compression_mask) ==
|
||||
std::byte {});
|
||||
REQUIRE((page_nbes.status & scsi::page_nbes::status_encryption_mask) ==
|
||||
std::byte {5u} << scsi::page_nbes::status_encryption_pos);
|
||||
REQUIRE(page_nbes.algorithm_index == 1u);
|
||||
REQUIRE((page_nbes.flags & scsi::page_nbes::flags_emes_mask) == std::byte {});
|
||||
REQUIRE((page_nbes.flags & scsi::page_nbes::flags_rdmds_mask) == std::byte {});
|
||||
REQUIRE((page_nbes.flags & scsi::page_nbes::flags_rdmds_mask) ==
|
||||
std::byte {});
|
||||
|
||||
auto kads = read_page_kads(page_nbes);
|
||||
REQUIRE(kads.size() == 1u);
|
||||
REQUIRE((kads[0]->flags & scsi::kad::flags_authenticated_mask) == std::byte {1u});
|
||||
REQUIRE((kads[0]->flags & scsi::kad::flags_authenticated_mask) ==
|
||||
std::byte {1u});
|
||||
REQUIRE(ntohs(kads[0]->length) == std::strlen("Hello world!"));
|
||||
REQUIRE(std::memcmp(kads[0]->descriptor, "Hello world!", ntohs(kads[0]->length)) == 0);
|
||||
REQUIRE(std::memcmp(kads[0]->descriptor, "Hello world!",
|
||||
ntohs(kads[0]->length)) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Interpret data encryption capabilties page", "[scsi]")
|
||||
{
|
||||
const std::uint8_t buffer[] {
|
||||
// clang-format off
|
||||
0x00, 0x10, // page code
|
||||
0x00, 0x3c, // length
|
||||
0x09, // EXTDECC and CFG_P
|
||||
@@ -279,9 +294,10 @@ TEST_CASE("Interpret data encryption capabilties page", "[scsi]")
|
||||
0x00, 0x00,
|
||||
0x00, 0x00,
|
||||
0x00, 0x01, 0x00, 0x10,
|
||||
// clang-format on
|
||||
};
|
||||
static_assert(sizeof(buffer) == sizeof(scsi::page_dec) +
|
||||
2 * sizeof(scsi::algorithm_descriptor));
|
||||
2 * sizeof(scsi::algorithm_descriptor));
|
||||
|
||||
auto& page_dec {reinterpret_cast<const scsi::page_dec&>(buffer)};
|
||||
REQUIRE(ntohs(page_dec.page_code) == 0x10u);
|
||||
@@ -337,8 +353,8 @@ TEST_CASE("Interpret data encryption capabilties page", "[scsi]")
|
||||
REQUIRE((algo1.flags3 & scsi::algorithm_descriptor::flags3_earem_mask) ==
|
||||
scsi::algorithm_descriptor::flags3_earem_mask);
|
||||
|
||||
REQUIRE((algo1.maximum_eedk_count & scsi::algorithm_descriptor::maximum_eedk_count_mask) ==
|
||||
0u);
|
||||
REQUIRE((algo1.maximum_eedk_count &
|
||||
scsi::algorithm_descriptor::maximum_eedk_count_mask) == 0u);
|
||||
REQUIRE(ntohs(algo1.msdk_count) == 0u);
|
||||
REQUIRE(ntohs(algo1.maximum_eedk_size) == 0u);
|
||||
REQUIRE(ntohl(algo1.security_algorithm_code) == 0x00010014u);
|
||||
@@ -385,8 +401,8 @@ TEST_CASE("Interpret data encryption capabilties page", "[scsi]")
|
||||
REQUIRE((algo2.flags3 & scsi::algorithm_descriptor::flags3_earem_mask) ==
|
||||
scsi::algorithm_descriptor::flags3_earem_mask);
|
||||
|
||||
REQUIRE((algo2.maximum_eedk_count & scsi::algorithm_descriptor::maximum_eedk_count_mask) ==
|
||||
0u);
|
||||
REQUIRE((algo2.maximum_eedk_count &
|
||||
scsi::algorithm_descriptor::maximum_eedk_count_mask) == 0u);
|
||||
REQUIRE(ntohs(algo2.msdk_count) == 0u);
|
||||
REQUIRE(ntohs(algo2.maximum_eedk_size) == 0u);
|
||||
REQUIRE(ntohl(algo2.security_algorithm_code) == 0x00010010u);
|
||||
|
||||
Reference in New Issue
Block a user