public static void PrintFlagAverages(IDrxStore store) { var flags = new Dictionary <Guid, int>(); foreach (var document in store.GetDocuments()) { foreach (var flag in document.Header.Flags) { if (!flags.ContainsKey(flag)) { flags[flag] = 0; } flags[flag] += 1; } } var sorted = from entry in flags orderby entry.Value descending select entry; foreach (var flag in sorted) { var resolved = store.ResolveFlag(flag.Key); if (resolved == null) { Console.WriteLine($"???? - {flag.Value}"); continue; } Console.WriteLine($"{resolved?.Tag} {resolved?.Name} - {flag.Value}"); } }
public static void PrintUnresolvableFlags(IDrxStore store) { foreach (var document in store.GetDocuments()) { foreach (var flag in document.Header.Flags) { var resolved = store.ResolveFlag(flag); if (resolved == null) { Console.WriteLine($"Warning: cannot resolve Flag ID {flag}"); continue; } } } }
public static async void PrintSecurityViolations(IDrxStore store, bool correct = false, bool verbose = false) { foreach (var document in store.GetDocuments()) { var violations = new List <string>(); foreach (var flag in document.Header.Flags) { var resolved = store.ResolveFlag(flag); if (resolved == null) { if (verbose) { Console.WriteLine($"Warning: cannot resolve Flag ID {flag}"); } continue; } if (resolved.SecurityLevel > document.Header.SecurityLevel) { if (correct && document.Header.SecurityLevel < resolved.SecurityLevel) { document.Header.SecurityLevel = resolved.SecurityLevel; } violations.Add($"- flag violation: {resolved.Tag} {resolved.Name} **{resolved.SecurityLevel}"); } } await document.LoadBodyAsync(); document.DecryptBodyBytes(); if (document.Header.SecurityLevel >= DrxSecurityLevel.Secret && !document.Header.Encrypted) { if (correct) { document.Header.Encrypted = true; } violations.Add("- document should be encrypted"); } if (violations.Count <= 0) { continue; } if (correct) { document.EncryptBodyBytes(); await document.SaveAsync(); } Console.WriteLine($"{document.ToString()} ({document.Id}) is not compliant: "); foreach (var violation in violations) { Console.WriteLine(violation); } Console.WriteLine(); } }