Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ac5979c
Add unit tests for encryption functionality and integration tests
zombocoder Sep 6, 2025
c55d73c
Fix encryption password function calls in end-to-end tests
zombocoder Sep 6, 2025
b17eeef
Refactor decryption calls for improved readability in bfc_reader.c
zombocoder Sep 6, 2025
63bfac0
Fix file path references in CI tests for compression and encryption f…
zombocoder Sep 6, 2025
fe2893c
Fix file path in CI test for encryption with compression and enhance …
zombocoder Sep 6, 2025
f976cec
Update file paths in end-to-end encryption tests to use relative paths
zombocoder Sep 6, 2025
4c63404
Update file paths in encryption tests to use unique temporary filenames
zombocoder Sep 6, 2025
4e9afb8
Make temporary filenames unique in end-to-end encryption tests using …
zombocoder Sep 6, 2025
9785fe3
Add encryption status display in container info summary
zombocoder Sep 6, 2025
3e8025e
Update encryption test to use a larger test file for compression vali…
zombocoder Sep 6, 2025
6908af5
Fix formatting inconsistencies in encryption test files and update co…
zombocoder Sep 6, 2025
4371fb6
Silence warnings on cleanup errors in run_demo function
zombocoder Sep 6, 2025
658f447
Add tests for encryption detection and error handling in bfc_encrypt
zombocoder Sep 6, 2025
022d0f7
Add build_*/ to .gitignore to exclude additional build directories
zombocoder Sep 6, 2025
f091536
Add comprehensive tests for compression and encryption edge cases
zombocoder Sep 6, 2025
04953a9
Add tests for ZSTD streaming context and enhance compression recommen…
zombocoder Sep 6, 2025
512788e
Refactor whitespace in compression test cases for improved readability
zombocoder Sep 6, 2025
67f5ecd
Update coverage threshold to reflect current achievable coverage
zombocoder Sep 6, 2025
1cf4918
Update coverage threshold to 75 and add parameter validation tests fo…
zombocoder Sep 6, 2025
4d40ceb
Add comprehensive tests for encryption functions and edge cases
zombocoder Sep 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 68 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake clang-format clang-tidy libzstd-dev
sudo apt-get install -y build-essential cmake clang-format clang-tidy libzstd-dev libsodium-dev

- name: Install dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install clang-format zstd || true
brew install clang-format zstd libsodium || true
# cmake is already available on macOS runners

- name: Set up environment
Expand All @@ -50,7 +50,8 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_C_COMPILER=${{ matrix.cc }} \
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \
-DBFC_WITH_ZSTD=ON
-DBFC_WITH_ZSTD=ON \
-DBFC_WITH_SODIUM=ON

- name: Build
run: cmake --build build --config ${{ matrix.build_type }} -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)
Expand All @@ -76,16 +77,16 @@ jobs:
./build/bin/bfc info test.bfc
./build/bin/bfc verify test.bfc
./build/bin/bfc verify --deep test.bfc

# Test compression functionality
./build/bin/bfc create -c zstd test_compressed.bfc test_data/
./build/bin/bfc info test_compressed.bfc hello.txt
./build/bin/bfc info test_compressed.bfc test_data/hello.txt
./build/bin/bfc verify test_compressed.bfc

# Test different compression levels
./build/bin/bfc create -c zstd -l 1 test_fast.bfc test_data/
./build/bin/bfc create -c zstd -l 6 test_balanced.bfc test_data/
./build/bin/bfc info test_balanced.bfc hello.txt
./build/bin/bfc info test_balanced.bfc test_data/hello.txt

# Test extraction
mkdir -p extract_test
Expand All @@ -98,13 +99,61 @@ jobs:
[ -f subdir/nested.txt ] && echo "nested.txt extracted"

cd ..
rm -rf extract_test test.bfc test_data test_compressed.bfc test_fast.bfc test_balanced.bfc
rm -rf extract_test

# Test encryption functionality
echo "Testing encryption features..."
./build/bin/bfc create -e testpassword123 test_encrypted.bfc test_data/
./build/bin/bfc info test_encrypted.bfc
./build/bin/bfc info test_encrypted.bfc test_data/hello.txt | grep -i encrypt

# Test encrypted extraction
mkdir -p extract_encrypted
cd extract_encrypted
../build/bin/bfc extract -p testpassword123 ../test_encrypted.bfc

# Verify extracted files from encrypted container
[ -f hello.txt ] && echo "hello.txt extracted from encrypted container"
[ -f bye.txt ] && echo "bye.txt extracted from encrypted container"
[ -f subdir/nested.txt ] && echo "nested.txt extracted from encrypted container"

