using DigitalData.Core.Abstractions.Security; namespace DigitalData.Core.Security.Cryptographer { //TODO: Create seperated extensions project public static class CryptographerExtensions { public static IEnumerable GetByIssuer(this IEnumerable cryptographers, string issuer) where TRSACryptographer: IRSACryptographer => cryptographers.Where(c => c.Issuer == issuer); public static IEnumerable GetByAudience(this IEnumerable cryptographers, string audience) where TRSACryptographer : IRSACryptographer => cryptographers.Where(c => c.Audience == audience); public static TRSACryptographer Get(this IEnumerable cryptographers, string issuer, string audience) where TRSACryptographer : IRSACryptographer => 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}."); public static bool TryGet(this IEnumerable cryptographers, string issuer, string audience, out TRSACryptographer? cryptographer) where TRSACryptographer : IRSACryptographer { cryptographer = cryptographers.SingleOrDefault(c => c.Issuer == issuer && c.Audience == audience); return cryptographer is not null; } public static RSACryptographerList ToCryptographerList(this IEnumerable cryptographers, Func keyGenerator) where TRSACryptographer : IRSACryptographer => new(keyGenerator: keyGenerator, cryptographers: cryptographers); } }