/// <summary> /// Loads a security profile with the specified options /// </summary> /// <param name="source">A reader for a profile file source. If null, the default profile is loaded</param> /// <param name="options">The optional flags for the profile</param> /// <returns>A dictionary containing the security profile</returns> /// <exception cref="ArgumentException">A regular expression parsing error occurred</exception> /// <exception cref="IOException">An I/O error occurs</exception> /// <exception cref="ObjectDisposedException">The TextReader is closed</exception> public static SecurityProfile LoadProfile(TextReader source, SecurityProfileOptions options) { var profile = new SecurityProfile(); if (source == null) { source = new StringReader(DefaultProfile); } string line; while ((line = source.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(line)) { continue; } var parts = line.Trim().Split(';'); if (parts.Length == 0) { continue; } var tag = new Regex(parts[0], RegexOptions.IgnoreCase | RegexOptions.Singleline); var empty = default(char).ToString(); for (var i = 0; i < OptionsCount; i++) { var flag = (SecurityProfileOptions)(1 << i); if ((options & flag) == flag) { var action = parts[i + 1].ToCharArray().FirstOrDefault().ToString(); if (action != empty) { profile[tag] = (SecurityProfileActions)Enum.Parse(typeof(SecurityProfileActions), action); } } } } return(profile); }
/// <summary> /// Return the tag and the appropriate action based on the security profile /// </summary> /// <param name="item">A valid confidentiality profile line</param> /// <param name="options">The security profile options</param> /// <returns></returns> private Tuple <string, AnonFunc> parseProfileItem(string item, SecurityProfileOptions options) { SecurityProfileActions?action = null; var parts = item.Split(';'); var tag = parts[0]; for (var i = 0; i < _optionsCount; i++) { var flag = (SecurityProfileOptions)(1 << i); if ((options & flag) == flag) { var a = parts[i + 1].ToCharArray().FirstOrDefault().ToString(); if (a != default(char).ToString()) { action = (SecurityProfileActions)Enum.Parse(typeof(SecurityProfileActions), a); } } } switch (action.Value) { case SecurityProfileActions.U: // UID return(Tuple.Create <string, AnonFunc>(tag, ReplaceUID)); case SecurityProfileActions.C: // Clean case SecurityProfileActions.D: // Dummy return(Tuple.Create <string, AnonFunc>(tag, CleanDummyElement)); case SecurityProfileActions.K: // Keep return(Tuple.Create <string, AnonFunc>(tag, KeepItem)); case SecurityProfileActions.X: // Remove return(Tuple.Create <string, AnonFunc>(tag, RemoveItem)); case SecurityProfileActions.Z: // Zero-length return(Tuple.Create <string, AnonFunc>(tag, BlankElement)); default: throw new ArgumentOutOfRangeException($"Unrecognized action: {action.Value}"); } }
public ConfidentialityProfile(SecurityProfileOptions ops) { _options = ops; }