diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3447c343..cea46a48 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,14 +20,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - run: cargo clippy -- -D warnings + - run: cargo clippy -- -D warnings test: strategy: matrix: # https://docs.github.com/en/actions/using-jobs/choosing-the-runner-for-a-job#choosing-github-hosted-runners os: [windows-latest, ubuntu-latest, macos-13] - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - run: cargo t diff --git a/README.md b/README.md index 8e1e79b6..fd949dde 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # Data Block Set + Data Block Set + +## For Developers + +Installation: + +``` +cargo install --git https://github.com/datablockset/blockset +``` + +Uninstallation: + +``` +cargo uninstall blockset +``` \ No newline at end of file diff --git a/blockset/src/base32.rs b/blockset/src/base32.rs index 25a48cb0..7d409b70 100644 --- a/blockset/src/base32.rs +++ b/blockset/src/base32.rs @@ -1,4 +1,4 @@ -use crate::{ascii::to_ascii, bit_vec32::BitVec32}; +use crate::{ascii::to_ascii, bit_vec::BitVec}; const fn to_base32(v: u8) -> char { //0 1 @@ -32,13 +32,13 @@ pub trait ToBase32 { } pub trait BitsToBase32 { - fn bits_to_base32(self) -> (String, BitVec32); + fn bits_to_base32(self) -> (String, BitVec); } -impl> BitsToBase32 for T { - fn bits_to_base32(self) -> (String, BitVec32) { +impl> BitsToBase32 for T { + fn bits_to_base32(self) -> (String, BitVec) { let mut result = String::default(); - let mut a = BitVec32::default(); + let mut a = BitVec::default(); for b in self { a.push(&mut |v| result.push(to_base32(v as u8)), 5, b) } @@ -61,13 +61,13 @@ impl StrEx for str { } } -impl FromBase32 for (Vec, BitVec32) { +impl FromBase32 for (Vec, BitVec) { fn from_base32(i: &str) -> Option { let mut result = Vec::default(); - let mut a = BitVec32::default(); + let mut a = BitVec::default(); for b in i.chars() { let v5 = from_base32(b)?; - a.push(&mut |v| result.push(v), 32, BitVec32::new(v5 as u32, 5)); + a.push(&mut |v| result.push(v), 32, BitVec::new(v5 as u32, 5)); } Some((result, a)) } diff --git a/blockset/src/bit_vec32.rs b/blockset/src/bit_vec.rs similarity index 60% rename from blockset/src/bit_vec32.rs rename to blockset/src/bit_vec.rs index 2b99807b..26f236b0 100644 --- a/blockset/src/bit_vec32.rs +++ b/blockset/src/bit_vec.rs @@ -1,25 +1,28 @@ #[derive(Default)] -pub struct BitVec32 { - pub v: u64, +pub struct BitVec { + pub value: u64, pub len: u8, } -impl BitVec32 { +impl BitVec { pub const fn new(v: u32, len: u8) -> Self { - Self { v: v as u64, len } + Self { + value: v as u64, + len, + } } - pub fn push(&mut self, f: &mut impl FnMut(u32), size: u8, b: BitVec32) { + pub fn push(&mut self, f: &mut impl FnMut(u32), size: u8, b: BitVec) { assert!(size <= 32); - self.v |= b.v << self.len; + self.value |= b.value << self.len; self.len += b.len; let mask = (1 << size) - 1; loop { if self.len < size { return; } - f((self.v & mask) as u32); + f((self.value & mask) as u32); self.len -= size; - self.v >>= size; + self.value >>= size; } } } diff --git a/blockset/src/digest224.rs b/blockset/src/digest224.rs index d9ea4383..858a76c3 100644 --- a/blockset/src/digest224.rs +++ b/blockset/src/digest224.rs @@ -2,7 +2,7 @@ use std::iter::once; use crate::{ base32::{BitsToBase32, FromBase32, StrEx, ToBase32}, - bit_vec32::BitVec32, + bit_vec::BitVec, }; pub type Digest224 = [u32; 7]; @@ -19,13 +19,13 @@ impl Digest224Ex for &Digest224 { impl ToBase32 for &Digest224 { fn to_base32(self) -> String { - let (result, a) = self + let (result, BitVec { value, len }) = self .iter() - .map(|x| BitVec32::new(*x, 32)) - .chain(once(BitVec32::new(self.parity_bit() as u32, 1))) + .map(|x| BitVec::new(*x, 32)) + .chain(once(BitVec::new(self.parity_bit() as u32, 1))) .bits_to_base32(); - assert_eq!(a.len, 0); - assert_eq!(a.v, 0); + assert_eq!(len, 0); + assert_eq!(value, 0); assert_eq!(result.len(), 45); result } @@ -33,15 +33,15 @@ impl ToBase32 for &Digest224 { impl FromBase32 for Digest224 { fn from_base32(i: &str) -> Option { - let (vec, a) = i.from_base32()?; + let (vec, BitVec { value, len }) = i.from_base32()?; if vec.len() != 7 { return None; } - assert_eq!(a.len, 1); - assert_eq!(a.v | 1, 1); + assert_eq!(len, 1); + assert_eq!(value | 1, 1); let mut result = Digest224::default(); result.copy_from_slice(&vec); - if a.v as u8 != result.parity_bit() { + if value != result.parity_bit() as u64 { return None; } Some(result) diff --git a/blockset/src/lib.rs b/blockset/src/lib.rs index 30de1f26..fd07368c 100644 --- a/blockset/src/lib.rs +++ b/blockset/src/lib.rs @@ -1,7 +1,7 @@ mod app; mod ascii; mod base32; -mod bit_vec32; +mod bit_vec; mod digest224; mod io; mod sha224;