diff --git a/src/WebEid.Security.Tests/Validator/VersionValidators/AuthTokenVersion1ValidatorTest.cs b/src/WebEid.Security.Tests/Validator/VersionValidators/AuthTokenVersion1ValidatorTest.cs index 87e958a..12cb1f1 100644 --- a/src/WebEid.Security.Tests/Validator/VersionValidators/AuthTokenVersion1ValidatorTest.cs +++ b/src/WebEid.Security.Tests/Validator/VersionValidators/AuthTokenVersion1ValidatorTest.cs @@ -84,9 +84,6 @@ public void SetUp() [TestCase("web-eid:1")] [TestCase("web-eid:1.0")] - [TestCase("web-eid:1.1")] - [TestCase("web-eid:1.10")] - [TestCase("web-eid:1.999")] public void WhenFormatIsValidMajorV1FormatThenSupportsReturnsTrue(string format) => Assert.That(validator.Supports(format), Is.True); @@ -95,7 +92,11 @@ public void WhenFormatIsValidMajorV1FormatThenSupportsReturnsTrue(string format) [TestCase("web-eid")] [TestCase("web-eid:1.")] [TestCase("web-eid:1.0TEST")] + [TestCase("web-eid:1.1")] [TestCase("web-eid:1.1.0")] + [TestCase("web-eid:1.2")] + [TestCase("web-eid:1.10")] + [TestCase("web-eid:1.999")] [TestCase("web-eid:0.9")] [TestCase("web-eid:2")] [TestCase("webauthn:1")] diff --git a/src/WebEid.Security/Validator/VersionValidators/AuthTokenVersion11Validator.cs b/src/WebEid.Security/Validator/VersionValidators/AuthTokenVersion11Validator.cs index feec139..3d0d55d 100644 --- a/src/WebEid.Security/Validator/VersionValidators/AuthTokenVersion11Validator.cs +++ b/src/WebEid.Security/Validator/VersionValidators/AuthTokenVersion11Validator.cs @@ -25,7 +25,6 @@ namespace WebEid.Security.Validator.VersionValidators using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; - using System.Text.RegularExpressions; using System.Threading.Tasks; using AuthToken; using CertValidators; @@ -40,10 +39,9 @@ namespace WebEid.Security.Validator.VersionValidators /// Validator for token format web-eid:1.1. /// Extends V1 validator with additional checks for signing certificate + supported algorithms. /// - public sealed partial class AuthTokenVersion11Validator : AuthTokenVersion1Validator + public sealed class AuthTokenVersion11Validator : AuthTokenVersion1Validator { - [GeneratedRegex(@"^web-eid:1\.1$", RegexOptions.IgnoreCase)] - private static partial Regex V11SupportedTokenFormatPattern(); + private const string V11_SUPPORTED_TOKEN_FORMAT = "web-eid:1.1"; private static readonly HashSet SupportedSigningCryptoAlgorithms = new(StringComparer.OrdinalIgnoreCase) @@ -97,9 +95,11 @@ internal AuthTokenVersion11Validator( this.logger = logger; } - /// - protected override Regex GetSupportedFormatPattern() => - V11SupportedTokenFormatPattern(); + /// + /// Determines whether this validator supports the specified token format. + /// + public override bool Supports(string format) => + format == V11_SUPPORTED_TOKEN_FORMAT; /// /// Validates a Web eID authentication token in format web-eid:1.1 diff --git a/src/WebEid.Security/Validator/VersionValidators/AuthTokenVersion1Validator.cs b/src/WebEid.Security/Validator/VersionValidators/AuthTokenVersion1Validator.cs index 425bff1..c3ecab1 100644 --- a/src/WebEid.Security/Validator/VersionValidators/AuthTokenVersion1Validator.cs +++ b/src/WebEid.Security/Validator/VersionValidators/AuthTokenVersion1Validator.cs @@ -23,7 +23,6 @@ namespace WebEid.Security.Validator.VersionValidators { using System; using System.Security.Cryptography.X509Certificates; - using System.Text.RegularExpressions; using System.Threading.Tasks; using AuthToken; using CertValidators; @@ -39,9 +38,6 @@ public partial class AuthTokenVersion1Validator : IAuthTokenVersionValidator { private const string V1_SUPPORTED_TOKEN_FORMAT_PREFIX = "web-eid:1"; - [GeneratedRegex(@"^web-eid:1(?:\.\d+)?$", RegexOptions.IgnoreCase)] - private static partial Regex V1SupportedTokenFormatPattern(); - private readonly SubjectCertificateValidatorBatch simpleSubjectCertificateValidators; private readonly AuthTokenSignatureValidator signatureValidator; private readonly AuthTokenValidationConfiguration configuration; @@ -72,14 +68,8 @@ internal AuthTokenVersion1Validator( /// Determines whether this validator supports the specified token format. /// public virtual bool Supports(string format) => - format != null && - GetSupportedFormatPattern().IsMatch(format); - - /// - /// Gets the supported token format pattern for this validator. - /// - protected virtual Regex GetSupportedFormatPattern() => - V1SupportedTokenFormatPattern(); + format == V1_SUPPORTED_TOKEN_FORMAT_PREFIX || + format == "web-eid:1.0"; /// /// Validates a Web eID authentication token and returns the authenticated user's certificate.