-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9385dce
commit 319386a
Showing
6 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Change Log | ||
|
||
## [$Unreleased] - $ReleaseDate | ||
|
||
This release is mostly laying the groundwork for a more serious improvements. | ||
|
||
### Added | ||
|
||
* It is now possible to provide block size with a scale unit. E.g. `128k` (128 kilobytes) instead of `131072`. Additionally, the number is checked to be a power of two. | ||
|
||
### Changed | ||
|
||
* Usuccessful validation now retries at the last successful position. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
[package] | ||
name = "lethe" | ||
version = "0.1.6-dev" | ||
authors = ["kostassoid <[email protected]>"] | ||
authors = ["Konstantin Alexandroff <[email protected]>"] | ||
description = "A command-line tool to generate cryptocurrency wallets" | ||
homepage = "https://github.com/Kostassoid/lethe" | ||
repository = "https://github.com/Kostassoid/lethe" | ||
categories = ["command-line-utilities"] | ||
keywords = ["security", "command-line", "disk", "erase", "wipe", "storage"] | ||
readme = "README.md" | ||
license = "Apache-2.0" | ||
edition = "2018" | ||
|
||
[badges] | ||
travis-ci = { repository = "Kostassoid/lethe", branch = "master" } | ||
|
||
[dependencies] | ||
nix = "0.14.1" | ||
clap = "~2.33" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
disable-publish = true | ||
dev-version-ext = "dev" | ||
pre-release-replacements = [ | ||
{file="README.md", search="v[0-9]+\\.[0-9]+\\.[0-9]+", replace="v{{version}}"} | ||
{file="README.md", search="v[0-9]+\\.[0-9]+\\.[0-9]+", replace="v{{version}}"}, | ||
{file="CHANGELOG.md", search="$Unreleased", replace="{{version}}"}, | ||
{file="CHANGELOG.md", search="$ReleaseDate", replace="{{date}}"} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use regex::Regex; | ||
|
||
pub fn parse_block_size(s: &str) -> Result<usize, &'static str> { | ||
let block_size_regex = Regex::new(r"^(?i)(\d+) *((k|m)b?)?$").unwrap(); | ||
let captures = block_size_regex.captures(s); | ||
|
||
match captures { | ||
Some(groups) => { | ||
let units = groups[1].parse::<usize>().map_err(|_x| "Not a number.")?; | ||
let unit_size = match groups.get(3).map(|m| m.as_str().to_uppercase()) { | ||
Some(ref u) if u == "K" => 1024, | ||
Some(ref u) if u == "M" => 1024 * 1024, | ||
_ => 1 | ||
}; | ||
|
||
let bytes_length = (units * unit_size) as usize; | ||
if bytes_length & (bytes_length - 1) == 0 { | ||
Ok((units * unit_size) as usize) | ||
} else { | ||
Err("Should be a power of two.") | ||
} | ||
}, | ||
_ => { | ||
Err("Use a number of bytes with optional scale (e.g. 4096, 128k or 2M).") | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use assert_matches::*; | ||
|
||
#[test] | ||
fn test_block_size_parser_good() { | ||
let k128 = 128 * 1024; | ||
let m2 = 2 * 1024 * 1024; | ||
|
||
assert_eq!(parse_block_size("4096"), Ok(4096)); | ||
assert_eq!(parse_block_size("128k"), Ok(k128)); | ||
assert_eq!(parse_block_size("128K"), Ok(k128)); | ||
assert_eq!(parse_block_size("2m"), Ok(m2)); | ||
assert_eq!(parse_block_size("2M"), Ok(m2)); | ||
} | ||
|
||
#[test] | ||
fn test_block_size_parser_bad() { | ||
assert_matches!(parse_block_size(""), Err(_)); | ||
assert_matches!(parse_block_size("xxx"), Err(_)); | ||
assert_matches!(parse_block_size("-128k"), Err(_)); | ||
assert_matches!(parse_block_size("4096.000"), Err(_)); | ||
assert_matches!(parse_block_size("4095"), Err(_)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod cli; | ||
pub mod args; |