refactor(CryptographerExtensions): Aktualisiert, um IRSACryptographer anstelle von RSACryptographer zu verwenden, um die Abstraktion zu erhöhen.
This commit is contained in:
parent
b8a4a1f2b5
commit
baf1f5e045
@ -1,24 +1,26 @@
|
|||||||
namespace DigitalData.Core.Security.Cryptographer
|
using DigitalData.Core.Abstractions.Security;
|
||||||
|
|
||||||
|
namespace DigitalData.Core.Security.Cryptographer
|
||||||
{
|
{
|
||||||
public static class CryptographerExtensions
|
public static class CryptographerExtensions
|
||||||
{
|
{
|
||||||
public static IEnumerable<TRSACryptographer> GetByIssuer<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string issuer) where TRSACryptographer: RSACryptographer
|
public static IEnumerable<TRSACryptographer> GetByIssuer<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string issuer) where TRSACryptographer: IRSACryptographer
|
||||||
=> cryptographers.Where(c => c.Issuer == issuer);
|
=> cryptographers.Where(c => c.Issuer == issuer);
|
||||||
|
|
||||||
public static IEnumerable<TRSACryptographer> GetByAudience<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string audience) where TRSACryptographer : RSACryptographer
|
public static IEnumerable<TRSACryptographer> GetByAudience<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string audience) where TRSACryptographer : IRSACryptographer
|
||||||
=> cryptographers.Where(c => c.Audience == audience);
|
=> cryptographers.Where(c => c.Audience == audience);
|
||||||
|
|
||||||
public static TRSACryptographer Get<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string issuer, string audience) where TRSACryptographer : RSACryptographer
|
public static TRSACryptographer Get<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string issuer, string audience) where TRSACryptographer : IRSACryptographer
|
||||||
=> cryptographers.Where(c => c.Issuer == issuer && c.Audience == audience).SingleOrDefault()
|
=> cryptographers.Where(c => c.Issuer == issuer && c.Audience == audience).SingleOrDefault()
|
||||||
?? throw new InvalidOperationException($"No {typeof(TRSACryptographer).GetType().Name.TrimStart('I')} found with Issuer: {issuer} and Audience: {audience}.");
|
?? throw new InvalidOperationException($"No {typeof(TRSACryptographer).GetType().Name.TrimStart('I')} 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
|
public static bool TryGet<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, string issuer, string audience, out TRSACryptographer? cryptographer) where TRSACryptographer : IRSACryptographer
|
||||||
{
|
{
|
||||||
cryptographer = cryptographers.SingleOrDefault(c => c.Issuer == issuer && c.Audience == audience);
|
cryptographer = cryptographers.SingleOrDefault(c => c.Issuer == issuer && c.Audience == audience);
|
||||||
return cryptographer is not null;
|
return cryptographer is not null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RSACryptographerList<TRSACryptographer> ToCryptographerList<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, Func<TRSACryptographer, string> keyGenerator) where TRSACryptographer : RSACryptographer
|
public static RSACryptographerList<TRSACryptographer> ToCryptographerList<TRSACryptographer>(this IEnumerable<TRSACryptographer> cryptographers, Func<TRSACryptographer, string> keyGenerator) where TRSACryptographer : IRSACryptographer
|
||||||
=> new(keyGenerator: keyGenerator, cryptographers: cryptographers);
|
=> new(keyGenerator: keyGenerator, cryptographers: cryptographers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user