From c6edc019cb767bea9361a5a7e199b07926c327a9 Mon Sep 17 00:00:00 2001 From: George Chakhidze <0xfeeddeadbeef@gmail.com> Date: Fri, 25 Nov 2022 20:02:41 +0400 Subject: [PATCH] Minor code formatting fixes --- src/TBC.OpenBanking.Jws/src/AlgorithmEcdsa.cs | 16 ++++----- .../src/AlgorithmRsaSsa.cs | 34 +++++++++---------- .../src/SupportedAlgorithms.cs | 20 +++++------ .../ConsoleHttpClientExample/Program.cs | 5 ++- .../WebApiHttpClientExample/Program.cs | 31 ++++++++--------- .../WeatherForecast.cs | 17 +++++----- 6 files changed, 59 insertions(+), 64 deletions(-) diff --git a/src/TBC.OpenBanking.Jws/src/AlgorithmEcdsa.cs b/src/TBC.OpenBanking.Jws/src/AlgorithmEcdsa.cs index 670824f..0c2fa85 100644 --- a/src/TBC.OpenBanking.Jws/src/AlgorithmEcdsa.cs +++ b/src/TBC.OpenBanking.Jws/src/AlgorithmEcdsa.cs @@ -34,14 +34,14 @@ namespace TBC.OpenBanking.Jws; /// Table is based on /// /// -/// +--------------+-------------------------------+--------------------+ -/// | "alg" Param | Digital Signature or MAC | Implementation | -/// | Value | Algorithm | Requirements | -/// +--------------+-------------------------------+--------------------+ -/// | ES256 | ECDSA using P-256 and SHA-256 | Recommended+ | -/// | ES384 | ECDSA using P-384 and SHA-384 | Optional | -/// | ES512 | ECDSA using P-521 and SHA-512 | Optional | -/// +--------------+-------------------------------+--------------------+ +/// +--------------+-------------------------------+--------------------+ +/// | "alg" Param | Digital Signature or MAC | Implementation | +/// | Value | Algorithm | Requirements | +/// +--------------+-------------------------------+--------------------+ +/// | ES256 | ECDSA using P-256 and SHA-256 | Recommended+ | +/// | ES384 | ECDSA using P-384 and SHA-384 | Optional | +/// | ES512 | ECDSA using P-521 and SHA-512 | Optional | +/// +--------------+-------------------------------+--------------------+ /// /// public class AlgorithmEcdsa : Algorithm diff --git a/src/TBC.OpenBanking.Jws/src/AlgorithmRsaSsa.cs b/src/TBC.OpenBanking.Jws/src/AlgorithmRsaSsa.cs index 0edf051..2627d32 100644 --- a/src/TBC.OpenBanking.Jws/src/AlgorithmRsaSsa.cs +++ b/src/TBC.OpenBanking.Jws/src/AlgorithmRsaSsa.cs @@ -32,23 +32,23 @@ namespace TBC.OpenBanking.Jws; /// /// Table is based on /// -/// +--------------+-------------------------------+--------------------+ -/// | "alg" Param | Digital Signature or MAC | Implementation | -/// | Value | Algorithm | Requirements | -/// +--------------+-------------------------------+--------------------+ -/// | RS256 | RSASSA-PKCS1-v1_5 using | Recommended | -/// | | SHA-256 | | -/// | RS384 | RSASSA-PKCS1-v1_5 using | Optional | -/// | | SHA-384 | | -/// | RS512 | RSASSA-PKCS1-v1_5 using | Optional | -/// | | SHA-512 | | -/// | PS256 | RSASSA-PSS using SHA-256 and | Optional | -/// | | MGF1 with SHA-256 | | -/// | PS384 | RSASSA-PSS using SHA-384 and | Optional | -/// | | MGF1 with SHA-384 | | -/// | PS512 | RSASSA-PSS using SHA-512 and | Optional | -/// | | MGF1 with SHA-512 | | -/// +--------------+-------------------------------+--------------------+ +/// +--------------+-------------------------------+--------------------+ +/// | "alg" Param | Digital Signature or MAC | Implementation | +/// | Value | Algorithm | Requirements | +/// +--------------+-------------------------------+--------------------+ +/// | RS256 | RSASSA-PKCS1-v1_5 using | Recommended | +/// | | SHA-256 | | +/// | RS384 | RSASSA-PKCS1-v1_5 using | Optional | +/// | | SHA-384 | | +/// | RS512 | RSASSA-PKCS1-v1_5 using | Optional | +/// | | SHA-512 | | +/// | PS256 | RSASSA-PSS using SHA-256 and | Optional | +/// | | MGF1 with SHA-256 | | +/// | PS384 | RSASSA-PSS using SHA-384 and | Optional | +/// | | MGF1 with SHA-384 | | +/// | PS512 | RSASSA-PSS using SHA-512 and | Optional | +/// | | MGF1 with SHA-512 | | +/// +--------------+-------------------------------+--------------------+ /// /// https://tools.ietf.org/html/rfc3447#section-8.2 /// diff --git a/src/TBC.OpenBanking.Jws/src/SupportedAlgorithms.cs b/src/TBC.OpenBanking.Jws/src/SupportedAlgorithms.cs index 618ba62..5cb705c 100644 --- a/src/TBC.OpenBanking.Jws/src/SupportedAlgorithms.cs +++ b/src/TBC.OpenBanking.Jws/src/SupportedAlgorithms.cs @@ -80,17 +80,17 @@ public static class SupportedAlgorithms private static readonly Dictionary> supportedAlgorithms = new(9, StringComparer.OrdinalIgnoreCase) { - [RsaPKCS1Sha256] = cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1), - [RsaPKCS1Sha384] = cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA384, RSASignaturePadding.Pkcs1), - [RsaPKCS1Sha512] = cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA512, RSASignaturePadding.Pkcs1), + [RsaPKCS1Sha256] = static cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1), + [RsaPKCS1Sha384] = static cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA384, RSASignaturePadding.Pkcs1), + [RsaPKCS1Sha512] = static cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA512, RSASignaturePadding.Pkcs1), - [RsaSsaPssSha256] = cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA256, RSASignaturePadding.Pss), - [RsaSsaPssSha384] = cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA384, RSASignaturePadding.Pss), - [RsaSsaPssSha512] = cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA512, RSASignaturePadding.Pss), + [RsaSsaPssSha256] = static cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA256, RSASignaturePadding.Pss), + [RsaSsaPssSha384] = static cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA384, RSASignaturePadding.Pss), + [RsaSsaPssSha512] = static cert => new AlgorithmRsaSsa(cert, HashAlgorithmName.SHA512, RSASignaturePadding.Pss), - [EcdsaSha256] = cert => new AlgorithmEcdsa(cert, HashAlgorithmName.SHA256), - [EcdsaSha384] = cert => new AlgorithmEcdsa(cert, HashAlgorithmName.SHA384), - [EcdsaSha512] = cert => new AlgorithmEcdsa(cert, HashAlgorithmName.SHA512), + [EcdsaSha256] = static cert => new AlgorithmEcdsa(cert, HashAlgorithmName.SHA256), + [EcdsaSha384] = static cert => new AlgorithmEcdsa(cert, HashAlgorithmName.SHA384), + [EcdsaSha512] = static cert => new AlgorithmEcdsa(cert, HashAlgorithmName.SHA512), }; static public bool IsSupportedAlgorithm(string alg) => supportedAlgorithms.ContainsKey(alg); @@ -110,7 +110,6 @@ static public ISigner CreateSigner(X509Certificate2 cert, string alg) if (!supportedAlgorithms.TryGetValue(alg, out var creator)) { - // Error. Unsupported algorithm throw new ArgumentOutOfRangeException(nameof(alg), $"Unsupported algorithm '{alg}'"); } @@ -127,7 +126,6 @@ static public Algorithm CreateVerifier(X509Certificate2 cert, string alg) { if (!supportedAlgorithms.TryGetValue(alg, out var creator)) { - // Error. Unsupported algorithm throw new ArgumentOutOfRangeException(nameof(alg), $"Unsupported algorithm '{alg}'"); } diff --git a/src/examples/ConsoleHttpClientExample/Program.cs b/src/examples/ConsoleHttpClientExample/Program.cs index 7561831..52909fc 100644 --- a/src/examples/ConsoleHttpClientExample/Program.cs +++ b/src/examples/ConsoleHttpClientExample/Program.cs @@ -62,10 +62,9 @@ await Host.CreateDefaultBuilder(args) }) .AddHttpMessageHandler(services => { - var options = services.GetRequiredService>(); - + var options = services.GetRequiredService>(); var loggerFactory = services.GetRequiredService(); - var cache = services.GetRequiredService(); + var cache = services.GetRequiredService(); return new JwsMessageHandler(options, loggerFactory, cache); }); diff --git a/src/examples/WebApiHttpClientExample/Program.cs b/src/examples/WebApiHttpClientExample/Program.cs index 557a599..5c83485 100644 --- a/src/examples/WebApiHttpClientExample/Program.cs +++ b/src/examples/WebApiHttpClientExample/Program.cs @@ -1,20 +1,19 @@ -namespace WebApiHttpClientExample -{ - using Microsoft.AspNetCore.Hosting; - using Microsoft.Extensions.Hosting; +namespace WebApiHttpClientExample; - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); +public static class Program +{ + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(builder => + { + builder.UseStartup(); + }); } diff --git a/src/examples/WebApiHttpClientExample/WeatherForecast.cs b/src/examples/WebApiHttpClientExample/WeatherForecast.cs index 45864f9..9c2af44 100644 --- a/src/examples/WebApiHttpClientExample/WeatherForecast.cs +++ b/src/examples/WebApiHttpClientExample/WeatherForecast.cs @@ -1,15 +1,14 @@ -using System; +using System; -namespace WebApiHttpClientExample +namespace WebApiHttpClientExample; + +public class WeatherForecast { - public class WeatherForecast - { - public DateTime Date { get; set; } + public DateTime Date { get; set; } - public int TemperatureC { get; set; } + public int TemperatureC { get; set; } - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - public string Summary { get; set; } - } + public string Summary { get; set; } }