Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 617957ce4a | |||
| eb178853e5 | |||
| 442f7fbb29 | |||
| 357f00d3e1 | |||
| 3560e321d7 | |||
| 5eb1aa2ece | |||
| d38b77fab2 | |||
| 233c48bb3f | |||
| 1adec1115c | |||
| e6eb390469 | |||
| da34f9b499 | |||
| e6c4f1fc98 | |||
| 26f5aa150c | |||
| 0608deb618 | |||
| f399c1b0a5 | |||
| 8a772f9fc5 | |||
| d50a82ad18 | |||
| f37271ec5b | |||
| 0126196ea8 | |||
| e0768cde3c | |||
| f9dbca34c7 |
@@ -0,0 +1,6 @@
|
||||
CompileFlags:
|
||||
CompilationDatabase: build/debug
|
||||
|
||||
Diagnostics:
|
||||
UnusedIncludes: Strict
|
||||
MissingIncludes: Strict
|
||||
@@ -3,7 +3,7 @@ name: Chaos Ci
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test-and-benchmark:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
@@ -17,27 +17,36 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential cmake valgrind lcov
|
||||
|
||||
- name: Configure and build tests [Debug]
|
||||
- name: Build tests
|
||||
run: |
|
||||
mkdir build-debug
|
||||
cmake -S . -B build-debug/ -D CMAKE_BUILD_TYPE=Debug
|
||||
cmake --build build-debug/ -t ChaosTests
|
||||
|
||||
- name: Configure and build benchmarks [Release]
|
||||
- name: Build tests with coverage
|
||||
run: |
|
||||
mkdir build-release
|
||||
cmake -S . -B build-release/ -D CMAKE_BUILD_TYPE=Release
|
||||
cmake --build build-release/ -t ChaosBenches
|
||||
mkdir build-debug-coverage
|
||||
cmake -S . -B build-debug-coverage/ -D CMAKE_BUILD_TYPE=Debug -D CHAOS_COVERAGE=ON
|
||||
cmake --build build-debug-coverage/ -t ChaosTests
|
||||
|
||||
- name: Run tests
|
||||
- name: Build tests with ASan and UBSan
|
||||
run: |
|
||||
mkdir build-debug-asanubsan
|
||||
cmake -S . -B build-debug-asanubsan/ -D CMAKE_BUILD_TYPE=Debug -D CHAOS_ASANUBSAN=ON
|
||||
cmake --build build-debug-asanubsan/ -t ChaosTests
|
||||
|
||||
- name: Run tests under valgrind
|
||||
run: valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all ./build-debug/ChaosTests/ChaosTests
|
||||
|
||||
- name: Run benchmarks
|
||||
run: ./build-release/ChaosBenches/ChaosBenches
|
||||
- name: Run tests under ASan and UBSan
|
||||
run: ASAN_OPTIONS=verbosity=1 UBSAN_OPTIONS=verbosity=1 ./build-debug-asanubsan/ChaosTests/ChaosTests
|
||||
|
||||
- name: Run tests for coverage
|
||||
run: ./build-debug-coverage/ChaosTests/ChaosTests
|
||||
|
||||
- name: Process coverage data
|
||||
run: |
|
||||
lcov --exclude '*/usr/*' --exclude '*/_deps/*' --exclude '*/ChaosTests/*' -c -d build-debug/ -o lcovout
|
||||
lcov --exclude '*/usr/*' --exclude '*/_deps/*' --exclude '*/ChaosTests/*' -c -d build-debug-coverage/ -o lcovout
|
||||
genhtml lcovout -o coverage-report/
|
||||
|
||||
- name: Upload coverage report
|
||||
@@ -48,3 +57,26 @@ jobs:
|
||||
if-no-files-found: error
|
||||
include-hidden-files: true
|
||||
retention-days: 10
|
||||
|
||||
benchmark:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential cmake
|
||||
|
||||
- name: Build benchmarks
|
||||
run: |
|
||||
mkdir build-release
|
||||
cmake -S . -B build-release/ -D CMAKE_BUILD_TYPE=Release
|
||||
cmake --build build-release/ -t ChaosBenches
|
||||
|
||||
- name: Run benchmarks
|
||||
run: ./build-release/ChaosBenches/ChaosBenches
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef CHAOS_CIPHER_ARC4_ARC4CRYPT_HPP
|
||||
#define CHAOS_CIPHER_ARC4_ARC4CRYPT_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Arc4Gen.hpp"
|
||||
#include "Service/SeArray.hpp"
|
||||
#include "Service/ChaosException.hpp"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include "Service/ChaosException.hpp"
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <cstddef>
|
||||
|
||||
#include "Service/ChaosException.hpp"
|
||||
#include "Service/SeArray.hpp"
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <cstddef>
|
||||
|
||||
#include "Hash.hpp"
|
||||
#include "Hasher.hpp"
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <cstddef>
|
||||
|
||||
#include "Hash.hpp"
|
||||
#include "Hasher.hpp"
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include <tuple>
|
||||
#include <algorithm>
|
||||
|
||||
#include "Hash.hpp"
|
||||
#include "Hasher.hpp"
|
||||
|
||||
@@ -14,6 +14,12 @@ public:
|
||||
Impl().Pad(begin, end);
|
||||
}
|
||||
|
||||
template<typename InputIt>
|
||||
auto ComputeUnpad(InputIt begin, InputIt end) const noexcept
|
||||
{
|
||||
return Impl().ComputeUnpad(begin, end);
|
||||
}
|
||||
|
||||
protected:
|
||||
Padder() = default;
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#ifndef CHAOS_PADDING_PADDERPKCS7_HPP
|
||||
#define CHAOS_PADDING_PADDERPKCS7_HPP
|
||||
|
||||
#include <climits>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
#include "Padding/Padder.hpp"
|
||||
#include "Service/ChaosException.hpp"
|
||||
@@ -19,6 +22,7 @@ public:
|
||||
{
|
||||
auto dist = std::distance(begin, end);
|
||||
|
||||
// TODO: dist > 0
|
||||
if (dist >= 0 && dist <= std::numeric_limits<uint8_t>::max())
|
||||
{
|
||||
for (OutputIt it = begin; it != end; ++it)
|
||||
@@ -31,6 +35,114 @@ public:
|
||||
throw Service::ChaosException("PadderPkcs7::Pad(): invalid range");
|
||||
}
|
||||
}
|
||||
|
||||
struct ComputeUnpadResult
|
||||
{
|
||||
bool IsOkay_;
|
||||
uint8_t PadSize_;
|
||||
};
|
||||
|
||||
template<typename InputIt>
|
||||
static ComputeUnpadResult ComputeUnpad(InputIt begin, InputIt end) noexcept
|
||||
{
|
||||
if (begin == end)
|
||||
{
|
||||
return { .IsOkay_ = false, .PadSize_ = 0 };
|
||||
}
|
||||
|
||||
const uint8_t padSize = *std::prev(end);
|
||||
uint8_t isOkay = ~BlIsZero<uint8_t>(padSize);
|
||||
|
||||
size_t suffixSize = 0;
|
||||
InputIt it = end;
|
||||
while (it != begin && suffixSize < std::numeric_limits<uint8_t>::max())
|
||||
{
|
||||
--it;
|
||||
++suffixSize;
|
||||
|
||||
isOkay &= (BlEq<uint8_t>(*it, padSize) |
|
||||
BlGt<uint8_t, size_t>(suffixSize, padSize));
|
||||
}
|
||||
|
||||
isOkay &= BlGe<uint8_t, size_t>(suffixSize, padSize);
|
||||
|
||||
return
|
||||
{
|
||||
.IsOkay_ = static_cast<bool>(isOkay),
|
||||
.PadSize_ = BlSel<uint8_t>(isOkay, padSize, 0)
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename OutUInt, typename InUInt>
|
||||
static constexpr OutUInt BlMsb(InUInt in) noexcept
|
||||
{
|
||||
static_assert(std::is_unsigned_v<OutUInt> &&
|
||||
std::is_unsigned_v<InUInt>);
|
||||
|
||||
constexpr uint8_t shift = (sizeof(InUInt) * CHAR_BIT) - 1;
|
||||
return static_cast<OutUInt>(0) - (in >> shift);
|
||||
}
|
||||
|
||||
template<typename OutUInt, typename InUInt>
|
||||
static constexpr OutUInt BlLt(InUInt lhs, InUInt rhs) noexcept
|
||||
{
|
||||
static_assert(std::is_unsigned_v<OutUInt> &&
|
||||
std::is_unsigned_v<InUInt>);
|
||||
static_assert(sizeof(InUInt) <= sizeof(uint64_t));
|
||||
|
||||
const uint64_t lhsEx = lhs;
|
||||
const uint64_t rhsEx = rhs;
|
||||
|
||||
return BlMsb<OutUInt>(lhsEx ^ ((lhsEx ^ rhsEx) | ((lhsEx - rhsEx) ^ lhsEx)));
|
||||
}
|
||||
|
||||
template<typename OutUInt, typename InUInt>
|
||||
static constexpr OutUInt BlIsZero(InUInt in) noexcept
|
||||
{
|
||||
static_assert(std::is_unsigned_v<OutUInt> &&
|
||||
std::is_unsigned_v<InUInt>);
|
||||
static_assert(sizeof(InUInt) <= sizeof(uint64_t));
|
||||
|
||||
const uint64_t inEx = in;
|
||||
|
||||
return BlMsb<OutUInt>(~inEx & (inEx - 1U));
|
||||
}
|
||||
|
||||
template<typename OutUInt, typename InUInt>
|
||||
static constexpr OutUInt BlEq(InUInt lhs, InUInt rhs) noexcept
|
||||
{
|
||||
static_assert(std::is_unsigned_v<OutUInt> &&
|
||||
std::is_unsigned_v<InUInt>);
|
||||
|
||||
return BlIsZero<OutUInt, InUInt>(lhs ^ rhs);
|
||||
}
|
||||
|
||||
template<typename OutUInt, typename InUInt>
|
||||
static constexpr OutUInt BlGe(InUInt lhs, InUInt rhs) noexcept
|
||||
{
|
||||
static_assert(std::is_unsigned_v<OutUInt> &&
|
||||
std::is_unsigned_v<InUInt>);
|
||||
|
||||
return ~BlLt<OutUInt>(lhs, rhs);
|
||||
}
|
||||
|
||||
template<typename OutUInt, typename InUInt>
|
||||
static constexpr OutUInt BlGt(InUInt lhs, InUInt rhs) noexcept
|
||||
{
|
||||
static_assert(std::is_unsigned_v<OutUInt> &&
|
||||
std::is_unsigned_v<InUInt>);
|
||||
|
||||
return BlLt<OutUInt>(rhs, lhs);
|
||||
}
|
||||
|
||||
template<typename UInt>
|
||||
static constexpr UInt BlSel(UInt mask, UInt onTrue, UInt onFalse) noexcept
|
||||
{
|
||||
static_assert(std::is_unsigned_v<UInt>);
|
||||
|
||||
return (mask & onTrue) | (~mask & onFalse);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Chaos::Padding
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CHAOS_SERVICE_CHAOSEXCEPTION_HPP
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace Chaos::Service
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
|
||||
namespace Chaos::Service
|
||||
{
|
||||
|
||||
@@ -31,11 +31,19 @@ target_include_directories(ChaosTests PRIVATE
|
||||
|
||||
target_compile_options(ChaosTests PRIVATE -Wunused -Werror=unused)
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
option(CHAOS_COVERAGE "Enable coverage" OFF)
|
||||
option(CHAOS_ASANUBSAN "Enable ASan and UBSan" OFF)
|
||||
|
||||
if(CHAOS_COVERAGE)
|
||||
target_compile_options(ChaosTests PRIVATE --coverage)
|
||||
target_link_options(ChaosTests PRIVATE --coverage)
|
||||
endif()
|
||||
|
||||
if(CHAOS_ASANUBSAN)
|
||||
target_compile_options(ChaosTests PRIVATE -fsanitize=address,undefined -fno-sanitize-recover=all)
|
||||
target_link_options(ChaosTests PRIVATE -fsanitize=address,undefined -fno-sanitize-recover=all)
|
||||
endif()
|
||||
|
||||
include(GoogleTest)
|
||||
|
||||
gtest_discover_tests(ChaosTests)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "Cipher/Arc4/Arc4Crypt.hpp"
|
||||
#include "Service/ChaosException.hpp"
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <iterator>
|
||||
#include <cstring>
|
||||
|
||||
#include "Cipher/Arc4/Arc4Gen.hpp"
|
||||
#include "Service/ChaosException.hpp"
|
||||
|
||||
using namespace Chaos::Cipher::Arc4;
|
||||
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include "Cipher/Block/Des/DesCrypt.hpp"
|
||||
#include "Cipher/Block/Encryptor.hpp"
|
||||
#include "Cipher/Block/Decryptor.hpp"
|
||||
#include "Service/ChaosException.hpp"
|
||||
|
||||
using namespace Chaos::Cipher::Block::Des;
|
||||
using namespace Chaos::Cipher::Block;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "Hash/Md4.hpp"
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "Hash/Md5.hpp"
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "Hash/Sha1.hpp"
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include "Hash/Md5.hpp"
|
||||
#include "Hash/Sha1.hpp"
|
||||
#include "Mac/Hmac.hpp"
|
||||
#include "Service/ChaosException.hpp"
|
||||
|
||||
using namespace Chaos::Mac::Hmac;
|
||||
using namespace Chaos::Hash::Md5;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Padding/PadderIso7816.hpp"
|
||||
#include "Padding/Padder.hpp"
|
||||
|
||||
using namespace Chaos::Padding;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Padding/PadderPkcs7.hpp"
|
||||
#include "Padding/Padder.hpp"
|
||||
#include "Service/ChaosException.hpp"
|
||||
|
||||
using namespace Chaos::Padding;
|
||||
@@ -141,3 +142,210 @@ TEST(PadPkcs7Tests, PadThroughBaseTest)
|
||||
ASSERT_EQ(expected, fact);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PadPkcs7Tests, UnpadTest)
|
||||
{
|
||||
{
|
||||
std::array<uint8_t, 1> data = { 0x01 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(1, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 4> data = { 0xaa, 0xbb, 0x02, 0x02 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(2, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 10> data = { 0xaa, 0xbb, 0xcc, 0x07, 0x07,
|
||||
0x07, 0x07, 0x07, 0x07, 0x07 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(7, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 10> data = { 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5,
|
||||
0xa6, 0xa7, 0xa8, 0x01 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(1, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 10> data = { 0xa0, 0xa1, 0xa2, 0x07, 0x07, 0x07,
|
||||
0x07, 0x07, 0x07, 0x07 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(7, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 10> data = { 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
|
||||
0x0a, 0x0a, 0x0a, 0x0a };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(10, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 4> data = { 0x03, 0x03, 0x03, 0x03 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(3, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 200> data;
|
||||
data.fill(0x41);
|
||||
*std::prev(data.end()) = 1;
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(1, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 200> data;
|
||||
data.fill(0x41);
|
||||
std::fill(data.end() - 100, data.end(), 100);
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(100, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 255> data;
|
||||
data.fill(255);
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(255, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 381> data;
|
||||
data.fill(0x9a);
|
||||
std::fill(data.end() - 255, data.end(), 255);
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(255, result.PadSize_);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(PadPkcs7Tests, UnpadErrorTest)
|
||||
{
|
||||
{
|
||||
std::array<uint8_t, 0> data = { };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_FALSE(result.IsOkay_);
|
||||
ASSERT_EQ(0, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 1> data = { 0x00 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_FALSE(result.IsOkay_);
|
||||
ASSERT_EQ(0, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 5> data = { 0xa0, 0xa1, 0xa2, 0xa3, 0xff };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_FALSE(result.IsOkay_);
|
||||
ASSERT_EQ(0, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 5> data = { 0xa0, 0xa1, 0xa2, 0xa3, 0x06 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_FALSE(result.IsOkay_);
|
||||
ASSERT_EQ(0, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 5> data = { 0xa0, 0xa1, 0xa2, 0xa3, 0x05 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_FALSE(result.IsOkay_);
|
||||
ASSERT_EQ(0, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 5> data = { 0xa0, 0xa1, 0x03, 0x02, 0x03 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_FALSE(result.IsOkay_);
|
||||
ASSERT_EQ(0, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 1> data = { 0xff };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_FALSE(result.IsOkay_);
|
||||
ASSERT_EQ(0, result.PadSize_);
|
||||
}
|
||||
|
||||
{
|
||||
std::array<uint8_t, 2> data = { 0x03, 0x03 };
|
||||
|
||||
auto result = PadderPkcs7::ComputeUnpad(data.begin(), data.end());
|
||||
|
||||
ASSERT_FALSE(result.IsOkay_);
|
||||
ASSERT_EQ(0, result.PadSize_);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Impl, typename OutputIt>
|
||||
auto ComputeUnpadThroughBase(const Padder<Impl> & padder, OutputIt begin, OutputIt end)
|
||||
{
|
||||
return padder.ComputeUnpad(begin, end);
|
||||
}
|
||||
|
||||
TEST(PadPkcs7Tests, ComputeUnpadThroughBaseTest)
|
||||
{
|
||||
{
|
||||
std::array<uint8_t, 5> data = { 0x05, 0x05, 0x05, 0x05, 0x05 };
|
||||
|
||||
const PadderPkcs7 padder;
|
||||
auto result = ComputeUnpadThroughBase(padder, data.begin(), data.end());
|
||||
|
||||
ASSERT_TRUE(result.IsOkay_);
|
||||
ASSERT_EQ(5, result.PadSize_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdint>
|
||||
#include <iterator>
|
||||
#include <cstddef>
|
||||
|
||||
#include "Service/SeArray.hpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user