diff --git a/Cargo.lock b/Cargo.lock index e8ef23e6..084bec67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,9 +142,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" dependencies = [ "jobserver", ] diff --git a/bin/app/src/lib.rs b/bin/app/src/lib.rs index 1e2bf0d1..1b823345 100644 --- a/bin/app/src/lib.rs +++ b/bin/app/src/lib.rs @@ -48,13 +48,6 @@ pub fn cli() -> Command { .action(ArgAction::Count) .short('v'), ); - global = global.arg( - clap::Arg::new("version") - .global(false) - .help("Print version") - .action(ArgAction::SetTrue) - .long("version"), - ); global = global.arg( clap::Arg::new("trace") .global(true) @@ -62,6 +55,16 @@ pub fn cli() -> Command { .action(ArgAction::SetTrue) .long("trace"), ); + #[cfg(debug_assertions)] + { + global = global.arg( + clap::Arg::new("in-test") + .global(true) + .help("we are in a test") + .action(ArgAction::SetTrue) + .long("in-test"), + ); + } global } @@ -73,13 +76,10 @@ pub fn cli() -> Command { /// # Panics /// If the number passed to `--threads` is not a valid number pub fn execute(matches: &ArgMatches) -> Result<(), AppError> { - if matches.get_flag("version") { - println!("HEMTT {}", env!("CARGO_PKG_VERSION")); - return Ok(()); + if cfg!(not(debug_assertions)) || !matches.get_flag("in-test") { + logging::init(matches.get_count("verbosity"), matches.get_flag("trace")); } - logging::init(matches.get_count("verbosity"), matches.get_flag("trace")); - trace!("version: {}", env!("CARGO_PKG_VERSION")); trace!("platform: {}", std::env::consts::OS); diff --git a/bin/app/src/modules/sign.rs b/bin/app/src/modules/sign.rs index cd0dcea8..03c01d7a 100644 --- a/bin/app/src/modules/sign.rs +++ b/bin/app/src/modules/sign.rs @@ -32,7 +32,7 @@ impl Module for Sign { let authority = get_authority(ctx, None)?; let addons_key = BIPrivateKey::generate(1024, &authority)?; create_dir_all(ctx.out_folder().join("keys"))?; - addons_key.write(&mut File::create( + addons_key.to_public_key().write(&mut File::create( ctx.out_folder() .join("keys") .join(format!("{authority}.bikey")), @@ -57,13 +57,12 @@ impl Module for Sign { if ctx.config().hemtt().build().optional_mod_folders() { let authority = get_authority(ctx, Some(&pbo_name))?; let key = BIPrivateKey::generate(1024, &authority)?; - let pubkey = key.to_public_key(); let mod_root = ctx .out_folder() .join("optionals") .join(format!("@{pbo_name}")); create_dir_all(mod_root.join("keys"))?; - pubkey.write(&mut File::create( + key.to_public_key().write(&mut File::create( mod_root.join("keys").join(format!("{authority}.bikey")), )?)?; (mod_root.join("addons").join(pbo_name), key, authority) diff --git a/bin/app/tests/build.rs b/bin/app/tests/build.rs index b48ed2c0..74732b4e 100644 --- a/bin/app/tests/build.rs +++ b/bin/app/tests/build.rs @@ -3,8 +3,8 @@ use hemtt::cli; #[test] pub fn build() { std::env::set_current_dir("tests/alpha").unwrap(); - hemtt::execute(&cli().get_matches_from(vec!["hemtt", "build"])).unwrap(); + hemtt::execute(&cli().get_matches_from(vec!["hemtt", "build", "--in-test"])).unwrap(); std::env::set_current_dir("../bravo").unwrap(); - hemtt::execute(&cli().get_matches_from(vec!["hemtt", "release"])).unwrap(); + hemtt::execute(&cli().get_matches_from(vec!["hemtt", "release", "--in-test"])).unwrap(); } diff --git a/libs/preprocessor/src/lib.rs b/libs/preprocessor/src/lib.rs index b94bf05e..932620e7 100644 --- a/libs/preprocessor/src/lib.rs +++ b/libs/preprocessor/src/lib.rs @@ -94,6 +94,11 @@ where if next.symbol() == &Symbol::Slash { whitespace::skip_comment(tokenstream); } + } else { + tokenstream.move_cursor_back().unwrap(); + if context.ifstates().reading() { + output.push(tokenstream.next().unwrap()); + } } } _ => { @@ -705,6 +710,9 @@ where if next.symbol() == &Symbol::Slash { whitespace::skip_comment(tokenstream); } + } else { + tokenstream.move_cursor_back().unwrap(); + output.push(tokenstream.next().unwrap()); } } _ => output.push(tokenstream.next().unwrap()), diff --git a/libs/signing/src/private.rs b/libs/signing/src/private.rs index 7e424fa3..3b41bef9 100644 --- a/libs/signing/src/private.rs +++ b/libs/signing/src/private.rs @@ -9,7 +9,7 @@ use sha1::{Digest, Sha1}; use crate::{error::Error, public::BIPublicKey, signature::BISign}; #[allow(clippy::module_name_repetitions)] -#[derive(Clone)] +#[derive(Debug, Clone)] /// A private key for signing PBOs pub struct BIPrivateKey { authority: String, @@ -36,9 +36,6 @@ impl BIPrivateKey { let mut rng = rand::thread_rng(); let mut rsa = RsaPrivateKey::new(&mut rng, length as usize)?; rsa.precompute()?; - // let Some(precomputed) = rsa.precomputed() else { - // return Err(Error::Rsa(rsa::errors::Error::Internal)); - // }; let primes = rsa.primes(); let Some(qinv) = rsa.qinv().unwrap().to_biguint() else { return Err(Error::Rsa(rsa::errors::Error::Internal)); @@ -180,7 +177,7 @@ impl BIPrivateKey { /// /// # Panics /// If the qinv sign is not `NoSign`. - pub fn write(&self, output: &mut O) -> Result<(), Error> { + pub fn write_danger(&self, output: &mut O) -> Result<(), Error> { output.write_cstring(&self.authority)?; output.write_u32::(self.length / 16 * 9 + 20)?; output.write_all(b"\x07\x02\x00\x00\x00\x24\x00\x00")?; diff --git a/libs/signing/tests/bootstrap.rs b/libs/signing/tests/bootstrap.rs index 91978969..fcec1e18 100644 --- a/libs/signing/tests/bootstrap.rs +++ b/libs/signing/tests/bootstrap.rs @@ -1,4 +1,4 @@ -use std::fs::File; +use std::{fs::File, io::Write}; use hemtt_pbo::ReadablePbo; use hemtt_signing::BIPrivateKey; @@ -15,7 +15,7 @@ fn bootstrap() { BIPrivateKey::read(&mut File::open(file.path().join("test.biprivatekey")).unwrap()) .unwrap(); let mut buffer = Vec::new(); - private.write(&mut buffer).unwrap(); + private.write_danger(&mut buffer).unwrap(); assert_eq!( buffer, std::fs::read(file.path().join("test.biprivatekey")).unwrap() diff --git a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign index 77d8985c..32c820b3 100644 Binary files a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign and b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign differ diff --git a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign.test b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign.test deleted file mode 100644 index 77d8985c..00000000 Binary files a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/source.pbo.test.bisign.test and /dev/null differ diff --git a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.bikey b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.bikey index 670d066a..d8c40a7b 100644 Binary files a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.bikey and b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.bikey differ diff --git a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.biprivatekey b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.biprivatekey index 1d79e680..cdc1bd92 100644 Binary files a/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.biprivatekey and b/libs/signing/tests/bootstrap/ace_ai_3.15.2.69/test.biprivatekey differ