feat(CryptographerExtensions): Erstellt Erweiterungen zum Suchen und Erstellen von RSACryptographerList.
This commit is contained in:
parent
35e2fef046
commit
c96af25e23
@ -0,0 +1,29 @@
|
|||||||
|
namespace DigitalData.Core.Security.Cryptographer
|
||||||
|
{
|
||||||
|
public static class CryptographerExtensions
|
||||||
|
{
|
||||||
|
public static IEnumerable<TRSACryptographer> GetByIssuer<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string issuer) where TRSACryptographer: RSACryptographer
|
||||||
|
=> cryptographers.Where(c => c.Issuer == issuer);
|
||||||
|
|
||||||
|
public static IEnumerable<TRSACryptographer> GetByAudience<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string audience) where TRSACryptographer : RSACryptographer
|
||||||
|
=> cryptographers.Where(c => c.Audience == audience);
|
||||||
|
|
||||||
|
public static TRSACryptographer Get<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string issuer, string audience) where TRSACryptographer : RSACryptographer
|
||||||
|
=> cryptographers.Where(c => c.Issuer == issuer && c.Audience == audience).SingleOrDefault()
|
||||||
|
?? throw new InvalidOperationException($"No {cryptographers.GetTypeName()} found with Issuer: {issuer} and Audience: {audience}");
|
||||||
|
|
||||||
|
public static bool TryGet<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string issuer, string audience, out TRSACryptographer? cryptographer) where TRSACryptographer : RSACryptographer
|
||||||
|
{
|
||||||
|
cryptographer = cryptographers.Where(c => c.Issuer == issuer && c.Audience == audience).SingleOrDefault();
|
||||||
|
return cryptographer is not null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RSACryptographerList<TRSACryptographer> ToCryptographerList<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, Func<TRSACryptographer, string> keyGenerator) where TRSACryptographer : RSACryptographer
|
||||||
|
=> new(keyGenerator: keyGenerator, cryptographers: cryptographers);
|
||||||
|
|
||||||
|
private static string GetTypeName<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers) where TRSACryptographer : RSACryptographer
|
||||||
|
=> typeof(TRSACryptographer).GetType().Name.TrimStart(InterfaceIdentifierChar);
|
||||||
|
|
||||||
|
private static readonly char InterfaceIdentifierChar = 'I';
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user