diff --git a/psistega3-cli/src/main.rs b/psistega3-cli/src/main.rs index 3ad2ebd..d951429 100644 --- a/psistega3-cli/src/main.rs +++ b/psistega3-cli/src/main.rs @@ -89,6 +89,7 @@ fn main() { // Attempt to extract the codec version number. // No default codec needs to be implemented here as the statement below // will always yield a valid codec. + let mut skip_version_checks = false; let mut codec: Box; if needs_codec { let mut codec_version: Option = None; @@ -106,6 +107,8 @@ fn main() { } else { show_abort_message(Error::VersionGuessingFailed); } + + skip_version_checks = true; } if let Ok(v) = version.parse::() { @@ -129,6 +132,9 @@ fn main() { codec = Box::::default(); } + // When using the version guessing system, the checks are skipped. + codec.set_config_state(Config::SkipVersionChecks, skip_version_checks); + // Execute the requested action with the provided arguments. let result = match action.as_str() { "-e" | "-encrypt" => handle_encode(&args[4..], &mut codec), diff --git a/psistega3-core/src/codecs/codec.rs b/psistega3-core/src/codecs/codec.rs index 926a681..1a20939 100644 --- a/psistega3-core/src/codecs/codec.rs +++ b/psistega3-core/src/codecs/codec.rs @@ -89,22 +89,26 @@ pub trait Codec { pub enum Config { /// Enable or disable the noise map. /// - /// Applicable to: v1. + /// Applicable to: v1, v2. NoiseLayer, /// Enable or disable verbose mode. /// - /// Applicable to: v1. + /// Applicable to: v1, v2. Verbose, /// Enable or disable the saving of files when encoding or decoding. /// - /// Applicable to: v1. + /// Applicable to: v1, v2. OutputFiles, /// Enable or disable the file access locking system for this file. /// - /// Applicable to: v1. + /// Applicable to: v1, v2. Locker, /// Enable or disable the single-read locker system. /// - /// Applicable to: v1. + /// Applicable to: v1, v2. ReadOnce, + /// Enable or disable version checking. + /// + /// Applicable to: v2. This is not applicable to v1 as checks are never performed. + SkipVersionChecks, } diff --git a/psistega3-core/src/codecs/v1.rs b/psistega3-core/src/codecs/v1.rs index 2d39d23..6dcb3da 100644 --- a/psistega3-core/src/codecs/v1.rs +++ b/psistega3-core/src/codecs/v1.rs @@ -881,6 +881,7 @@ impl Codec for StegaV1 { Config::ReadOnce => { self.set_feature_flag_state(1, state); } + Config::SkipVersionChecks => {} } } } diff --git a/psistega3-core/src/codecs/v2.rs b/psistega3-core/src/codecs/v2.rs index c21a968..a6f30cd 100644 --- a/psistega3-core/src/codecs/v2.rs +++ b/psistega3-core/src/codecs/v2.rs @@ -39,6 +39,8 @@ pub struct StegaV2 { noise_layer: bool, /// If the resulting image file should be saved when encoding. output_files: bool, + /// Should we skip version checks? + skip_version_checks: bool, /// Flags for use when encoding and decoding. /// Bit 0 indicates that the file locker is to be used with this file. /// Bit 1 indicates that the file is read-once. @@ -65,6 +67,7 @@ impl StegaV2 { data_cell_map: HashMap::new(), noise_layer: true, output_files: true, + skip_version_checks: false, flags: 0, locker, logger: Logger::new(false), @@ -597,6 +600,11 @@ impl StegaV2 { return false; } + if !self.skip_version_checks && data[5] != CODED_VERSION { + // The codec version does not match. + return false; + } + // The 1st bit are be stored in byte 1. // Bit 1 stores the flag indicating whether the file locker should be // used with this file. @@ -881,6 +889,9 @@ impl Codec for StegaV2 { Config::ReadOnce => { self.set_feature_flag_state(1, state); } + Config::SkipVersionChecks => { + self.skip_version_checks = state; + } } } } @@ -1149,6 +1160,7 @@ mod tests_encode_decode { data_cell_map: HashMap::new(), noise_layer: false, // We do not need this here. output_files: true, + skip_version_checks: false, flags: 0, locker, logger: Logger::new(false),