Formatação (cargo fmt) e ajustes do clippy para o CI da 1.0.0
Release / Cria a release (push) Canceled after 0s
Release / CLI (linux-aarch64) (push) Canceled after 0s
Release / CLI (linux-x86_64) (push) Canceled after 0s
Release / CLI (macos-aarch64) (push) Canceled after 0s
Release / CLI (macos-x86_64) (push) Canceled after 0s
Release / CLI (windows-x86_64) (push) Canceled after 0s
Release / App desktop (linux-x86_64) (push) Canceled after 0s
Release / App desktop (macos-aarch64) (push) Canceled after 0s
Release / App desktop (macos-x86_64) (push) Canceled after 0s
Release / App desktop (windows-x86_64) (push) Canceled after 0s
Release / Publica a release (push) Canceled after 0s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-10-19 11:41:58 -03:00
1 parent 74218e7beb
commit beb83fef92
49 files changed
+3806 -854

No files matched your search

+105 -15
View File
@@ -25,8 +25,17 @@ fn py_ok() -> bool {
fn run_stdin(cmd: &mut Command, input: &str) -> bool {
use std::io::Write;
let mut ch = cmd.stdin(Stdio::piped()).stdout(Stdio::null()).stderr(Stdio::null()).spawn().unwrap();
ch.stdin.take().unwrap().write_all(input.as_bytes()).unwrap();
let mut ch = cmd
.stdin(Stdio::piped())
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.unwrap();
ch.stdin
.take()
.unwrap()
.write_all(input.as_bytes())
.unwrap();
ch.wait().unwrap().success()
}
@@ -51,11 +60,26 @@ struct Case<'a> {
}
fn payload_offset(img: &Path, ver2: bool) -> u64 {
let o = Command::new("cryptsetup").arg("luksDump").arg(img).output().unwrap();
let o = Command::new("cryptsetup")
.arg("luksDump")
.arg(img)
.output()
.unwrap();
let t = String::from_utf8_lossy(&o.stdout).to_string();
if ver2 {
let l = t.lines().skip_while(|l| !l.starts_with("Data segments")).find(|l| l.contains("offset:")).unwrap();
l.split(':').nth(1).unwrap().split_whitespace().next().unwrap().parse().unwrap()
let l = t
.lines()
.skip_while(|l| !l.starts_with("Data segments"))
.find(|l| l.contains("offset:"))
.unwrap();
l.split(':')
.nth(1)
.unwrap()
.split_whitespace()
.next()
.unwrap()
.parse()
.unwrap()
} else {
let l = t.lines().find(|l| l.starts_with("Payload offset")).unwrap();
l.split(':').nth(1).unwrap().trim().parse::<u64>().unwrap() * 512
@@ -72,7 +96,10 @@ fn run_case(c: &Case) {
let plain = dir.path().join("plain.bin");
let data = plain_data(3 * 1024 * 1024 + 4096);
std::fs::write(&plain, &data).unwrap();
std::fs::File::create(&img).unwrap().set_len(24 << 20).unwrap();
std::fs::File::create(&img)
.unwrap()
.set_len(24 << 20)
.unwrap();
let pw = "senha com acentuação ç";
let mut fmt = Command::new("cryptsetup");
fmt.args(["luksFormat", "--batch-mode", "--key-file", "-"]);
@@ -81,9 +108,20 @@ fn run_case(c: &Case) {
assert!(run_stdin(&mut fmt, pw), "luksFormat falhou ({})", c.name);
let vkf = dir.path().join("vk.bin");
let mut dump = Command::new("cryptsetup");
dump.args(["luksDump", "--dump-volume-key", "--batch-mode", "--key-file", "-", "--volume-key-file"]);
dump.args([
"luksDump",
"--dump-volume-key",
"--batch-mode",
"--key-file",
"-",
"--volume-key-file",
]);
dump.arg(&vkf).arg(&img);
assert!(run_stdin(&mut dump, pw), "dump da chave falhou ({})", c.name);
assert!(
run_stdin(&mut dump, pw),
"dump da chave falhou ({})",
c.name
);
let off = payload_offset(&img, c.ver2);
let st = Command::new("python3")
.arg(Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/support/luks_encrypt.py"))
@@ -104,21 +142,36 @@ fn run_case(c: &Case) {
Err(e) => panic!("{}: erro inesperado {e}", c.name),
Ok(_) => panic!("{}: abriu com senha errada", c.name),
}
let u = luks::unlock(src.clone(), &[Secret::Password("x".into()), Secret::Password(pw.into())])
.unwrap_or_else(|e| panic!("{}: {e}", c.name));
let u = luks::unlock(
src.clone(),
&[Secret::Password("x".into()), Secret::Password(pw.into())],
)
.unwrap_or_else(|e| panic!("{}: {e}", c.name));
let got = read_vec(u.source.as_ref(), 0, data.len()).unwrap();
assert!(got == data, "{}: conteúdo difere", c.name);
// Também abre com a chave do volume.
let vk = std::fs::read(&vkf).unwrap();
let u2 = luks::unlock(src, &[Secret::VolumeKey(vk)]).unwrap();
assert_eq!(read_vec(u2.source.as_ref(), 1000, 5000).unwrap(), &data[1000..6000]);
assert_eq!(
read_vec(u2.source.as_ref(), 1000, 5000).unwrap(),
&data[1000..6000]
);
}
#[test]
fn luks1_xts() {
run_case(&Case {
name: "luks1-xts",
format_args: vec!["--type", "luks1", "--pbkdf-force-iterations", "1000", "-c", "aes-xts-plain64", "-s", "512"],
format_args: vec![
"--type",
"luks1",
"--pbkdf-force-iterations",
"1000",
"-c",
"aes-xts-plain64",
"-s",
"512",
],
cipher: "aes-xts-plain64",
sector: 512,
ver2: false,
@@ -129,7 +182,18 @@ fn luks1_xts() {
fn luks1_cbc_essiv_sha1() {
run_case(&Case {
name: "luks1-cbc-essiv",
format_args: vec!["--type", "luks1", "--pbkdf-force-iterations", "1000", "-c", "aes-cbc-essiv:sha256", "-s", "256", "-h", "sha1"],
format_args: vec![
"--type",
"luks1",
"--pbkdf-force-iterations",
"1000",
"-c",
"aes-cbc-essiv:sha256",
"-s",
"256",
"-h",
"sha1",
],
cipher: "aes-cbc-essiv:sha256",
sector: 512,
ver2: false,
@@ -140,7 +204,20 @@ fn luks1_cbc_essiv_sha1() {
fn luks2_argon2id_xts() {
run_case(&Case {
name: "luks2-argon2id",
format_args: vec!["--type", "luks2", "--pbkdf", "argon2id", "--pbkdf-force-iterations", "4", "--pbkdf-memory", "64", "-c", "aes-xts-plain64", "-s", "512"],
format_args: vec![
"--type",
"luks2",
"--pbkdf",
"argon2id",
"--pbkdf-force-iterations",
"4",
"--pbkdf-memory",
"64",
"-c",
"aes-xts-plain64",
"-s",
"512",
],
cipher: "aes-xts-plain64",
sector: 4096,
ver2: true,
@@ -151,7 +228,20 @@ fn luks2_argon2id_xts() {
fn luks2_pbkdf2_sector512_aes256() {
run_case(&Case {
name: "luks2-pbkdf2",
format_args: vec!["--type", "luks2", "--pbkdf", "pbkdf2", "--pbkdf-force-iterations", "1000", "-c", "aes-xts-plain64", "-s", "256", "--sector-size", "512"],
format_args: vec![
"--type",
"luks2",
"--pbkdf",
"pbkdf2",
"--pbkdf-force-iterations",
"1000",
"-c",
"aes-xts-plain64",
"-s",
"256",
"--sector-size",
"512",
],
cipher: "aes-xts-plain64",
sector: 512,
ver2: true,