From 738005f5dc84c81ae22446b717a4de89081ee703 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Thu, 5 Dec 2024 14:33:24 +0100 Subject: [PATCH] feat(RSACryptographerList): Die Ausgabe der Indexer-Methode ist nicht null und wirft eine Ausnahme, wenn sie nicht gefunden wird. --- .../Cryptographer/CryptographerExtensions.cs | 7 +------ .../Cryptographer/RSACryptographerList.cs | 4 +++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/DigitalData.Core.Security/Cryptographer/CryptographerExtensions.cs b/DigitalData.Core.Security/Cryptographer/CryptographerExtensions.cs index 4452007..72f58e0 100644 --- a/DigitalData.Core.Security/Cryptographer/CryptographerExtensions.cs +++ b/DigitalData.Core.Security/Cryptographer/CryptographerExtensions.cs @@ -10,7 +10,7 @@ public static TRSACryptographer Get(this IEnumerable 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}"); + ?? 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 : RSACryptographer { @@ -20,10 +20,5 @@ public static RSACryptographerList ToCryptographerList(this IEnumerable cryptographers, Func keyGenerator) where TRSACryptographer : RSACryptographer => new(keyGenerator: keyGenerator, cryptographers: cryptographers); - - private static string GetTypeName(this IEnumerable cryptographers) where TRSACryptographer : RSACryptographer - => typeof(TRSACryptographer).GetType().Name.TrimStart(InterfaceIdentifierChar); - - private static readonly char InterfaceIdentifierChar = 'I'; } } \ No newline at end of file diff --git a/DigitalData.Core.Security/Cryptographer/RSACryptographerList.cs b/DigitalData.Core.Security/Cryptographer/RSACryptographerList.cs index e4c4272..f7ab7a7 100644 --- a/DigitalData.Core.Security/Cryptographer/RSACryptographerList.cs +++ b/DigitalData.Core.Security/Cryptographer/RSACryptographerList.cs @@ -15,7 +15,9 @@ namespace DigitalData.Core.Security.Cryptographer _cryptographers = cryptographers; } - public TRSACryptographer? this[string key] => _cryptographers.SingleOrDefault(crypt => _keyGenerator(crypt) == key); + public TRSACryptographer this[string key] + => _cryptographers.SingleOrDefault(crypt => _keyGenerator(crypt) == key) + ?? throw new InvalidOperationException($"No {typeof(TRSACryptographer).GetType().Name.TrimStart('I')} found with Key: {key}."); public IEnumerator GetEnumerator() => _cryptographers.GetEnumerator();