Skip to content

Commit

Permalink
Update (#30)
Browse files Browse the repository at this point in the history
* All algorithm constructors are private now
  • Loading branch information
nd1012 authored Feb 24, 2024
1 parent 1a4847a commit 2d3f519
Show file tree
Hide file tree
Showing 56 changed files with 127 additions and 126 deletions.
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC Tests/wan24-Crypto-BC Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="coverlet.collector" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="wan24-Crypto-Shared-Tests" Version="2.1.3" />
<PackageReference Include="wan24-Crypto-Shared-Tests" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricBcEcDiffieHellmanAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -44,7 +44,7 @@ public sealed record class AsymmetricBcEcDiffieHellmanAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -54,12 +54,12 @@ public sealed record class AsymmetricBcEcDiffieHellmanAlgorithm
256,
384,
521
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricBcEcDiffieHellmanAlgorithm()
private AsymmetricBcEcDiffieHellmanAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: true, _AllowedKeySizes, isPostQuantum: false, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricBcEcDsaAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -44,7 +44,7 @@ public sealed record class AsymmetricBcEcDsaAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -54,12 +54,12 @@ public sealed record class AsymmetricBcEcDsaAlgorithm
256,
384,
521
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricBcEcDsaAlgorithm()
private AsymmetricBcEcDsaAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: true, _AllowedKeySizes, isPostQuantum: true, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricBikeAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Org.BouncyCastle.Pqc.Crypto.Bike;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public sealed record class AsymmetricBikeAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -52,12 +52,12 @@ public sealed record class AsymmetricBikeAlgorithm
128,// 128 bit security
192,// 192 bit security
256// 256 bit security
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricBikeAlgorithm()
private AsymmetricBikeAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: false, _AllowedKeySizes, isPostQuantum: true, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricDilithiumAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Org.BouncyCastle.Pqc.Crypto.Crystals.Dilithium;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public sealed record class AsymmetricDilithiumAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -52,12 +52,12 @@ public sealed record class AsymmetricDilithiumAlgorithm
512,// 128 bit security
768,// 192 bit security
1024// 256 bit security
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricDilithiumAlgorithm()
private AsymmetricDilithiumAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: false, _AllowedKeySizes, isPostQuantum: true, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricEd25519Algorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using System.Collections.ObjectModel;
using System.Collections.Frozen;
using wan24.Core;

namespace wan24.Crypto.BC
Expand Down Expand Up @@ -46,20 +46,20 @@ public sealed record class AsymmetricEd25519Algorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
/// </summary>
static AsymmetricEd25519Algorithm() => _AllowedKeySizes = new List<int>()
{
256
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricEd25519Algorithm()
private AsymmetricEd25519Algorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: true, _AllowedKeySizes, isPostQuantum: false, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricEd448Algorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using System.Collections.ObjectModel;
using System.Collections.Frozen;
using wan24.Core;

namespace wan24.Crypto.BC
Expand Down Expand Up @@ -46,7 +46,7 @@ public sealed record class AsymmetricEd448Algorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -55,12 +55,12 @@ public sealed record class AsymmetricEd448Algorithm
{
448,
456
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricEd448Algorithm()
private AsymmetricEd448Algorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: true, _AllowedKeySizes, isPostQuantum: false, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricFalconAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Org.BouncyCastle.Pqc.Crypto.Falcon;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public sealed record class AsymmetricFalconAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -51,12 +51,12 @@ public sealed record class AsymmetricFalconAlgorithm
{
512,// 128 bit security
1024// 224 bit security
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricFalconAlgorithm()
private AsymmetricFalconAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: false, _AllowedKeySizes, isPostQuantum: true, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricFrodoKemAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Org.BouncyCastle.Pqc.Crypto.Frodo;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public sealed record class AsymmetricFrodoKemAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -52,12 +52,12 @@ public sealed record class AsymmetricFrodoKemAlgorithm
128,
192,
256
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricFrodoKemAlgorithm()
private AsymmetricFrodoKemAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: false, _AllowedKeySizes, isPostQuantum: true, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricHqcAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Org.BouncyCastle.Pqc.Crypto.Hqc;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public sealed record class AsymmetricHqcAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -52,12 +52,12 @@ public sealed record class AsymmetricHqcAlgorithm
128,// 128 bit security
192,// 192 bit security
256// 256 bit security
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricHqcAlgorithm()
private AsymmetricHqcAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: false, _AllowedKeySizes, isPostQuantum: true, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricKyberAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Org.BouncyCastle.Pqc.Crypto.Crystals.Kyber;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public sealed record class AsymmetricKyberAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -52,12 +52,12 @@ public sealed record class AsymmetricKyberAlgorithm
512,// 128 bit security
768,// 192 bit security
1024// 256 bit security
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricKyberAlgorithm()
private AsymmetricKyberAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: false, _AllowedKeySizes, isPostQuantum: true, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricNtruEncryptAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Org.BouncyCastle.Pqc.Crypto.Ntru;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public sealed record class AsymmetricNtruEncryptAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -53,12 +53,12 @@ public sealed record class AsymmetricNtruEncryptAlgorithm
677,// 192 bit security
701,// 256 bit security
821// 123 bit security
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricNtruEncryptAlgorithm()
private AsymmetricNtruEncryptAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: false, _AllowedKeySizes, isPostQuantum: true, DEFAULT_KEY_SIZE)
{ }

Expand Down
8 changes: 4 additions & 4 deletions src/wan24-Crypto-BC/AsymmetricPicnicAlgorithm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Org.BouncyCastle.Pqc.Crypto.Picnic;
using System.Collections.ObjectModel;
using System.Collections.Frozen;

namespace wan24.Crypto.BC
{
Expand Down Expand Up @@ -42,7 +42,7 @@ public sealed record class AsymmetricPicnicAlgorithm
/// <summary>
/// Allowed key sizes in bits
/// </summary>
private static readonly ReadOnlyCollection<int> _AllowedKeySizes;
private static readonly FrozenSet<int> _AllowedKeySizes;

/// <summary>
/// Static constructor
Expand All @@ -52,12 +52,12 @@ public sealed record class AsymmetricPicnicAlgorithm
128,// 128 bit security
192,// 192 bit security
256// 256 bit security
}.AsReadOnly();
}.ToFrozenSet();

/// <summary>
/// Constructor
/// </summary>
public AsymmetricPicnicAlgorithm()
private AsymmetricPicnicAlgorithm()
: base(ALGORITHM_NAME, ALGORITHM_VALUE, USAGES, isEllipticCurveAlgorithm: false, _AllowedKeySizes, isPostQuantum: true, DEFAULT_KEY_SIZE)
{ }

Expand Down
Loading

0 comments on commit 2d3f519

Please sign in to comment.