Skip to content

Commit d28c0b4

Browse files
committed
fix: code coverage
1 parent 1834119 commit d28c0b4

File tree

8 files changed

+705
-29
lines changed

8 files changed

+705
-29
lines changed

.github/workflows/rust.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,6 @@ jobs:
5454
- name: Run fmt
5555
run: cargo fmt --verbose --all -- --check
5656

57-
coverage:
58-
runs-on: ubuntu-latest
59-
container:
60-
image: xd009642/tarpaulin
61-
options: --security-opt seccomp=unconfined
62-
steps:
63-
- name: Checkout repository
64-
uses: actions/checkout@v3
65-
66-
- name: Generate code coverage
67-
run: |
68-
cargo tarpaulin --all-targets --all-features --lib --timeout 180 --out xml
69-
70-
- name: Upload to codecov.io
71-
uses: codecov/codecov-action@v2
72-
with:
73-
fail_ci_if_error: true
74-
7557
x86_64-unknown-none:
7658
runs-on: ubuntu-latest
7759

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Homomorphic Encryption Scheme in Rust
22

3-
[![Coverage Status](https://coveralls.io/repos/github/mathisbot/homomorph-rust/badge.svg)](https://coveralls.io/github/mathisbot/homomorph-rust)
3+
[Code coverage](tarpaulin-report.html)
44

55
This repository contains a Rust implementation of an homomorphic encryption scheme.
66

check.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Run-Command "cargo run --example new_struct"
4242
Run-Command "cargo clippy --all-targets --all-features -- -D warnings --no-deps"
4343
Run-Command "cargo test --release -- --ignored"
4444
Run-Command "cargo fmt"
45+
# Optional
46+
# Run-Command "cargo tarpaulin --lib --all-features --locked --out Html"
4547

4648
Write-Host "`n./src contains $(Count-Lines "src") non-empty lines" -ForegroundColor blue
4749
Write-Host "Ready to push!" -ForegroundColor Green

check.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ run_command "cargo run --example new_struct"
4040
run_command "cargo clippy --all-targets --all-features -- -D warnings --no-deps"
4141
run_command "cargo test --release -- --ignored"
4242
run_command "cargo fmt"
43+
# Optional
44+
# run_command "cargo tarpaulin --lib --all-features --locked --out Html"
4345

4446
echo -e "\n./src contains $(count_lines 'src') non-empty lines"
4547
echo -e "\033[32mReady to push!\033[0m"

src/cipher.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ unsafe impl<T: Copy + Sized> ByteConvertible for T {
111111
fn from_bytes(bytes: &[u8]) -> Self {
112112
assert!(
113113
bytes.len() == size_of::<T>(),
114-
"Invalid size of bytes for conversion: {} instead of {}",
115-
bytes.len(),
116-
size_of::<T>()
114+
"Invalid byte count for conversion: expected {} got {}",
115+
size_of::<T>(),
116+
bytes.len()
117117
);
118118

119119
let mut data: MaybeUninit<T> = core::mem::MaybeUninit::uninit();
@@ -261,12 +261,19 @@ mod tests {
261261
#[derive(Copy, Clone, Debug, PartialEq)]
262262
#[repr(C)]
263263
struct MyStruct {
264-
a: usize,
265-
b: usize,
264+
a: u32,
265+
b: u32,
266266
}
267267

268268
#[test]
269269
fn test_byteconvertible() {
270+
let raw = [2_u8, 1_u8];
271+
let data = u16::from_bytes(&raw);
272+
assert_eq!(258, data);
273+
274+
let bytes = data.to_bytes();
275+
assert_eq!(raw, bytes.as_slice());
276+
270277
let data = 0b1000_1010_u8;
271278
let bytes = data.to_bytes();
272279
let decrypted = u8::from_bytes(&bytes);
@@ -285,10 +292,10 @@ mod tests {
285292
}
286293

287294
#[test]
288-
#[should_panic = "Invalid size of bytes for conversion: 2 instead of 1"]
295+
#[should_panic = "Invalid byte count for conversion: expected 8 got 1"]
289296
fn test_byteconvertible_panic() {
290-
let bytes = [0u8; 2];
291-
let _ = u8::from_bytes(&bytes);
297+
let bytes = [0u8; 1];
298+
let _ = MyStruct::from_bytes(&bytes);
292299
}
293300

294301
#[test]

src/context.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,18 @@ impl Context {
443443
mod tests {
444444
use super::*;
445445

446+
#[test]
447+
#[should_panic = "Delta must be strictly less than d"]
448+
fn test_parameters_delta_panic() {
449+
let _ = Parameters::new(6, 3, 6, 5);
450+
}
451+
452+
#[test]
453+
#[should_panic = "Parameters must be strictly positive"]
454+
fn test_parameters_null_panic() {
455+
let _ = Parameters::new(6, 0, 2, 5);
456+
}
457+
446458
#[test]
447459
fn test_secret_key() {
448460
let s = vec![5, 14, 8];

src/operations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub trait HomomorphicOperation2<T: ByteConvertible> {
155155
/// impl<const N: usize> HomomorphicOperation<N, MyStruct> for MyOperation {
156156
/// /// ## Safety
157157
/// ///
158-
/// /// `d/delta` on cipher must have been at least `18*sizeof::<T>()`.
158+
/// /// `d/delta` on cipher must have been at least `3*sizeof::<T>()`.
159159
/// unsafe fn apply(args: [&Ciphered<MyStruct>; N]) -> Ciphered<MyStruct> {
160160
/// let result = args[0].deref().clone();
161161
///
@@ -166,7 +166,7 @@ pub trait HomomorphicOperation2<T: ByteConvertible> {
166166
/// }
167167
///
168168
/// // Usage
169-
/// let params = Parameters::new(128, 128, 1, 128);
169+
/// let params = Parameters::new(32, 8, 4, 8);
170170
/// let mut context = Context::new(params);
171171
/// context.generate_secret_key();
172172
/// context.generate_public_key();

tarpaulin-report.html

Lines changed: 671 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)