Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 6, 2023
1 parent c269d90 commit 82d4470
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 242 deletions.
30 changes: 15 additions & 15 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,21 +390,21 @@ For readability, newlines are allowed to delineate key value pairs:
<a id='snippet-parseemailheaderfullnewlines'></a>
```cs
var protectiveMarking = Parser.ParseProtectiveMarking("""
VER=2018.4,
NS=gov.au,
SEC=TOP-SECRET,
CAVEAT=C:CodeWord,
CAVEAT=FG:USA caveat,
CAVEAT=RI:AGAO,
CAVEAT=SH:CABINET,
CAVEAT=SH:EXCLUSIVE-FOR person,
CAVEAT=RI:REL AFG/DZA,
EXPIRES=2020-10-01,
DOWNTO=OFFICIAL,
ACCESS=Legal-Privilege,
NOTE=the comments,
[email protected]
""");
VER=2018.4,
NS=gov.au,
SEC=TOP-SECRET,
CAVEAT=C:CodeWord,
CAVEAT=FG:USA caveat,
CAVEAT=RI:AGAO,
CAVEAT=SH:CABINET,
CAVEAT=SH:EXCLUSIVE-FOR person,
CAVEAT=RI:REL AFG/DZA,
EXPIRES=2020-10-01,
DOWNTO=OFFICIAL,
ACCESS=Legal-Privilege,
NOTE=the comments,
[email protected]
""");
```
<sup><a href='/src/Tests/Samples.cs#L216-L235' title='Snippet source file'>snippet source</a> | <a href='#snippet-parseemailheaderfullnewlines' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
Expand Down
20 changes: 1 addition & 19 deletions src/AustralianProtectiveMarkings/Caveats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ public readonly record struct Caveats

/// <summary>
/// Sensitive compartmented information.
///
/// Maps to: CAVEAT=C code-word
///
/// Use of codewords is primarily within the national security community. A codeword indicates that the information
/// is of sufficient sensitivity that it requires protection in addition to that offered by a security
/// classification.
///
/// Each codeword identifies a special need-to-know compartment. A compartment is a mechanism for restricting
/// access to information by defined individuals who have been ‘briefed’ on the particular sensitivities of that
/// information and any special rules that may apply. The codeword is chosen so that its ordinary meaning is
Expand All @@ -43,9 +40,7 @@ public string? Codeword
/// <summary>
/// Foreign government markings are applied to information created by Australian agencies from foreign source
/// information.
///
/// Maps to: CAVEAT=FG caveat-name
///
/// https://www.protectivesecurity.gov.au/publications-library/policy-7-security-governance-international-sharing
/// </summary>
public string? ForeignGovernment
Expand All @@ -66,9 +61,7 @@ public string? ForeignGovernment

/// <summary>
/// Identifies information intended for access by a named recipient only.
///
/// Maps to: CAVEAT=SH:EXCLUSIVE-FOR named-person>|indicator
///
/// Access to EXCLUSIVE FOR information is limited to a named person, position title or designation.
/// </summary>
public string? ExclusiveFor
Expand All @@ -80,15 +73,14 @@ public string? ExclusiveFor
{
TextValidator.Validate(value);
}

exclusiveFor = value;
}
}

/// <summary>
/// Releasability (REL) caveats
///
/// Maps to: CAVEAT=RI:REL Code1/Code2...
///
/// For example, REL AUS/CAN/GBR/NZL/USA means that the information may be passed to citizens of Australia, Canada,
/// United Kingdom, New Zealand and the United States of America only
/// </summary>
Expand All @@ -115,12 +107,9 @@ void GuardDuplicateCountryCodeUse()
/// Indicates information that can only be accessed by appropriately cleared Australian citizens
/// and appropriately cleared representatives of Five-Eyes Governments on exchange, secondment, long-term posting
/// or attachment within the National Intelligence Community and the Department of Defence.
///
/// Maps to: CAVEAT=RI:AGAO
///
/// AGAO information must not be distributed to the Five Eyes foreign representative’s parent agency or government.
/// AGAO information may not be shared with any other foreign nationals.
///
/// Where appropriate, all entities may apply the AGAO caveat to classified information. However, entities other
/// than members of the National Intelligence Community and the Department of Defence must handle AGAO material as
/// if it were marked AUSTEO.
Expand All @@ -130,9 +119,7 @@ void GuardDuplicateCountryCodeUse()
/// <summary>
/// Indicates only appropriately cleared Australian citizens can access the information.
/// Additional citizenships do not preclude access.
///
/// Maps to: CAVEAT=RI:AUSTEO
///
/// Information marked AUSTEO is only passed to, or accessed by, Australian citizens. While a person who has dual
/// Australian citizenship may be given AUSTEO-marked information, in no circumstance may the Australian citizenship
/// requirement be waived.
Expand All @@ -146,21 +133,17 @@ void GuardDuplicateCountryCodeUse()

