Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb178853e5 | |||
| 442f7fbb29 | |||
| 357f00d3e1 | |||
| 3560e321d7 | |||
| 5eb1aa2ece | |||
| e6c4f1fc98 | |||
| 26f5aa150c | |||
| 0608deb618 | |||
| f399c1b0a5 | |||
| 8a772f9fc5 | |||
| d50a82ad18 | |||
| f37271ec5b | |||
| 0126196ea8 | |||
| e0768cde3c | |||
| f9dbca34c7 | |||
| 6c5a12f339 | |||
| aafe22106e | |||
| 6c5b2a6ca9 | |||
| 4df35b5256 |
@@ -0,0 +1,6 @@
|
|||||||
|
CompileFlags:
|
||||||
|
CompilationDatabase: build/debug
|
||||||
|
|
||||||
|
Diagnostics:
|
||||||
|
UnusedIncludes: Strict
|
||||||
|
MissingIncludes: Strict
|
||||||
@@ -3,7 +3,7 @@ name: Chaos Ci
|
|||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-and-benchmark:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -17,27 +17,36 @@ jobs:
|
|||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y build-essential cmake valgrind lcov
|
sudo apt-get install -y build-essential cmake valgrind lcov
|
||||||
|
|
||||||
- name: Configure and build tests [Debug]
|
- name: Build tests
|
||||||
run: |
|
run: |
|
||||||
mkdir build-debug
|
mkdir build-debug
|
||||||
cmake -S . -B build-debug/ -D CMAKE_BUILD_TYPE=Debug
|
cmake -S . -B build-debug/ -D CMAKE_BUILD_TYPE=Debug
|
||||||
cmake --build build-debug/ -t ChaosTests
|
cmake --build build-debug/ -t ChaosTests
|
||||||
|
|
||||||
- name: Configure and build benchmarks [Release]
|
- name: Build tests with coverage
|
||||||
run: |
|
run: |
|
||||||
mkdir build-release
|
mkdir build-debug-coverage
|
||||||
cmake -S . -B build-release/ -D CMAKE_BUILD_TYPE=Release
|
cmake -S . -B build-debug-coverage/ -D CMAKE_BUILD_TYPE=Debug -D CHAOS_COVERAGE=ON
|
||||||
cmake --build build-release/ -t ChaosBenches
|
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
|
run: valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all ./build-debug/ChaosTests/ChaosTests
|
||||||
|
|
||||||
- name: Run benchmarks
|
- name: Run tests under ASan and UBSan
|
||||||
run: ./build-release/ChaosBenches/ChaosBenches
|
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
|
- name: Process coverage data
|
||||||
run: |
|
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/
|
genhtml lcovout -o coverage-report/
|
||||||
|
|
||||||
- name: Upload coverage report
|
- name: Upload coverage report
|
||||||
@@ -48,3 +57,26 @@ jobs:
|
|||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
include-hidden-files: true
|
include-hidden-files: true
|
||||||
retention-days: 10
|
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
|
#ifndef CHAOS_CIPHER_ARC4_ARC4CRYPT_HPP
|
||||||
#define CHAOS_CIPHER_ARC4_ARC4CRYPT_HPP
|
#define CHAOS_CIPHER_ARC4_ARC4CRYPT_HPP
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "Arc4Gen.hpp"
|
#include "Arc4Gen.hpp"
|
||||||
#include "Service/SeArray.hpp"
|
#include "Service/SeArray.hpp"
|
||||||
#include "Service/ChaosException.hpp"
|
#include "Service/ChaosException.hpp"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "Service/ChaosException.hpp"
|
#include "Service/ChaosException.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <iterator>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#include "Service/ChaosException.hpp"
|
#include "Service/ChaosException.hpp"
|
||||||
#include "Service/SeArray.hpp"
|
#include "Service/SeArray.hpp"
|
||||||
@@ -230,14 +233,14 @@ public:
|
|||||||
Inner_::RawKey Key_;
|
Inner_::RawKey Key_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DesEncryptor : public Encryptor<DesEncryptor>
|
class Encryptor : public Chaos::Cipher::Block::Encryptor<Encryptor>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Key = DesCrypt::Key;
|
using Key = DesCrypt::Key;
|
||||||
static constexpr size_t BlockSize = DesCrypt::BlockSize;
|
static constexpr size_t BlockSize = DesCrypt::BlockSize;
|
||||||
static constexpr size_t KeySize = DesCrypt::KeySize;
|
static constexpr size_t KeySize = DesCrypt::KeySize;
|
||||||
|
|
||||||
DesEncryptor(const Key & key)
|
Encryptor(const Key & key)
|
||||||
: Schedule_(Inner_::KeySchedule::Direction::Encrypt, key.Key_)
|
: Schedule_(Inner_::KeySchedule::Direction::Encrypt, key.Key_)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -275,14 +278,14 @@ public:
|
|||||||
Inner_::KeySchedule Schedule_;
|
Inner_::KeySchedule Schedule_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DesDecryptor : public Decryptor<DesDecryptor>
|
class Decryptor : public Chaos::Cipher::Block::Decryptor<Decryptor>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Key = DesCrypt::Key;
|
using Key = DesCrypt::Key;
|
||||||
static constexpr size_t BlockSize = DesCrypt::BlockSize;
|
static constexpr size_t BlockSize = DesCrypt::BlockSize;
|
||||||
static constexpr size_t KeySize = DesCrypt::KeySize;
|
static constexpr size_t KeySize = DesCrypt::KeySize;
|
||||||
|
|
||||||
DesDecryptor(const Key & key)
|
Decryptor(const Key & key)
|
||||||
: Schedule_(Inner_::KeySchedule::Direction::Decrypt, key.Key_)
|
: Schedule_(Inner_::KeySchedule::Direction::Decrypt, key.Key_)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#include "Hash.hpp"
|
#include "Hash.hpp"
|
||||||
#include "Hasher.hpp"
|
#include "Hasher.hpp"
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#include "Hash.hpp"
|
#include "Hash.hpp"
|
||||||
#include "Hasher.hpp"
|
#include "Hasher.hpp"
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <tuple>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "Hash.hpp"
|
#include "Hash.hpp"
|
||||||
#include "Hasher.hpp"
|
#include "Hasher.hpp"
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ public:
|
|||||||
Impl().Pad(begin, end);
|
Impl().Pad(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename InputIt>
|
||||||
|
auto ComputeUnpad(InputIt begin, InputIt end) const noexcept
|
||||||
|
{
|
||||||
|
return Impl().ComputeUnpad(begin, end);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Padder() = default;
|
Padder() = default;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#ifndef CHAOS_PADDING_PADDERPKCS7_HPP
|
#ifndef CHAOS_PADDING_PADDERPKCS7_HPP
|
||||||
#define CHAOS_PADDING_PADDERPKCS7_HPP
|
#define CHAOS_PADDING_PADDERPKCS7_HPP
|
||||||
|
|
||||||
|
#include <climits>
|
||||||
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "Padding/Padder.hpp"
|
#include "Padding/Padder.hpp"
|
||||||
#include "Service/ChaosException.hpp"
|
#include "Service/ChaosException.hpp"
|
||||||
@@ -19,6 +22,7 @@ public:
|
|||||||
{
|
{
|
||||||
auto dist = std::distance(begin, end);
|
auto dist = std::distance(begin, end);
|
||||||
|
|
||||||
|
// TODO: dist > 0
|
||||||
if (dist >= 0 && dist <= std::numeric_limits<uint8_t>::max())
|
if (dist >= 0 && dist <= std::numeric_limits<uint8_t>::max())
|
||||||
{
|
{
|
||||||
for (OutputIt it = begin; it != end; ++it)
|
for (OutputIt it = begin; it != end; ++it)
|
||||||
@@ -31,6 +35,114 @@ public:
|
|||||||
throw Service::ChaosException("PadderPkcs7::Pad(): invalid range");
|
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
|
} // namespace Chaos::Padding
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define CHAOS_SERVICE_CHAOSEXCEPTION_HPP
|
#define CHAOS_SERVICE_CHAOSEXCEPTION_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace Chaos::Service
|
namespace Chaos::Service
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
namespace Chaos::Service
|
namespace Chaos::Service
|
||||||
{
|
{
|
||||||
@@ -43,7 +44,7 @@ public:
|
|||||||
return Storage_.data();
|
return Storage_.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
const T * Begin() const noexcept
|
const T * Begin() const noexcept
|
||||||
{
|
{
|
||||||
return Storage_.data();
|
return Storage_.data();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,19 @@ target_include_directories(ChaosTests PRIVATE
|
|||||||
|
|
||||||
target_compile_options(ChaosTests PRIVATE -Wunused -Werror=unused)
|
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_compile_options(ChaosTests PRIVATE --coverage)
|
||||||
target_link_options(ChaosTests PRIVATE --coverage)
|
target_link_options(ChaosTests PRIVATE --coverage)
|
||||||
endif()
|
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)
|
include(GoogleTest)
|
||||||
|
|
||||||
gtest_discover_tests(ChaosTests)
|
gtest_discover_tests(ChaosTests)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "Cipher/Arc4/Arc4Crypt.hpp"
|
#include "Cipher/Arc4/Arc4Crypt.hpp"
|
||||||
#include "Service/ChaosException.hpp"
|
#include "Service/ChaosException.hpp"
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <array>
|
||||||
|
#include <iterator>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "Cipher/Arc4/Arc4Gen.hpp"
|
#include "Cipher/Arc4/Arc4Gen.hpp"
|
||||||
|
#include "Service/ChaosException.hpp"
|
||||||
|
|
||||||
using namespace Chaos::Cipher::Arc4;
|
using namespace Chaos::Cipher::Arc4;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "Cipher/Block/Des/DesCrypt.hpp"
|
#include "Cipher/Block/Des/DesCrypt.hpp"
|
||||||
#include "Cipher/Block/Encryptor.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::Des;
|
||||||
using namespace Chaos::Cipher::Block;
|
using namespace Chaos::Cipher::Block;
|
||||||
@@ -49,7 +54,7 @@ TEST(DesCryptTests, EncryptTest)
|
|||||||
std::array<uint8_t, DesCrypt::BlockSize> result = {};
|
std::array<uint8_t, DesCrypt::BlockSize> result = {};
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesEncryptor enc(desKey);
|
DesCrypt::Encryptor enc(desKey);
|
||||||
enc.EncryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
enc.EncryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -94,7 +99,7 @@ TEST(DesCryptTests, EncryptUInt64BlockTest)
|
|||||||
const std::array<uint8_t, DesCrypt::KeySize> & key) const
|
const std::array<uint8_t, DesCrypt::KeySize> & key) const
|
||||||
{
|
{
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesEncryptor enc(desKey);
|
DesCrypt::Encryptor enc(desKey);
|
||||||
|
|
||||||
return enc.EncryptBlock(data);
|
return enc.EncryptBlock(data);
|
||||||
}
|
}
|
||||||
@@ -141,7 +146,7 @@ TEST(DesCryptTests, EncryptShortDataTest)
|
|||||||
result.resize(DesCrypt::BlockSize, 0);
|
result.resize(DesCrypt::BlockSize, 0);
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesEncryptor enc(desKey);
|
DesCrypt::Encryptor enc(desKey);
|
||||||
enc.EncryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
enc.EncryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -175,7 +180,7 @@ TEST(DesCryptTests, EncryptLongDataTest)
|
|||||||
result.resize(DesCrypt::BlockSize, 0);
|
result.resize(DesCrypt::BlockSize, 0);
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesEncryptor enc(desKey);
|
DesCrypt::Encryptor enc(desKey);
|
||||||
enc.EncryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
enc.EncryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -208,7 +213,7 @@ TEST(DesCryptTests, DecryptTest)
|
|||||||
std::array<uint8_t, DesCrypt::BlockSize> result = {};
|
std::array<uint8_t, DesCrypt::BlockSize> result = {};
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesDecryptor dec(desKey);
|
DesCrypt::Decryptor dec(desKey);
|
||||||
dec.DecryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
dec.DecryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -253,7 +258,7 @@ TEST(DesCryptTests, DecryptUInt64BlockTest)
|
|||||||
const std::array<uint8_t, DesCrypt::KeySize> & key) const
|
const std::array<uint8_t, DesCrypt::KeySize> & key) const
|
||||||
{
|
{
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesDecryptor dec(desKey);
|
DesCrypt::Decryptor dec(desKey);
|
||||||
|
|
||||||
return dec.DecryptBlock(data);
|
return dec.DecryptBlock(data);
|
||||||
}
|
}
|
||||||
@@ -300,7 +305,7 @@ TEST(DesCryptTests, DecryptShortDataTest)
|
|||||||
result.resize(DesCrypt::BlockSize, 0);
|
result.resize(DesCrypt::BlockSize, 0);
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesDecryptor dec(desKey);
|
DesCrypt::Decryptor dec(desKey);
|
||||||
dec.DecryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
dec.DecryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -334,7 +339,7 @@ TEST(DesCryptTests, DecryptLongDataTest)
|
|||||||
result.resize(DesCrypt::BlockSize, 0);
|
result.resize(DesCrypt::BlockSize, 0);
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesDecryptor dec(desKey);
|
DesCrypt::Decryptor dec(desKey);
|
||||||
dec.DecryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
dec.DecryptBlock(result.begin(), result.end(), data.begin(), data.end());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -384,7 +389,7 @@ TEST(DesCryptTests, OutIteratorUsageEncryptTest)
|
|||||||
std::array<uint8_t, 11> expected = { 0x00, 0x00, 0x00, 0x42, 0x27, 0x88, 0xa6, 0x7b, 0x00, 0x00, 0x00 };
|
std::array<uint8_t, 11> expected = { 0x00, 0x00, 0x00, 0x42, 0x27, 0x88, 0xa6, 0x7b, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesEncryptor enc(desKey);
|
DesCrypt::Encryptor enc(desKey);
|
||||||
enc.EncryptBlock(fact.begin() + 3, fact.end() - 3, data.begin(), data.end());
|
enc.EncryptBlock(fact.begin() + 3, fact.end() - 3, data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_EQ(expected, fact);
|
ASSERT_EQ(expected, fact);
|
||||||
@@ -399,7 +404,7 @@ TEST(DesCryptTests, OutIteratorUsageEncryptTest)
|
|||||||
std::array<uint8_t, 12> expected = { 0x00, 0x00, 0x00, 0x00, 0x42, 0x27, 0x88, 0xa6, 0x00, 0x00, 0x00, 0x00 };
|
std::array<uint8_t, 12> expected = { 0x00, 0x00, 0x00, 0x00, 0x42, 0x27, 0x88, 0xa6, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesEncryptor enc(desKey);
|
DesCrypt::Encryptor enc(desKey);
|
||||||
enc.EncryptBlock(fact.begin() + 4, fact.end() - 4, data.begin(), data.end());
|
enc.EncryptBlock(fact.begin() + 4, fact.end() - 4, data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_EQ(expected, fact);
|
ASSERT_EQ(expected, fact);
|
||||||
@@ -413,7 +418,7 @@ TEST(DesCryptTests, OutIteratorUsageEncryptTest)
|
|||||||
std::array<uint8_t, 12> expected = {};
|
std::array<uint8_t, 12> expected = {};
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesEncryptor enc(desKey);
|
DesCrypt::Encryptor enc(desKey);
|
||||||
enc.EncryptBlock(fact.begin() + 3, fact.begin() + 3, data.begin(), data.end());
|
enc.EncryptBlock(fact.begin() + 3, fact.begin() + 3, data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_EQ(expected, fact);
|
ASSERT_EQ(expected, fact);
|
||||||
@@ -431,7 +436,7 @@ TEST(DesCryptTests, OutIteratorUsageDecryptTest)
|
|||||||
std::array<uint8_t, 11> expected = { 0x00, 0x00, 0x00, 0x45, 0x69, 0x71, 0x17, 0x13, 0x00, 0x00, 0x00 };
|
std::array<uint8_t, 11> expected = { 0x00, 0x00, 0x00, 0x45, 0x69, 0x71, 0x17, 0x13, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesDecryptor dec(desKey);
|
DesCrypt::Decryptor dec(desKey);
|
||||||
dec.DecryptBlock(fact.begin() + 3, fact.end() - 3, data.begin(), data.end());
|
dec.DecryptBlock(fact.begin() + 3, fact.end() - 3, data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_EQ(expected, fact);
|
ASSERT_EQ(expected, fact);
|
||||||
@@ -446,7 +451,7 @@ TEST(DesCryptTests, OutIteratorUsageDecryptTest)
|
|||||||
std::array<uint8_t, 12> expected = { 0x00, 0x00, 0x00, 0x00, 0x45, 0x69, 0x71, 0x17, 0x00, 0x00, 0x00, 0x00 };
|
std::array<uint8_t, 12> expected = { 0x00, 0x00, 0x00, 0x00, 0x45, 0x69, 0x71, 0x17, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesDecryptor dec(desKey);
|
DesCrypt::Decryptor dec(desKey);
|
||||||
dec.DecryptBlock(fact.begin() + 4, fact.end() - 4, data.begin(), data.end());
|
dec.DecryptBlock(fact.begin() + 4, fact.end() - 4, data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_EQ(expected, fact);
|
ASSERT_EQ(expected, fact);
|
||||||
@@ -460,7 +465,7 @@ TEST(DesCryptTests, OutIteratorUsageDecryptTest)
|
|||||||
std::array<uint8_t, 12> expected = {};
|
std::array<uint8_t, 12> expected = {};
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesDecryptor dec(desKey);
|
DesCrypt::Decryptor dec(desKey);
|
||||||
dec.DecryptBlock(fact.begin() + 3, fact.begin() + 3, data.begin(), data.end());
|
dec.DecryptBlock(fact.begin() + 3, fact.begin() + 3, data.begin(), data.end());
|
||||||
|
|
||||||
ASSERT_EQ(expected, fact);
|
ASSERT_EQ(expected, fact);
|
||||||
@@ -486,7 +491,7 @@ TEST(DesCryptTests, EncryptThroughBaseTest)
|
|||||||
std::vector<uint8_t> expected = { 0x85, 0xe8, 0x13, 0x54, 0x0f, 0x0a, 0xb4, 0x05 };
|
std::vector<uint8_t> expected = { 0x85, 0xe8, 0x13, 0x54, 0x0f, 0x0a, 0xb4, 0x05 };
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesEncryptor enc(desKey);
|
DesCrypt::Encryptor enc(desKey);
|
||||||
|
|
||||||
ASSERT_EQ(expected, EncryptThroughBase(enc, data.begin(), data.end()));
|
ASSERT_EQ(expected, EncryptThroughBase(enc, data.begin(), data.end()));
|
||||||
}
|
}
|
||||||
@@ -505,7 +510,7 @@ TEST(DesCryptTests, EncryptUInt64BlockThroughBaseTest)
|
|||||||
uint64_t expected = 0x85e813540f0ab405;
|
uint64_t expected = 0x85e813540f0ab405;
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesEncryptor enc(desKey);
|
DesCrypt::Encryptor enc(desKey);
|
||||||
|
|
||||||
ASSERT_EQ(expected, EncryptUInt64BlockThroughBase(enc, data));
|
ASSERT_EQ(expected, EncryptUInt64BlockThroughBase(enc, data));
|
||||||
}
|
}
|
||||||
@@ -529,7 +534,7 @@ TEST(DesCryptTests, DecryptThroughBaseTest)
|
|||||||
std::vector<uint8_t> expected = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
std::vector<uint8_t> expected = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesDecryptor dec(desKey);
|
DesCrypt::Decryptor dec(desKey);
|
||||||
|
|
||||||
ASSERT_EQ(expected, DecryptThroughBase(dec, data.begin(), data.end()));
|
ASSERT_EQ(expected, DecryptThroughBase(dec, data.begin(), data.end()));
|
||||||
}
|
}
|
||||||
@@ -548,7 +553,7 @@ TEST(DesCryptTests, DecryptUInt64BlockThroughBaseTest)
|
|||||||
uint64_t expected = 0x0123456789abcdef;
|
uint64_t expected = 0x0123456789abcdef;
|
||||||
|
|
||||||
DesCrypt::Key desKey(key.begin(), key.end());
|
DesCrypt::Key desKey(key.begin(), key.end());
|
||||||
DesCrypt::DesDecryptor dec(desKey);
|
DesCrypt::Decryptor dec(desKey);
|
||||||
|
|
||||||
ASSERT_EQ(expected, DecryptUInt64BlockThroughBase(dec, data));
|
ASSERT_EQ(expected, DecryptUInt64BlockThroughBase(dec, data));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "Hash/Md4.hpp"
|
#include "Hash/Md4.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "Hash/Md5.hpp"
|
#include "Hash/Md5.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "Hash/Sha1.hpp"
|
#include "Hash/Sha1.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#include "Hash/Md5.hpp"
|
#include "Hash/Md5.hpp"
|
||||||
#include "Hash/Sha1.hpp"
|
#include "Hash/Sha1.hpp"
|
||||||
#include "Mac/Hmac.hpp"
|
#include "Mac/Hmac.hpp"
|
||||||
|
#include "Service/ChaosException.hpp"
|
||||||
|
|
||||||
using namespace Chaos::Mac::Hmac;
|
using namespace Chaos::Mac::Hmac;
|
||||||
using namespace Chaos::Hash::Md5;
|
using namespace Chaos::Hash::Md5;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Padding/PadderIso7816.hpp"
|
#include "Padding/PadderIso7816.hpp"
|
||||||
|
#include "Padding/Padder.hpp"
|
||||||
|
|
||||||
using namespace Chaos::Padding;
|
using namespace Chaos::Padding;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Padding/PadderPkcs7.hpp"
|
#include "Padding/PadderPkcs7.hpp"
|
||||||
|
#include "Padding/Padder.hpp"
|
||||||
#include "Service/ChaosException.hpp"
|
#include "Service/ChaosException.hpp"
|
||||||
|
|
||||||
using namespace Chaos::Padding;
|
using namespace Chaos::Padding;
|
||||||
@@ -141,3 +142,210 @@ TEST(PadPkcs7Tests, PadThroughBaseTest)
|
|||||||
ASSERT_EQ(expected, fact);
|
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 <gtest/gtest.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#include "Service/SeArray.hpp"
|
#include "Service/SeArray.hpp"
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ TEST(SeArrayTests, InitializationTest)
|
|||||||
ASSERT_EQ(0, arr[i]);
|
ASSERT_EQ(0, arr[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SeArray<uint32_t, 333> arr;
|
SeArray<uint32_t, 333> arr;
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ TEST(SeArrayTests, EraseTest)
|
|||||||
ASSERT_EQ(0, arr[i]);
|
ASSERT_EQ(0, arr[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
SeArray<uint32_t, 333> arr;
|
SeArray<uint32_t, 333> arr;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user