diff --git a/BinaryObjectScanner.Test/ScannerTests.cs b/BinaryObjectScanner.Test/ProtectionDictionaryTests.cs similarity index 67% rename from BinaryObjectScanner.Test/ScannerTests.cs rename to BinaryObjectScanner.Test/ProtectionDictionaryTests.cs index 122af976..d93dc25c 100644 --- a/BinaryObjectScanner.Test/ScannerTests.cs +++ b/BinaryObjectScanner.Test/ProtectionDictionaryTests.cs @@ -3,7 +3,7 @@ using Xunit; namespace BinaryObjectScanner.Test { - public class ScannerTests + public class ProtectionDictionaryTests { #region ProcessProtectionString @@ -11,7 +11,7 @@ namespace BinaryObjectScanner.Test public void ProcessProtectionString_Null_Empty() { string? protection = null; - List actual = Scanner.ProcessProtectionString(protection); + List actual = ProtectionDictionary.ProcessProtectionString(protection); Assert.Empty(actual); } @@ -19,7 +19,7 @@ namespace BinaryObjectScanner.Test public void ProcessProtectionString_Empty_Empty() { string? protection = string.Empty; - List actual = Scanner.ProcessProtectionString(protection); + List actual = ProtectionDictionary.ProcessProtectionString(protection); Assert.Empty(actual); } @@ -27,7 +27,7 @@ namespace BinaryObjectScanner.Test public void ProcessProtectionString_NoIndicator_Single() { string? protection = "item1"; - List actual = Scanner.ProcessProtectionString(protection); + List actual = ProtectionDictionary.ProcessProtectionString(protection); Assert.Single(actual); } @@ -35,7 +35,7 @@ namespace BinaryObjectScanner.Test public void ProcessProtectionString_Indicator_Multiple() { string? protection = "item1;item2"; - List actual = Scanner.ProcessProtectionString(protection); + List actual = ProtectionDictionary.ProcessProtectionString(protection); Assert.Equal(2, actual.Count); } diff --git a/BinaryObjectScanner/ProtectionDictionary.cs b/BinaryObjectScanner/ProtectionDictionary.cs index d5b16ad2..c365fa72 100644 --- a/BinaryObjectScanner/ProtectionDictionary.cs +++ b/BinaryObjectScanner/ProtectionDictionary.cs @@ -21,13 +21,16 @@ namespace BinaryObjectScanner /// /// Key to add information to /// String value to add - public void Append(string key, string value) + public void Append(string key, string? value) { // If the value is empty, don't add it if (value == null || value.Trim().Length == 0) return; - Append(key, [value]); + foreach (string subValue in ProcessProtectionString(value)) + { + this[key].Enqueue(subValue); + } } /// @@ -47,7 +50,10 @@ namespace BinaryObjectScanner if (value == null || value.Trim().Length == 0) continue; - this[key].Enqueue(value); + foreach (string subValue in ProcessProtectionString(value)) + { + this[key].Enqueue(subValue); + } } } @@ -186,10 +192,43 @@ namespace BinaryObjectScanner if (value == null || value.Trim().Length == 0) continue; - this[key].Enqueue(value); + foreach (string subValue in ProcessProtectionString(value)) + { + this[key].Enqueue(subValue); + } } } + #region Helpers + + /// + /// Process a protection string if it includes multiple protections + /// + /// Protection string to process + /// Set of protections parsed, empty on error + internal static List ProcessProtectionString(string? protection) + { + // If we have an invalid protection string + if (string.IsNullOrEmpty(protection)) + return []; + + // Setup the output queue + var protections = new List(); + + // If we have an indicator of multiple protections + if (protection!.Contains(";")) + { + var splitProtections = protection.Split(';'); + protections.AddRange(splitProtections); + } + else + { + protections.Add(protection); + } + + return protections; + } + /// /// Ensure the collection for the given key exists /// @@ -202,5 +241,7 @@ namespace BinaryObjectScanner TryAdd(key, new ConcurrentQueue()); #endif } + + #endregion } } \ No newline at end of file diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs index c9b6c2b5..09028561 100644 --- a/BinaryObjectScanner/Scanner.cs +++ b/BinaryObjectScanner/Scanner.cs @@ -284,7 +284,7 @@ namespace BinaryObjectScanner else { var subProtection = detectable.Detect(stream, fileName, _options.IncludeDebug); - protections.Append(fileName, ProcessProtectionString(subProtection)); + protections.Append(fileName, subProtection); } } @@ -395,8 +395,8 @@ namespace BinaryObjectScanner if (File.Exists(path)) { var protection = impl.CheckFilePath(path!); - var subProtections = ProcessProtectionString(protection); - protections.AddRange(subProtections); + if (protection != null) + protections.Add(protection); } // If we have a directory path @@ -411,37 +411,5 @@ namespace BinaryObjectScanner } #endregion - - #region Helpers - - /// - /// Process a protection string if it includes multiple protections - /// - /// Protection string to process - /// Set of protections parsed, empty on error - internal static List ProcessProtectionString(string? protection) - { - // If we have an invalid protection string - if (string.IsNullOrEmpty(protection)) - return []; - - // Setup the output queue - var protections = new List(); - - // If we have an indicator of multiple protections - if (protection!.Contains(";")) - { - var splitProtections = protection.Split(';'); - protections.AddRange(splitProtections); - } - else - { - protections.Add(protection); - } - - return protections; - } - - #endregion } }