Skip to content

Commit

Permalink
Merge pull request #15 from petiaccja/refactor
Browse files Browse the repository at this point in the history
large refactoring
  • Loading branch information
petiaccja authored Jan 8, 2024
2 parents f8990ce + 206ddd4 commit 0cd061e
Show file tree
Hide file tree
Showing 104 changed files with 4,346 additions and 4,219 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ IncludeBlocks: Regroup
IncludeCategories:
- Regex: '(<|")((C|c)atch.*)/'
Priority: 5
- Regex: '(<|")((Archive|Data|Specification|StorageDevice|TrustedPeripheral|Error|MockDevice).*)/'
- Regex: '(<|")((Archive|Messaging|Specification|StorageDevice|TrustedPeripheral|Error|MockDevice).*)/'
Priority: 2
- Regex: '<([[:alnum:].]|_|/)+\..*>'
Priority: 3
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compile_options("-fsanitize=memory")
add_link_options("-fsanitize=memory")
endif()
add_compile_options("-Wno-shift-count-overflow")
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
add_compile_options("/utf-8")
endif()
Expand Down
20 changes: 15 additions & 5 deletions src/EncryptedDevice/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
add_library(SEDManager)
add_library(EncryptedDevice)

target_compile_features(SEDManager PRIVATE cxx_std_20)
target_compile_features(EncryptedDevice PRIVATE cxx_std_20)

