Skip to content

Commit

Permalink
Minor code formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfeeddeadbeef committed Nov 25, 2022
1 parent 1f43c16 commit c6edc01
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 64 deletions.
16 changes: 8 additions & 8 deletions src/TBC.OpenBanking.Jws/src/AlgorithmEcdsa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ namespace TBC.OpenBanking.Jws;
/// Table is based on <see href="https://tools.ietf.org/html/rfc7518#section-3.1"/>
/// </para>
/// <code>
/// +--------------+-------------------------------+--------------------+
/// | "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 |
/// +--------------+-------------------------------+--------------------+
/// </code>
/// </summary>
public class AlgorithmEcdsa : Algorithm
Expand Down
34 changes: 17 additions & 17 deletions src/TBC.OpenBanking.Jws/src/AlgorithmRsaSsa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ namespace TBC.OpenBanking.Jws;
/// <summary>
/// Table is based on <see href="https://tools.ietf.org/html/rfc7518#section-3.1"/>
/// <code>
/// <para>+--------------+-------------------------------+--------------------+</para>
/// <para>| "alg" Param | Digital Signature or MAC | Implementation |</para>
/// <para>| Value | Algorithm | Requirements |</para>
/// <para>+--------------+-------------------------------+--------------------+</para>
/// <para>| RS256 | RSASSA-PKCS1-v1_5 using | Recommended |</para>
/// <para>| | SHA-256 | |</para>
/// <para>| RS384 | RSASSA-PKCS1-v1_5 using | Optional |</para>
/// <para>| | SHA-384 | |</para>
/// <para>| RS512 | RSASSA-PKCS1-v1_5 using | Optional |</para>
/// <para>| | SHA-512 | |</para>
/// <para>| PS256 | RSASSA-PSS using SHA-256 and | Optional |</para>
/// <para>| | MGF1 with SHA-256 | |</para>
/// <para>| PS384 | RSASSA-PSS using SHA-384 and | Optional |</para>
/// <para>| | MGF1 with SHA-384 | |</para>
/// <para>| PS512 | RSASSA-PSS using SHA-512 and | Optional |</para>
/// <para>| | MGF1 with SHA-512 | |</para>
/// <para>+--------------+-------------------------------+--------------------+</para>
/// +--------------+-------------------------------+--------------------+
/// | "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 | |
/// +--------------+-------------------------------+--------------------+
/// </code>
/// https://tools.ietf.org/html/rfc3447#section-8.2
/// </summary>
Expand Down
20 changes: 9 additions & 11 deletions src/TBC.OpenBanking.Jws/src/SupportedAlgorithms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ public static class SupportedAlgorithms

private static readonly Dictionary<string, Func<X509Certificate2, Algorithm>> 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);
Expand All @@ -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}'");
}

Expand All @@ -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}'");
}

Expand Down
5 changes: 2 additions & 3 deletions src/examples/ConsoleHttpClientExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ await Host.CreateDefaultBuilder(args)
})
.AddHttpMessageHandler(services =>
{
var options = services.GetRequiredService<IOptions<JwsClientOptions>>();

var options = services.GetRequiredService<IOptions<JwsClientOptions>>();
var loggerFactory = services.GetRequiredService<ILoggerFactory>();
var cache = services.GetRequiredService<IMemoryCache>();
var cache = services.GetRequiredService<IMemoryCache>();

return new JwsMessageHandler(options, loggerFactory, cache);
});
Expand Down
31 changes: 15 additions & 16 deletions src/examples/WebApiHttpClientExample/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Startup>();
});
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<Startup>();
});
}
17 changes: 8 additions & 9 deletions src/examples/WebApiHttpClientExample/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -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; }
}

0 comments on commit c6edc01

Please sign in to comment.