From fb5b3611ada0ab7073170749f321d537fe40a28e Mon Sep 17 00:00:00 2001 From: Sascha Kiefer Date: Mon, 6 Jan 2025 16:08:17 +0100 Subject: [PATCH] Satisfy tests, remove obsolete overload --- csharp/Svix/Utils.cs | 7 ------- csharp/Svix/Webhook.cs | 33 +++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/csharp/Svix/Utils.cs b/csharp/Svix/Utils.cs index 4cf0a7c86..207ab4199 100644 --- a/csharp/Svix/Utils.cs +++ b/csharp/Svix/Utils.cs @@ -5,13 +5,6 @@ namespace Svix { internal static class Utils { - public static bool SecureCompare(string a, string b) - { - ArgumentNullException.ThrowIfNull(a); - ArgumentNullException.ThrowIfNull(b); - return SecureCompare(a.AsSpan(), b.AsSpan()); - } - // Borrowed from Stripe-dotnet https://github.com/stripe/stripe-dotnet/blob/7b62c461d7c0cf2c9e06dce5e564b374a9d232e0/src/Stripe.net/Infrastructure/StringUtils.cs#L30 // basically identical to SecureCompare from Rails::ActiveSupport used in our ruby lib [MethodImpl(MethodImplOptions.NoOptimization)] diff --git a/csharp/Svix/Webhook.cs b/csharp/Svix/Webhook.cs index 0d6546056..3de8ed55f 100644 --- a/csharp/Svix/Webhook.cs +++ b/csharp/Svix/Webhook.cs @@ -43,25 +43,38 @@ public Webhook(byte[] key) public void Verify(ReadOnlySpan payload, WebHeaderCollection headers) { - ArgumentNullException.ThrowIfNull(headers); + if (payload == null) + { + throw new ArgumentNullException(nameof(payload)); + } + if (headers == null) + { + throw new ArgumentNullException(nameof(headers)); + } Verify(payload, headers.Get); } - public void Verify(string payload, Func headersProvider) + public void Verify(ReadOnlySpan payload, Func headersProvider) { - ArgumentNullException.ThrowIfNull(payload); - ArgumentNullException.ThrowIfNull(headersProvider); + if (payload == null) + { + throw new ArgumentNullException(nameof(payload)); + } + if (headersProvider == null) + { + throw new ArgumentNullException(nameof(headersProvider)); + } - ReadOnlySpan msgId = headerProvider(SVIX_ID_HEADER_KEY); - ReadOnlySpan msgTimestamp = headerProvider(SVIX_TIMESTAMP_HEADER_KEY); - ReadOnlySpan msgSignature = headerProvider(SVIX_SIGNATURE_HEADER_KEY); + ReadOnlySpan msgId = headersProvider(SVIX_ID_HEADER_KEY); + ReadOnlySpan msgTimestamp = headersProvider(SVIX_TIMESTAMP_HEADER_KEY); + ReadOnlySpan msgSignature = headersProvider(SVIX_SIGNATURE_HEADER_KEY); if (msgId.IsEmpty || msgSignature.IsEmpty || msgTimestamp.IsEmpty) { - msgId = headerProvider(UNBRANDED_ID_HEADER_KEY); - msgSignature = headerProvider(UNBRANDED_SIGNATURE_HEADER_KEY); - msgTimestamp = headerProvider(UNBRANDED_TIMESTAMP_HEADER_KEY); + msgId = headersProvider(UNBRANDED_ID_HEADER_KEY); + msgSignature = headersProvider(UNBRANDED_SIGNATURE_HEADER_KEY); + msgTimestamp = headersProvider(UNBRANDED_TIMESTAMP_HEADER_KEY); if (msgId.IsEmpty || msgSignature.IsEmpty || msgTimestamp.IsEmpty) { throw new WebhookVerificationException("Missing Required Headers");