using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace RuriLib.Models { /// /// Settings for customizeable data types used in the library. /// public class EnvironmentSettings { /// List of custom Wordlist Types. public List WordlistTypes { get; set; } = new List(); /// List of custom KeyChain Types. public List CustomKeychains { get; set; } = new List(); /// List of custom Export Formats. public List ExportFormats { get; set; } = new List(); /// /// Gets the names of all Wordlist Types. /// /// The list of all the names of custom Wordlist Types public List GetWordlistTypeNames() { return WordlistTypes.Select(w => w.Name).ToList(); } /// /// Automatically recognizes a Wordlist Type between the ones available by matching the Regex patterns and returning the first successful match. /// /// The data for which you want to recognize the Wordlist Type /// The correct Wordlist Type or (if every Regex match failed) the first one public string RecognizeWordlistType(string data) { foreach (var type in WordlistTypes) { if (Regex.Match(data, type.Regex).Success) { return type.Name; } } return WordlistTypes.First().Name; } /// /// Gets the names of all Custom KeyChains. /// /// The list of all the names of custom KeyChain types public List GetCustomKeychainNames() { return CustomKeychains.Select(c => c.Name).ToList(); } /// /// Gets a Custom KeyChain given its name. /// /// The name of the Custom KeyChain /// The CustomKeychain object if found, a default one if not public CustomKeychain GetCustomKeychain(string name) { try { return CustomKeychains.First(w => w.Name == name); } catch { return new CustomKeychain(); } } /// /// Gets a Wordlist Type given its name. /// /// The name of the Wordlist Type /// The WordlistType object if found, a default one if not public WordlistType GetWordlistType(string name) { try { return WordlistTypes.FirstOrDefault(w => w.Name == name); } catch { return new WordlistType(); } } } }