target_sources(SEDManager
target_sources(EncryptedDevice
PRIVATE
EncryptedDevice.cpp
EncryptedDevice.hpp
)

target_include_directories(SEDManager INTERFACE "${CMAKE_CURRENT_LIST_DIR}/..")
target_link_libraries(SEDManager TrustedPeripheral)
# TODO: ValueToJSON is only used by CLI and C API, it does not belong here.
target_sources(EncryptedDevice
PRIVATE
ValueToJSON.cpp
ValueToJSON.hpp
)

target_include_directories(EncryptedDevice INTERFACE "${CMAKE_CURRENT_LIST_DIR}/..")
target_link_libraries(EncryptedDevice TrustedPeripheral)

find_package(nlohmann_json)
target_link_libraries(EncryptedDevice nlohmann_json::nlohmann_json)
24 changes: 12 additions & 12 deletions src/EncryptedDevice/EncryptedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ const ModuleCollection& EncryptedDevice::GetModules() const {
}


asyncpp::task<void> EncryptedDevice::Login(Uid securityProvider) {
asyncpp::task<void> EncryptedDevice::Login(UID securityProvider) {
m_session = std::make_shared<Session>(co_await Session::Start(m_sessionManager, securityProvider));
}


asyncpp::task<void> EncryptedDevice::Authenticate(Uid authority, std::optional<std::span<const std::byte>> password) {
asyncpp::task<void> EncryptedDevice::Authenticate(UID authority, std::optional<std::span<const std::byte>> password) {
if (m_session) {
return m_session->base.Authenticate(authority, password);
}
Expand All @@ -83,7 +83,7 @@ asyncpp::task<void> EncryptedDevice::End() {
}


asyncpp::stream<Uid> EncryptedDevice::GetTableRows(Uid table) {
asyncpp::stream<UID> EncryptedDevice::GetTableRows(UID table) {
const auto desc = GetModules().FindTable(table);
if (!desc) {
throw std::invalid_argument("could not find table description");
Expand All @@ -92,9 +92,9 @@ asyncpp::stream<Uid> EncryptedDevice::GetTableRows(Uid table) {
co_yield *desc->singleRow;
}
else {
std::optional<Uid> lastUid = std::nullopt;
std::optional<UID> lastUid = std::nullopt;
while (const auto rowUid = co_await m_session->base.Next(table, lastUid)) {
if (*rowUid != Uid(0)) {
if (*rowUid != UID(0)) {
co_yield *rowUid;
}
lastUid = *rowUid;
Expand All @@ -103,7 +103,7 @@ asyncpp::stream<Uid> EncryptedDevice::GetTableRows(Uid table) {
}


asyncpp::stream<Value> EncryptedDevice::GetObjectColumns(Uid table, Uid object) {
asyncpp::stream<Value> EncryptedDevice::GetObjectColumns(UID table, UID object) {
const auto maybeTableDesc = GetModules().FindTable(table);
if (!maybeTableDesc) {
throw std::invalid_argument("could not find table description");
Expand All @@ -116,33 +116,33 @@ asyncpp::stream<Value> EncryptedDevice::GetObjectColumns(Uid table, Uid object)
}


asyncpp::task<Value> EncryptedDevice::GetObjectColumn(Uid object, uint32_t column) {
asyncpp::task<Value> EncryptedDevice::GetObjectColumn(UID object, uint32_t column) {
co_return co_await m_session->base.Get(object, column);
}


asyncpp::task<void> EncryptedDevice::SetObjectColumn(Uid object, uint32_t column, Value value) {
asyncpp::task<void> EncryptedDevice::SetObjectColumn(UID object, uint32_t column, Value value) {
co_await m_session->base.Set(object, column, value);
}


asyncpp::task<void> EncryptedDevice::GenMEK(Uid lockingRange) {
asyncpp::task<void> EncryptedDevice::GenMEK(UID lockingRange) {
co_await m_session->base.GenKey(lockingRange);
}


asyncpp::task<void> EncryptedDevice::GenPIN(Uid credentialObject, uint32_t length) {
asyncpp::task<void> EncryptedDevice::GenPIN(UID credentialObject, uint32_t length) {
co_await m_session->base.GenKey(credentialObject, std::nullopt, length);
}


asyncpp::task<void> EncryptedDevice::Revert(Uid securityProvider) {
asyncpp::task<void> EncryptedDevice::Revert(UID securityProvider) {
co_await m_session->opal.Revert(securityProvider);
co_await End();
}


asyncpp::task<void> EncryptedDevice::Activate(Uid securityProvider) {
asyncpp::task<void> EncryptedDevice::Activate(UID securityProvider) {
co_await m_session->opal.Activate(securityProvider);
}

Expand Down
22 changes: 11 additions & 11 deletions src/EncryptedDevice/EncryptedDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace sedmgr {

struct NamedObject {
Uid uid = 0;
UID uid = 0_uid;
std::optional<std::string> name = std::nullopt;
};

Expand All @@ -29,21 +29,21 @@ class EncryptedDevice {
const TPerDesc& GetDesc() const;
const ModuleCollection& GetModules() const;

asyncpp::task<void> Login(Uid securityProvider);
asyncpp::task<void> Authenticate(Uid authority, std::optional<std::span<const std::byte>> password = {});
asyncpp::task<void> Login(UID securityProvider);
asyncpp::task<void> Authenticate(UID authority, std::optional<std::span<const std::byte>> password = {});
asyncpp::task<void> StackReset();
asyncpp::task<void> Reset();
asyncpp::task<void> End();

asyncpp::stream<Uid> GetTableRows(Uid table);
asyncpp::stream<Value> GetObjectColumns(Uid table, Uid object);
asyncpp::task<Value> GetObjectColumn(Uid object, uint32_t column);
asyncpp::task<void> SetObjectColumn(Uid object, uint32_t column, Value value);
asyncpp::stream<UID> GetTableRows(UID table);
asyncpp::stream<Value> GetObjectColumns(UID table, UID object);
asyncpp::task<Value> GetObjectColumn(UID object, uint32_t column);
asyncpp::task<void> SetObjectColumn(UID object, uint32_t column, Value value);

asyncpp::task<void> GenMEK(Uid lockingRange);
asyncpp::task<void> GenPIN(Uid credentialObject, uint32_t length);
asyncpp::task<void> Revert(Uid securityProvider);
asyncpp::task<void> Activate(Uid securityProvider);
asyncpp::task<void> GenMEK(UID lockingRange);
asyncpp::task<void> GenPIN(UID credentialObject, uint32_t length);
asyncpp::task<void> Revert(UID securityProvider);
asyncpp::task<void> Activate(UID securityProvider);

private:
EncryptedDevice(std::shared_ptr<StorageDevice> device,
Expand Down
Loading

0 comments on commit 0cd061e

Please sign in to comment.