| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title SdlsFileKeyManager.cpp | ||
| 3 | // \author lestarch-autobot | ||
| 4 | // \brief cpp file for SdlsFileKeyManager component implementation class | ||
| 5 | // ====================================================================== | ||
| 6 | |||
| 7 | #include "Svc/Ccsds/SdlsFileKeyManager/SdlsFileKeyManager.hpp" | ||
| 8 | #include <cstring> | ||
| 9 | #include "Fw/Types/Assert.hpp" | ||
| 10 | #include "Fw/Types/StringUtils.hpp" | ||
| 11 | #include "Os/File.hpp" | ||
| 12 | |||
| 13 | namespace Svc { | ||
| 14 | |||
| 15 | namespace Ccsds { | ||
| 16 | |||
| 17 | // ---------------------------------------------------------------------- | ||
| 18 | // Component construction, configuration, and destruction | ||
| 19 | // ---------------------------------------------------------------------- | ||
| 20 | |||
| 21 | 3 | SdlsFileKeyManager ::SdlsFileKeyManager(const char* const compName) | |
| 22 |
1/1✓ Branch 10 taken 3 times.
|
3 | : SdlsFileKeyManagerComponentBase(compName), m_path(), m_keySize(0), m_configured(false) {} |
| 23 | |||
| 24 | 6 | SdlsFileKeyManager ::~SdlsFileKeyManager() {} | |
| 25 | |||
| 26 | 3 | void SdlsFileKeyManager ::configure(const char* path, FwSizeType keySize) { | |
| 27 | 3 | FW_ASSERT(path != nullptr); | |
| 28 | 3 | FW_ASSERT(keySize > 0, static_cast<FwAssertArgType>(keySize)); | |
| 29 | 3 | FW_ASSERT(keySize <= SdlsCfg::MAX_SDLS_KEY_SIZE, static_cast<FwAssertArgType>(keySize)); | |
| 30 | // Reject paths that would be silently truncated by the string assignment | ||
| 31 | 3 | FW_ASSERT(Fw::StringUtils::string_length(path, this->m_path.getCapacity()) < this->m_path.getCapacity()); | |
| 32 | 3 | this->m_path = path; | |
| 33 | 3 | this->m_keySize = keySize; | |
| 34 | 3 | this->m_configured = true; | |
| 35 | 3 | } | |
| 36 | |||
| 37 | // ---------------------------------------------------------------------- | ||
| 38 | // Handler implementations for typed input ports | ||
| 39 | // ---------------------------------------------------------------------- | ||
| 40 | |||
| 41 | 3 | Svc::Ccsds::SdlsStatus SdlsFileKeyManager ::keyGet_handler(FwIndexType portNum, Svc::Ccsds::SdlsKeyBuffer& key) { | |
| 42 | 3 | FW_ASSERT(this->m_configured); | |
| 43 |
1/1✓ Branch 2 taken 3 times.
|
3 | Os::File file; |
| 44 |
1/1✓ Branch 8 taken 3 times.
|
3 | const Os::File::Status openStatus = file.open(this->m_path.toChar(), Os::File::OPEN_READ); |
| 45 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (openStatus != Os::File::OP_OK) { |
| 46 |
1/1✓ Branch 9 taken 1 times.
|
1 | this->log_WARNING_HI_KeyReadFailed(static_cast<I32>(openStatus), 0, this->m_keySize); |
| 47 | // Zeroize any stale key bytes so they cannot leak to the caller | ||
| 48 |
1/2✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
|
1 | (void)::memset(key.getBuffAddr(), 0, static_cast<size_t>(key.getCapacity())); |
| 49 |
1/1✓ Branch 5 taken 1 times.
|
1 | const Fw::SerializeStatus resetStatus = key.setBuffLen(0); |
| 50 | 1 | FW_ASSERT(resetStatus == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(resetStatus)); | |
| 51 |
1/1✓ Branch 1 taken 1 times.
|
1 | return SdlsStatus::KEY_ERROR; |
| 52 | } | ||
| 53 | 2 | FwSizeType readSize = this->m_keySize; | |
| 54 |
1/1✓ Branch 7 taken 2 times.
|
2 | const Os::File::Status readStatus = file.read(key.getBuffAddr(), readSize); |
| 55 |
3/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
|
2 | if ((readStatus != Os::File::OP_OK) || (readSize != this->m_keySize)) { |
| 56 |
1/1✓ Branch 9 taken 1 times.
|
1 | this->log_WARNING_HI_KeyReadFailed(static_cast<I32>(readStatus), readSize, this->m_keySize); |
| 57 | // Zeroize any partially-read key bytes so they cannot leak to the caller | ||
| 58 |
1/2✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
|
1 | (void)::memset(key.getBuffAddr(), 0, static_cast<size_t>(key.getCapacity())); |
| 59 |
1/1✓ Branch 5 taken 1 times.
|
1 | const Fw::SerializeStatus resetStatus = key.setBuffLen(0); |
| 60 | 1 | FW_ASSERT(resetStatus == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(resetStatus)); | |
| 61 |
1/1✓ Branch 1 taken 1 times.
|
1 | return SdlsStatus::KEY_ERROR; |
| 62 | } | ||
| 63 |
1/1✓ Branch 9 taken 1 times.
|
1 | const Fw::SerializeStatus setStatus = key.setBuffLen(this->m_keySize); |
| 64 | 1 | FW_ASSERT(setStatus == Fw::FW_SERIALIZE_OK, static_cast<FwAssertArgType>(setStatus)); | |
| 65 |
1/1✓ Branch 1 taken 1 times.
|
1 | return SdlsStatus::SUCCESS; |
| 66 | 3 | } | |
| 67 | |||
| 68 | } // namespace Ccsds | ||
| 69 | |||
| 70 | } // namespace Svc | ||
| 71 |