/// <summary>
/// Originator controlled.
///
/// Maps to: CAVEAT=SH:ORCON
/// </summary>
public bool Orcon { get; init; }

/// <summary>
/// Identifies any information that:
///
/// Maps to: CAVEAT=SH:CABINET
///
/// a. is prepared for the purpose of informing the Cabinet
/// b. reveals the decision and/or deliberations of the Cabinet
/// c. is prepared by departments to brief their ministers on matters proposed for Cabinet consideration
/// d. has been created for the purpose of informing a proposal to be considered by the Cabinet.
///
/// The Cabinet Handbook specifies handling requirements for Cabinet documents. This includes applying a security
/// classification of at least PROTECTED to all Cabinet documents and associated records.
/// </summary>
Expand All @@ -169,7 +152,6 @@ void GuardDuplicateCountryCodeUse()
/// <summary>
/// The NATIONAL CABINET caveat identifies any information that which has been specifically prepared for National
/// Cabinet or its subcommittees.
///
/// Maps to: CAVEAT=SH:NATIONAL-CABINET
/// </summary>
public bool NationalCabinet { get; init; }
Expand Down
3 changes: 1 addition & 2 deletions src/AustralianProtectiveMarkings/Classification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

/// <summary>
/// Corresponds to the PSPF policy: Sensitive and classified information’s classifications.
///
/// https://www.protectivesecurity.gov.au/system/files/2023-01/pspf-policy-08-sensitive-and-classified-information.pdf#C.2
/// </summary>
public enum Classification
Expand All @@ -12,5 +11,5 @@ public enum Classification
OfficialSensitive,
Protected,
Secret,
TopSecret,
TopSecret
}
3 changes: 1 addition & 2 deletions src/AustralianProtectiveMarkings/Country.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,5 @@ public enum Country
/// <summary>
/// Zimbabwe - ZWE
/// </summary>
Zimbabwe,

Zimbabwe
}
5 changes: 2 additions & 3 deletions src/AustralianProtectiveMarkings/CountryCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,7 @@ public static Country GetCodeForLetters(string letters)
},
{
"ZWE", Country.Zimbabwe
},

}
};