cd ..
rm -rf extract_encrypted

# Test wrong password failure
mkdir -p extract_fail_test
cd extract_fail_test
! ../build/bin/bfc extract -p wrongpassword ../test_encrypted.bfc && echo "Correctly failed with wrong password"
cd ..
rm -rf extract_fail_test

# Test key file encryption
echo -n "0123456789abcdef0123456789abcdef" > test.key
./build/bin/bfc create -k test.key test_keyfile.bfc test_data/
./build/bin/bfc info test_keyfile.bfc | grep -i encrypt

mkdir -p extract_keyfile
cd extract_keyfile
../build/bin/bfc extract -K ../test.key ../test_keyfile.bfc
[ -f hello.txt ] && echo "hello.txt extracted with key file"
cd ..
rm -rf extract_keyfile

# Test encryption with compression
echo "This is a larger test file with enough content to be compressed by zstd compression algorithm." > test_data/large.txt
./build/bin/bfc create -e testpass -c zstd test_enc_comp.bfc test_data/
./build/bin/bfc info test_enc_comp.bfc test_data/large.txt | grep -i encrypt
./build/bin/bfc info test_enc_comp.bfc test_data/large.txt | grep -i zstd

# Clean up
rm -rf test.bfc test_data test_compressed.bfc test_fast.bfc test_balanced.bfc
rm -rf test_encrypted.bfc test_keyfile.bfc test_enc_comp.bfc test.key

- name: Run benchmarks
run: |
cd build/benchmarks
./benchmark_crc32c

# Run compression benchmark (quick test)
timeout 60s ./benchmark_compress || gtimeout 60s ./benchmark_compress || echo "Compression benchmark completed or timed out"

Expand Down Expand Up @@ -136,7 +185,6 @@ jobs:

coverage:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

steps:
- name: Checkout code
Expand All @@ -145,14 +193,15 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake lcov bc libzstd-dev
sudo apt-get install -y build-essential cmake lcov bc libzstd-dev libsodium-dev

- name: Configure CMake with coverage
run: |
cmake -B build \
-DCMAKE_BUILD_TYPE=Debug \
-DBFC_COVERAGE=ON \
-DBFC_WITH_ZSTD=ON \
-DBFC_WITH_SODIUM=ON \
-DBFC_BUILD_BENCHMARKS=OFF \
-DCMAKE_C_FLAGS="--coverage -fprofile-arcs -ftest-coverage"

Expand All @@ -171,7 +220,6 @@ jobs:
--rc branch_coverage=1 \
--ignore-errors deprecated,unsupported,unused
lcov --remove coverage.info \
'/usr/*' \
'*/tests/*' \
--output-file coverage_filtered.info \
--rc branch_coverage=1 \
Expand All @@ -198,7 +246,7 @@ jobs:
echo "Functions: ${FUNC_COV}%"
echo "Branches: ${BRANCH_COV}%"

# Set coverage threshold (we achieved 78.5% so let's set to 75%)
# Set coverage threshold
THRESHOLD=75

# Check thresholds using bc for floating point comparison
Expand Down Expand Up @@ -237,10 +285,10 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake clang-tidy cppcheck libzstd-dev
sudo apt-get install -y build-essential cmake clang-tidy cppcheck libzstd-dev libsodium-dev

- name: Configure CMake
run: cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBFC_WITH_ZSTD=ON
run: cmake -B build -DCMAKE_BUILD_TYPE=Debug -DBFC_WITH_ZSTD=ON -DBFC_WITH_SODIUM=ON

- name: Run clang-tidy
run: |
Expand All @@ -259,7 +307,7 @@ jobs:

security:
runs-on: ubuntu-latest

# Add permissions for security scanning
permissions:
contents: read
Expand All @@ -278,11 +326,11 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake libzstd-dev
sudo apt-get install -y build-essential cmake libzstd-dev libsodium-dev

- name: Build for CodeQL
run: |
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBFC_WITH_ZSTD=ON -DBFC_BUILD_BENCHMARKS=OFF
cmake -B build -DCMAKE_BUILD_TYPE=Release -DBFC_WITH_ZSTD=ON -DBFC_WITH_SODIUM=ON -DBFC_BUILD_BENCHMARKS=OFF
cmake --build build

- name: Perform CodeQL Analysis
Expand All @@ -291,13 +339,13 @@ jobs:
documentation:
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

# Add permissions for GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Environment for GitHub Pages deployment
environment:
name: github-pages
Expand Down
35 changes: 28 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ jobs:
if: matrix.platform == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake clang rpm libzstd-dev
sudo apt-get install -y build-essential cmake clang rpm libzstd-dev libsodium-dev
# Install fpm for package creation
sudo gem install fpm

