-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
214 additions
and
62 deletions.
There are no files selected for viewing
18 changes: 0 additions & 18 deletions
18
src/Nager.EmailAuthentication.UnitTest/DkimHeaderParserTests/BasicTest.cs
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/Nager.EmailAuthentication.UnitTest/DkimPublicKeyRecordParserTests/BasicTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Nager.EmailAuthentication.UnitTest.DkimPublicKeyRecordParserTests | ||
{ | ||
[TestClass] | ||
public sealed class BasicTest | ||
{ | ||
[TestMethod] | ||
public void TryParse_ValidDkimHeaderString1_ReturnsTrueAndPopulatesDataFragment() | ||
{ | ||
var dkimPublicKeyRecord = "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuu8v3TAGlg2cKEVtHbqh5QfebUSdVp2qwH4NFaIG/rEsBshHI97fdP6TqiJCmpLhK8mHSQMit2HiHAEUApa0xAw7SI68XiBr6epKpTkHaUx27C/kjyuxYmGFOJy6mrDzeC2E5+Lp1u9QifjuBtUk78ORSA+EXeEMxssHy51NdHT0BlZGk1M+wXTxniQ2d198gDVjjqRGM433Q0AP6uSJac9LQj80tHkWrnr/bjct7EOdtF+6mDl4qjAaJTruk03Xt3Alaj+DIOPmnwP1mbPLQmK4blnzM7jwQc2kZz9gSJocc0nhs8KfuR6Xj23iSOJV+WEt6WoLoJzSl8/Dx5CKJwIDAQAB"; | ||
|
||
var isSuccessful = DkimPublicKeyRecordParser.TryParse(dkimPublicKeyRecord, out var dkimPublicKeyRecordDataFragment, out var parsingResults); | ||
|
||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dkimPublicKeyRecordDataFragment); | ||
//Assert.IsNull(parsingResults, "ParsingResults is not null"); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Nager.EmailAuthentication.UnitTest/DkimSignatureParserTests/BasicTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Nager.EmailAuthentication.UnitTest.DkimSignatureParserTests | ||
{ | ||
[TestClass] | ||
public sealed class BasicTest | ||
{ | ||
[TestMethod] | ||
public void TryParse_ValidDkimHeaderString1_ReturnsTrueAndPopulatesDataFragment() | ||
{ | ||
var dkimSignature = "v=1; a=rsa-sha256; c=relaxed/simple; q=dns/txt; d=domain.com; [email protected]; s=mailjet; x=1737017824; h=message-id:from:from:reply-to:to:to:subject:subject:date:date:list-unsubscribe-post:list-unsubscribe:feedback-id:x-csa-complaints:x-mj-mid:x-report-abuse-to:mime-version:content-type; bh=TyN/x6t3AOfI298rgJAgZHgdWcq/XLISGen5nN3NLAc=; b=HLCLiikV92Ku/k9mGlZM0bmqPjKggGnMI0igqhXmPRzPJUC+5SUWRS6/FLUpxbX6AUGJRDYQnKKMtp6uZkYVuKG8SPZ01cUkvIiiAkczb4bK6IVvPbZOnsWqHkD6EvK3TrpIhgFfGLlcG+zIwgdDZ3O++uhpJkIX1WJlkXZYqxQ="; | ||
|
||
var isSuccessful = DkimSignatureParser.TryParse(dkimSignature, out var dkimSignatureDataFragment, out var parsingResults); | ||
|
||
Assert.IsTrue(isSuccessful); | ||
Assert.IsNotNull(dkimSignatureDataFragment); | ||
//Assert.IsNull(parsingResults, "ParsingResults is not null"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/Nager.EmailAuthentication/DkimPublicKeyRecordParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Nager.EmailAuthentication.Handlers; | ||
using Nager.EmailAuthentication.Models; | ||
|
||
namespace Nager.EmailAuthentication | ||
{ | ||
/// <summary> | ||
/// Dkim Public Key Record Parser | ||
/// </summary> | ||
public static class DkimPublicKeyRecordParser | ||
{ | ||
/// <summary> | ||
/// TryParse | ||
/// </summary> | ||
/// <param name="dkimPublicKeyRecord"></param> | ||
/// <param name="dkimPublicKeyRecordDataFragment"></param> | ||
/// <returns></returns> | ||
public static bool TryParse( | ||
string dkimPublicKeyRecord, | ||
out DkimPublicKeyRecordDataFragment? dkimPublicKeyRecordDataFragment) | ||
{ | ||
return TryParse(dkimPublicKeyRecord, out dkimPublicKeyRecordDataFragment, out _); | ||
} | ||
|
||
/// <summary> | ||
/// TryParse | ||
/// </summary> | ||
/// <param name="dkimPublicKeyRecord"></param> | ||
/// <param name="dkimPublicKeyRecordDataFragment"></param> | ||
/// <param name="parsingResults"></param> | ||
/// <returns></returns> | ||
public static bool TryParse( | ||
string dkimPublicKeyRecord, | ||
out DkimPublicKeyRecordDataFragment? dkimPublicKeyRecordDataFragment, | ||
out ParsingResult[]? parsingResults) | ||
{ | ||
var handlers = new Dictionary<string, MappingHandler<DkimPublicKeyRecordDataFragment>> | ||
{ | ||
{ | ||
"v", new MappingHandler<DkimPublicKeyRecordDataFragment> | ||
{ | ||
Map = (dataFragment, value) => dataFragment.Version = value, | ||
} | ||
}, | ||
{ | ||
"p", new MappingHandler<DkimPublicKeyRecordDataFragment> | ||
{ | ||
Map = (dataFragment, value) => dataFragment.PublicKeyData = value, | ||
} | ||
}, | ||
{ | ||
"n", new MappingHandler<DkimPublicKeyRecordDataFragment> | ||
{ | ||
Map = (dataFragment, value) => dataFragment.Notes = value | ||
} | ||
}, | ||
{ | ||
"k", new MappingHandler<DkimPublicKeyRecordDataFragment> | ||
{ | ||
Map = (dataFragment, value) => dataFragment.KeyType = value | ||
} | ||
}, | ||
{ | ||
"g", new MappingHandler<DkimPublicKeyRecordDataFragment> | ||
{ | ||
Map = (dataFragment, value) => dataFragment.Granularity = value | ||
} | ||
}, | ||
{ | ||
"t", new MappingHandler<DkimPublicKeyRecordDataFragment> | ||
{ | ||
Map = (dataFragment, value) => dataFragment.Flags = value | ||
} | ||
}, | ||
}; | ||
|
||
var parserBase = new KeyValueParserBase<DkimPublicKeyRecordDataFragment>(handlers); | ||
return parserBase.TryParse(dkimPublicKeyRecord, out dkimPublicKeyRecordDataFragment, out parsingResults); | ||
} | ||
} | ||
} |
61 changes: 39 additions & 22 deletions
61
...r.EmailAuthentication/DkimHeaderParser.cs → ...mailAuthentication/DkimSignatureParser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ger.EmailAuthentication/MappingHandler.cs → ...Authentication/Handlers/MappingHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.