static Dictionary<Country, string> codeToLetters = new()
Expand Down Expand Up @@ -1550,6 +1549,6 @@ public static Country GetCodeForLetters(string letters)
},
{
Country.Zimbabwe, "ZWE"
},
}
};
}
2 changes: 1 addition & 1 deletion src/AustralianProtectiveMarkings/DateFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ static class DateFormatter
{
public static bool TryParse(string value, [NotNullWhen(true)] out DateTimeOffset? result)
{
if (!DateTimeOffset.TryParse(value,CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var parsed))
if (!DateTimeOffset.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var parsed))
{
result = null;
return false;
Expand Down
5 changes: 2 additions & 3 deletions src/AustralianProtectiveMarkings/Expiry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public record struct Expiry
{
readonly string? @event;
readonly DateTimeOffset? genDate;

/// <summary>
/// The classification that will be downgraded to when <see cref="Event"/> or <see cref="GenDate"/> occurs.
/// The classification that will be downgraded to when <see cref="Event" /> or <see cref="GenDate" /> occurs.
/// </summary>
public required Classification DownTo { get; init; }

/// <summary>
/// The date that will trigger the classification expiry.
///
/// Maps to: the EXPIRES=genDate
/// </summary>
/// <exception cref="Exception"></exception>
Expand All @@ -39,7 +39,6 @@ public DateTimeOffset? GenDate

/// <summary>
/// The event that will trigger the classification expiry.
///
/// Maps to: the EXPIRES=genDate
/// </summary>
public string? Event
Expand Down
2 changes: 1 addition & 1 deletion src/AustralianProtectiveMarkings/InternalsVisibleTo.cs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[assembly:InternalsVisibleTo("Tests, PublicKey=0024000004800000140100000602000000240000525341310008000001000100355DA8205E1DDA9DAF198048E0472C874B1F33CEA17040443207E4E5B727EB509C61ACC14F4AE1A1A95230E39C5D674F8F7A502BBFE7F5845B28E902B0CC2FC3020FA17B917B14746C8D7B31D6E1E3146D6FB0B403C61D217ABCDF10211777D920E2029A8F56C9049E810FD56984D5DE7478C7DB5E038F75C0FA11E66B69E224E261F9C76D8791E0CABC4A6413545321CD81E78838A75CB3B2F7410C76998503569772410654CD72C8F6B5EF531472FD5B0C37476039FA28107AE839A06E420AF48F472C85D05B795E90FAEDD945B4B860BF1124AF8424D953E8327FDD2972B0BDA33FAF1AAC61D67031940CB9AA12EAEC1669E2E53C52D51B2D9B06E8A2BBC0")]
[assembly: InternalsVisibleTo("Tests, PublicKey=0024000004800000140100000602000000240000525341310008000001000100355DA8205E1DDA9DAF198048E0472C874B1F33CEA17040443207E4E5B727EB509C61ACC14F4AE1A1A95230E39C5D674F8F7A502BBFE7F5845B28E902B0CC2FC3020FA17B917B14746C8D7B31D6E1E3146D6FB0B403C61D217ABCDF10211777D920E2029A8F56C9049E810FD56984D5DE7478C7DB5E038F75C0FA11E66B69E224E261F9C76D8791E0CABC4A6413545321CD81E78838A75CB3B2F7410C76998503569772410654CD72C8F6B5EF531472FD5B0C37476039FA28107AE839A06E420AF48F472C85D05B795E90FAEDD945B4B860BF1124AF8424D953E8327FDD2972B0BDA33FAF1AAC61D67031940CB9AA12EAEC1669E2E53C52D51B2D9B06E8A2BBC0")]
48 changes: 30 additions & 18 deletions src/AustralianProtectiveMarkings/OfficeDocHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ public static bool TryReadProtectiveMarkings(
var document = XDocument.Load(reader);
var root = document.Root!;
var propertyName = root.GetDefaultNamespace() + "property";
var properties = root.Elements(propertyName).ToList();
var property = properties.SingleOrDefault(_ => _.Attribute("name")?.Value == "X-Protective-Marking");
var properties = root
.Elements(propertyName)
.ToList();
var property = properties.SingleOrDefault(_ => _.Attribute("name")
?.Value == "X-Protective-Marking");

if (property == null)
{
Expand Down Expand Up @@ -70,10 +73,13 @@ internal static void EnsureCustomXmlInContentTypes(XDocument document)
{
var root = document.Root!;
var overrideName = root.GetDefaultNamespace() + "Override";
var overrides = root.Elements(overrideName).ToList();
var overrides = root
.Elements(overrideName)
.ToList();

var overrideElement = overrides
.SingleOrDefault(_ => _.Attribute("PartName")?.Value == "/docProps/custom.xml");
.SingleOrDefault(_ => _.Attribute("PartName")
?.Value == "/docProps/custom.xml");

if (overrideElement != null)
{
Expand All @@ -97,9 +103,12 @@ internal static void EnsureCustomXmlInRels(XDocument document)
{
var root = document.Root!;
var relationshipName = root.GetDefaultNamespace() + "Relationship";
var relationships = root.Elements(relationshipName).ToList();
var relationships = root
.Elements(relationshipName)
.ToList();
var overrideElement = relationships
.SingleOrDefault(_ => _.Attribute("Target")?.Value == "docProps/custom.xml");
.SingleOrDefault(_ => _.Attribute("Target")
?.Value == "docProps/custom.xml");

if (overrideElement != null)
{
Expand Down Expand Up @@ -138,16 +147,16 @@ static async Task EnsureCustomPropertyEntry(ZipArchive zip, string header)
using var stream = entry.Open();
using var writer = new StreamWriter(stream);
await writer.WriteAsync($$"""
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
pid="2"
name="X-Protective-Marking">
<vt:lpwstr>{{header}}</vt:lpwstr>
</property>
</Properties>
""");
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"
pid="2"
name="X-Protective-Marking">
<vt:lpwstr>{{header}}</vt:lpwstr>
</property>
</Properties>
""");
}
else
{
Expand All @@ -161,8 +170,11 @@ internal static void SetHeader(XDocument document, string marking)
{
var root = document.Root!;
var propertyName = root.GetDefaultNamespace() + "property";
var properties = root.Elements(propertyName).ToList();
var property = properties.SingleOrDefault(_ => _.Attribute("name")?.Value == "X-Protective-Marking");
var properties = root
.Elements(propertyName)
.ToList();
var property = properties.SingleOrDefault(_ => _.Attribute("name")
?.Value == "X-Protective-Marking");
if (property == null)
{
var maxId = properties
Expand Down
Loading

0 comments on commit 82d4470

Please sign in to comment.