- name: Install dependencies (macOS)
if: matrix.platform == 'macos'
run: |
echo "cmake is already available on macOS runners"
# Install create-dmg for DMG creation and zstd for compression
brew install create-dmg zstd
# Install create-dmg for DMG creation, zstd for compression, and libsodium for encryption
brew install create-dmg zstd libsodium

- name: Build Release
env:
Expand All @@ -61,7 +61,8 @@ jobs:
-DCMAKE_C_COMPILER=${{ matrix.cc }} \
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DBFC_WITH_ZSTD=ON
-DBFC_WITH_ZSTD=ON \
-DBFC_WITH_SODIUM=ON

cmake --build build --config Release -j$(nproc 2>/dev/null || sysctl -n hw.ncpu)

Expand All @@ -75,14 +76,30 @@ jobs:
# Create test data
mkdir -p test_data
echo "Release test" > test_data/test.txt
echo "Sensitive data for encryption test" > test_data/secret.txt

# Test basic functionality
./build/bin/bfc create test.bfc test_data/
./build/bin/bfc list test.bfc
./build/bin/bfc verify test.bfc

# Test encryption functionality (password-based)
./build/bin/bfc create -e testpass encrypted.bfc test_data/
./build/bin/bfc list encrypted.bfc
./build/bin/bfc verify encrypted.bfc

# Test extraction with password
mkdir -p extracted
./build/bin/bfc extract -p testpass -C extracted encrypted.bfc
diff test_data/test.txt extracted/test.txt
diff test_data/secret.txt extracted/secret.txt

# Test encryption with compression
./build/bin/bfc create -e testpass -c zstd compressed_encrypted.bfc test_data/
./build/bin/bfc verify compressed_encrypted.bfc

# Clean up
rm -rf test_data test.bfc
rm -rf test_data test.bfc encrypted.bfc compressed_encrypted.bfc extracted

- name: Get version
id: get_version
Expand Down Expand Up @@ -164,23 +181,27 @@ jobs:

# Create DEB package
fpm -s dir -t deb -n bfc -v ${VERSION_NO_V} \
--description "Binary File Container - High-performance single-file container format" \
--description "Binary File Container - High-performance single-file container format with encryption and compression support" \
--url "https://github.com/zombocoder/bfc" \
--maintainer "zombocoder <zombocoder@users.noreply.github.com>" \
--license "Apache-2.0" \
--architecture ${{ matrix.arch }} \
--depends libc6 \
--depends libzstd1 \
--depends libsodium23 \
-C staging \
usr/bin usr/lib usr/include usr/share

# Create RPM package
fpm -s dir -t rpm -n bfc -v ${VERSION_NO_V} \
--description "Binary File Container - High-performance single-file container format" \
--description "Binary File Container - High-performance single-file container format with encryption and compression support" \
--url "https://github.com/zombocoder/bfc" \
--maintainer "zombocoder <zombocoder@users.noreply.github.com>" \
--license "Apache-2.0" \
--architecture ${{ matrix.arch }} \
--depends glibc \
--depends libzstd \
--depends libsodium \
-C staging \
usr/bin usr/lib usr/include usr/share

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Build directories
build/
build_*/
cmake-build-*/

# CMake files
Expand Down
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ set(CMAKE_C_EXTENSIONS OFF)

# Build options
option(BFC_WITH_FUSE "Build with FUSE support for mounting" OFF)
option(BFC_WITH_ZSTD "Build with Zstd compression support (reserved for v2)" OFF)
option(BFC_WITH_ZSTD "Build with Zstd compression support" OFF)
option(BFC_WITH_SODIUM "Build with libsodium encryption support" OFF)
option(BFC_COVERAGE "Enable coverage reporting" OFF)
option(BFC_BUILD_BENCHMARKS "Build benchmarks" ON)
option(BFC_BUILD_EXAMPLES "Build examples" ON)
Expand Down Expand Up @@ -57,6 +58,12 @@ if(BFC_WITH_ZSTD)
message(STATUS "ZSTD compression support enabled")
endif()

if(BFC_WITH_SODIUM)
find_package(PkgConfig REQUIRED)
pkg_check_modules(SODIUM REQUIRED libsodium)
message(STATUS "libsodium encryption support enabled")
endif()

# Include directories
include_directories(include)

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ configure:
cmake -B $(BUILD_DIR) \
-DCMAKE_BUILD_TYPE=$(CMAKE_BUILD_TYPE) \
-DBFC_WITH_ZSTD=ON
-DBFC_WITH_SODIUM=ON

# Build the project
build: configure
Expand Down
Loading
Loading