diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 6e47d26..e57f82b 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -22,7 +22,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/Directory.Build.props b/Directory.Build.props index ae85c83..ca9b138 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,15 @@ - 9.5.1 - 9.5.1 - 9.5.1 + net9.0 + 13 + enable + true + ONIXLabs + en + Copyright © ONIXLabs 2020 + https://github.com/onix-labs/onixlabs-dotnet + 10.0.0 + 10.0.0 + 10.0.0 diff --git a/OnixLabs.Core.UnitTests.Data/BufferSegment.cs b/OnixLabs.Core.UnitTests.Data/BufferSegment.cs index 277e3b2..24fa24c 100644 --- a/OnixLabs.Core.UnitTests.Data/BufferSegment.cs +++ b/OnixLabs.Core.UnitTests.Data/BufferSegment.cs @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Buffers; +using System.Linq; namespace OnixLabs.Core.UnitTests.Data; diff --git a/OnixLabs.Core.UnitTests.Data/Disposable.cs b/OnixLabs.Core.UnitTests.Data/Disposable.cs index 9ec964b..8410361 100644 --- a/OnixLabs.Core.UnitTests.Data/Disposable.cs +++ b/OnixLabs.Core.UnitTests.Data/Disposable.cs @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Threading.Tasks; + namespace OnixLabs.Core.UnitTests.Data; public sealed class Disposable : IDisposable, IAsyncDisposable diff --git a/OnixLabs.Core.UnitTests.Data/InvalidFormatProvider.cs b/OnixLabs.Core.UnitTests.Data/InvalidFormatProvider.cs index 494541d..736f328 100644 --- a/OnixLabs.Core.UnitTests.Data/InvalidFormatProvider.cs +++ b/OnixLabs.Core.UnitTests.Data/InvalidFormatProvider.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; + namespace OnixLabs.Core.UnitTests.Data; public sealed class InvalidFormatProvider : IFormatProvider diff --git a/OnixLabs.Core.UnitTests.Data/Numeric.cs b/OnixLabs.Core.UnitTests.Data/Numeric.cs index dc20316..7d233ae 100644 --- a/OnixLabs.Core.UnitTests.Data/Numeric.cs +++ b/OnixLabs.Core.UnitTests.Data/Numeric.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Numerics; namespace OnixLabs.Core.UnitTests.Data; diff --git a/OnixLabs.Core.UnitTests.Data/OnixLabs.Core.UnitTests.Data.csproj b/OnixLabs.Core.UnitTests.Data/OnixLabs.Core.UnitTests.Data.csproj index 3bb46b3..62d7548 100644 --- a/OnixLabs.Core.UnitTests.Data/OnixLabs.Core.UnitTests.Data.csproj +++ b/OnixLabs.Core.UnitTests.Data/OnixLabs.Core.UnitTests.Data.csproj @@ -1,16 +1,12 @@ - net8.0 - enable - enable false - 12 false - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -20,9 +16,9 @@ - + - + diff --git a/OnixLabs.Core.UnitTests.Data/Record.cs b/OnixLabs.Core.UnitTests.Data/Record.cs index c2fb53d..37c50a8 100644 --- a/OnixLabs.Core.UnitTests.Data/Record.cs +++ b/OnixLabs.Core.UnitTests.Data/Record.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; + namespace OnixLabs.Core.UnitTests.Data; public sealed record Record(string Text, int Number, T Value, IEnumerable? Values = null); diff --git a/OnixLabs.Core.UnitTests/Collections/CollectionTests.cs b/OnixLabs.Core.UnitTests/Collections/CollectionTests.cs index ba83e20..9f18b7b 100644 --- a/OnixLabs.Core.UnitTests/Collections/CollectionTests.cs +++ b/OnixLabs.Core.UnitTests/Collections/CollectionTests.cs @@ -22,23 +22,11 @@ namespace OnixLabs.Core.UnitTests.Collections; public sealed class CollectionTests { - private static readonly object[] EnumerableInitializers = [true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23]; - - private static readonly int[] NumericInitializers = [123, 456, 789, 0, 1, -1, -987, 123, 456, 789, 0, 1, -1, -987]; - private static readonly KeyValuePair[] DictionaryInitializers = - [ - new KeyValuePair(123, true), - new KeyValuePair("abc", null), - new KeyValuePair(123.45f, "value") - ]; + [new(123, true), new("abc", null), new(123.45f, "value")]; private static readonly KeyValuePair[] SortedDictionaryInitializers = - [ - new KeyValuePair("key1", 123), - new KeyValuePair("key2", false), - new KeyValuePair("key3", "abc") - ]; + [new("key1", 123), new("key2", false), new("key3", "abc")]; [Fact(DisplayName = "Collections.EmptyEnumerable should produce the expected result")] public void CollectionsEmptyEnumerableShouldProduceTheExpectedResult() @@ -231,8 +219,8 @@ public void CollectionsEmptyImmutableQueueShouldProduceTheExpectedResult() public void CollectionsEnumerableOfShouldReturnTheExpectedResult() { // Given - IEnumerable expected = EnumerableInitializers; - IEnumerable actual = EnumerableOf(EnumerableInitializers); + IEnumerable expected = [true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23]; + IEnumerable actual = EnumerableOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -242,8 +230,8 @@ public void CollectionsEnumerableOfShouldReturnTheExpectedResult() public void CollectionsArrayOfShouldReturnTheExpectedResult() { // Given - object[] expected = EnumerableInitializers.ToArray(); - object[] actual = ArrayOf(EnumerableInitializers); + object[] expected = [true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23]; + object[] actual = ArrayOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -253,8 +241,8 @@ public void CollectionsArrayOfShouldReturnTheExpectedResult() public void CollectionsImmutableArrayOfShouldReturnTheExpectedResult() { // Given - ImmutableArray expected = [..EnumerableInitializers]; - ImmutableArray actual = ImmutableArrayOf(EnumerableInitializers); + ImmutableArray expected = [true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23]; + ImmutableArray actual = ImmutableArrayOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -264,8 +252,8 @@ public void CollectionsImmutableArrayOfShouldReturnTheExpectedResult() public void CollectionsListOfShouldReturnTheExpectedResult() { // Given - List expected = [..EnumerableInitializers]; - List actual = ListOf(EnumerableInitializers); + List expected = [true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23]; + List actual = ListOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -275,8 +263,8 @@ public void CollectionsListOfShouldReturnTheExpectedResult() public void CollectionsImmutableListOfShouldReturnTheExpectedResult() { // Given - ImmutableList expected = ImmutableList.Create(EnumerableInitializers); - ImmutableList actual = ImmutableListOf(EnumerableInitializers); + ImmutableList expected = ImmutableList.Create(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); + ImmutableList actual = ImmutableListOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -290,6 +278,7 @@ public void CollectionsDictionaryOfShouldReturnTheExpectedResult() Dictionary actual = DictionaryOf(DictionaryInitializers); // Then + // ReSharper disable once UsageOfDefaultStructEquality Assert.True(expected.SequenceEqual(actual)); } @@ -301,6 +290,7 @@ public void CollectionsImmutableDictionaryOfShouldReturnTheExpectedResult() ImmutableDictionary actual = ImmutableDictionaryOf(DictionaryInitializers); // Then + // ReSharper disable once UsageOfDefaultStructEquality Assert.True(expected.SequenceEqual(actual)); } @@ -312,6 +302,7 @@ public void CollectionsSortedDictionaryOfShouldReturnTheExpectedResult() SortedDictionary actual = SortedDictionaryOf(SortedDictionaryInitializers); // Then + // ReSharper disable once UsageOfDefaultStructEquality Assert.True(expected.SequenceEqual(actual)); } @@ -324,6 +315,7 @@ public void CollectionsImmutableSortedDictionaryOfShouldReturnTheExpectedResult( ImmutableSortedDictionary actual = ImmutableSortedDictionaryOf(SortedDictionaryInitializers); // Then + // ReSharper disable once UsageOfDefaultStructEquality Assert.True(expected.SequenceEqual(actual)); } @@ -331,8 +323,8 @@ public void CollectionsImmutableSortedDictionaryOfShouldReturnTheExpectedResult( public void CollectionsHashSetOfShouldReturnTheExpectedResult() { // Given - HashSet expected = [..EnumerableInitializers]; - HashSet actual = HashSetOf(EnumerableInitializers); + HashSet expected = [true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23]; + HashSet actual = HashSetOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -342,8 +334,8 @@ public void CollectionsHashSetOfShouldReturnTheExpectedResult() public void CollectionsImmutableHashSetOfShouldReturnTheExpectedResult() { // Given - ImmutableHashSet expected = ImmutableHashSet.Create(EnumerableInitializers); - ImmutableHashSet actual = ImmutableHashSetOf(EnumerableInitializers); + ImmutableHashSet expected = ImmutableHashSet.Create(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); + ImmutableHashSet actual = ImmutableHashSetOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -353,8 +345,8 @@ public void CollectionsImmutableHashSetOfShouldReturnTheExpectedResult() public void CollectionsSortedSetOfShouldReturnTheExpectedResult() { // Given - SortedSet expected = new(NumericInitializers); - SortedSet actual = SortedSetOf(NumericInitializers); + SortedSet expected = new([123, 456, 789, 0, 1, -1, -987, 123, 456, 789, 0, 1, -1, -987]); + SortedSet actual = SortedSetOf(123, 456, 789, 0, 1, -1, -987, 123, 456, 789, 0, 1, -1, -987); // Then Assert.True(expected.SequenceEqual(actual)); @@ -364,8 +356,8 @@ public void CollectionsSortedSetOfShouldReturnTheExpectedResult() public void CollectionsImmutableSortedSetOfShouldReturnTheExpectedResult() { // Given - ImmutableSortedSet expected = ImmutableSortedSet.Create(NumericInitializers); - ImmutableSortedSet actual = ImmutableSortedSetOf(NumericInitializers); + ImmutableSortedSet expected = ImmutableSortedSet.Create(123, 456, 789, 0, 1, -1, -987, 123, 456, 789, 0, 1, -1, -987); + ImmutableSortedSet actual = ImmutableSortedSetOf(123, 456, 789, 0, 1, -1, -987, 123, 456, 789, 0, 1, -1, -987); // Then Assert.True(expected.SequenceEqual(actual)); @@ -375,8 +367,8 @@ public void CollectionsImmutableSortedSetOfShouldReturnTheExpectedResult() public void CollectionsStackOfShouldReturnTheExpectedResult() { // Given - Stack expected = new(EnumerableInitializers); - Stack actual = StackOf(EnumerableInitializers); + Stack expected = new([true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23]); + Stack actual = StackOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -386,8 +378,8 @@ public void CollectionsStackOfShouldReturnTheExpectedResult() public void CollectionsImmutableStackOfShouldReturnTheExpectedResult() { // Given - ImmutableStack expected = ImmutableStack.Create(EnumerableInitializers); - ImmutableStack actual = ImmutableStackOf(EnumerableInitializers); + ImmutableStack expected = ImmutableStack.Create(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); + ImmutableStack actual = ImmutableStackOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -397,8 +389,8 @@ public void CollectionsImmutableStackOfShouldReturnTheExpectedResult() public void CollectionsQueueOfShouldReturnTheExpectedResult() { // Given - Queue expected = new(EnumerableInitializers); - Queue actual = QueueOf(EnumerableInitializers); + Queue expected = new([true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23]); + Queue actual = QueueOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); @@ -408,8 +400,8 @@ public void CollectionsQueueOfShouldReturnTheExpectedResult() public void CollectionsImmutableQueueOfShouldReturnTheExpectedResult() { // Given - ImmutableQueue expected = ImmutableQueue.Create(EnumerableInitializers); - ImmutableQueue actual = ImmutableQueueOf(EnumerableInitializers); + ImmutableQueue expected = ImmutableQueue.Create(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); + ImmutableQueue actual = ImmutableQueueOf(true, false, 123, "abc", 1.23, true, false, 123, "abc", 1.23); // Then Assert.True(expected.SequenceEqual(actual)); diff --git a/OnixLabs.Core.UnitTests/OnixLabs.Core.UnitTests.csproj b/OnixLabs.Core.UnitTests/OnixLabs.Core.UnitTests.csproj index 199ccab..ddfd2f7 100644 --- a/OnixLabs.Core.UnitTests/OnixLabs.Core.UnitTests.csproj +++ b/OnixLabs.Core.UnitTests/OnixLabs.Core.UnitTests.csproj @@ -1,14 +1,12 @@ - net8.0 false - 12 - enable + true - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -18,10 +16,10 @@ - - + + - + diff --git a/OnixLabs.Core.UnitTests/Reflection/TypeExtensionTests.cs b/OnixLabs.Core.UnitTests/Reflection/TypeExtensionTests.cs index 3b44847..cf074cc 100644 --- a/OnixLabs.Core.UnitTests/Reflection/TypeExtensionTests.cs +++ b/OnixLabs.Core.UnitTests/Reflection/TypeExtensionTests.cs @@ -21,31 +21,6 @@ namespace OnixLabs.Core.UnitTests.Reflection; public sealed class TypeExtensionTests { -#pragma warning disable CS0618 // Type or member is obsolete - [Theory(DisplayName = "Type.GetName should produce the expected result")] - [InlineData(typeof(object), TypeNameFlags.None, "Object")] - [InlineData(typeof(List<>), TypeNameFlags.None, "List")] - [InlineData(typeof(Dictionary<,>), TypeNameFlags.None, "Dictionary")] - [InlineData(typeof(object), TypeNameFlags.UseFullNames, "System.Object")] - [InlineData(typeof(List<>), TypeNameFlags.UseFullNames, "System.Collections.Generic.List")] - [InlineData(typeof(Dictionary<,>), TypeNameFlags.UseFullNames, "System.Collections.Generic.Dictionary")] - [InlineData(typeof(object), TypeNameFlags.UseGenericTypeArguments, "Object")] - [InlineData(typeof(List<>), TypeNameFlags.UseGenericTypeArguments, "List<>")] - [InlineData(typeof(Dictionary<,>), TypeNameFlags.UseGenericTypeArguments, "Dictionary<>")] - [InlineData(typeof(List>), TypeNameFlags.UseGenericTypeArguments, "List>")] - [InlineData(typeof(Dictionary>), TypeNameFlags.UseGenericTypeArguments, "Dictionary>")] - [InlineData(typeof(List>), TypeNameFlags.All, "System.Collections.Generic.List>")] - [InlineData(typeof(Dictionary>), TypeNameFlags.All, "System.Collections.Generic.Dictionary>")] - public void TypeGetNameShouldProduceExpectedResult(Type type, TypeNameFlags flags, string expected) - { - // When - string actual = type.GetName(flags); - - // Then - Assert.Equal(expected, actual); - } -#pragma warning restore CS0618 // Type or member is obsolete - [Theory(DisplayName = "Type.GetCSharpTypeDeclaration should produce the expected result")] [InlineData(typeof(byte), TypeDeclarationFlags.None, "Byte")] [InlineData(typeof(byte), TypeDeclarationFlags.UseNamespaceQualifiedTypeNames, "System.Byte")] diff --git a/OnixLabs.Core.UnitTests/Text/Base16Tests.cs b/OnixLabs.Core.UnitTests/Text/Base16Tests.cs index a6a824c..f9c3980 100644 --- a/OnixLabs.Core.UnitTests/Text/Base16Tests.cs +++ b/OnixLabs.Core.UnitTests/Text/Base16Tests.cs @@ -42,7 +42,7 @@ public void Base16ShouldBeImplicitlyConstructableFromReadOnlySpanOfByte() { // Given const string expected = "414243616263313233"; - ReadOnlySpan value = "ABCabc123".ToByteArray().AsSpan(); + ReadOnlySpan value = "ABCabc123".ToByteArray(); // When Base16 candidate = value; @@ -106,7 +106,7 @@ public void Base16ShouldBeImplicitlyConstructableFromReadOnlySequenceOfByte() // When Base16 candidate = value; - byte[] actual = candidate.ToByteArray(); + ReadOnlySpan actual = candidate.AsReadOnlySpan(); // Then Assert.Equal(expected, actual); @@ -136,8 +136,7 @@ public void Base16ShouldNotChangeWhenModifyingObtainedByteArray() const string expected = "414243616263313233"; // When - byte[] bytes = candidate.ToByteArray(); - bytes[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then @@ -200,7 +199,7 @@ public void Base16ParseShouldProduceExpectedResult(string value, string expected Base16 candidate = Base16.Parse(value); // When - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.Equal(expected, actual); @@ -253,7 +252,7 @@ public void Base16TryFormatShouldProduceExpectedResultWhenValueWasNotFormattedCo { // Given ISpanFormattable candidate = new Base16(Encoding.UTF8.GetBytes(value)); - Span destination = stackalloc char[0]; + Span destination = []; // When bool result = candidate.TryFormat(destination, out int charsWritten, [], null); @@ -274,7 +273,7 @@ public void Base16TryParseShouldProduceTheExpectedResultWhenStringIsParsedSucces { // When bool result = Base16.TryParse(value, null, out Base16 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.True(result); @@ -287,7 +286,7 @@ public void Base16TryParseShouldProduceTheExpectedResultWhenStringIsNotParsedSuc { // When bool result = Base16.TryParse(value, null, out Base16 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.False(result); @@ -304,7 +303,7 @@ public void Base16TryParseShouldProduceTheExpectedResultWhenReadOnlySpanOfCharIs { // When bool result = Base16.TryParse(value.AsSpan(), null, out Base16 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.True(result); @@ -317,7 +316,7 @@ public void Base16TryParseShouldProduceTheExpectedResultWhenReadOnlySpanOfCharIs { // When bool result = Base16.TryParse(value.AsSpan(), null, out Base16 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.False(result); diff --git a/OnixLabs.Core.UnitTests/Text/Base32Tests.cs b/OnixLabs.Core.UnitTests/Text/Base32Tests.cs index 93446f4..0cacf48 100644 --- a/OnixLabs.Core.UnitTests/Text/Base32Tests.cs +++ b/OnixLabs.Core.UnitTests/Text/Base32Tests.cs @@ -42,7 +42,7 @@ public void Base32ShouldBeImplicitlyConstructableFromReadOnlySpanOfByte() { // Given const string expected = "IFBEGYLCMMYTEMY"; - ReadOnlySpan value = "ABCabc123".ToByteArray().AsSpan(); + ReadOnlySpan value = "ABCabc123".ToByteArray(); // When Base32 candidate = value; @@ -106,7 +106,7 @@ public void Base32ShouldBeImplicitlyConstructableFromReadOnlySequenceOfByte() // When Base32 candidate = value; - byte[] actual = candidate.ToByteArray(); + ReadOnlySpan actual = candidate.AsReadOnlySpan(); // Then Assert.Equal(expected, actual); @@ -136,8 +136,7 @@ public void Base32ShouldNotChangeWhenModifyingObtainedByteArray() const string expected = "IFBEGYLCMMYTEMY"; // When - byte[] bytes = candidate.ToByteArray(); - bytes[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then @@ -200,7 +199,7 @@ public void Base32ParseShouldProduceExpectedResult(string value, string expected Base32 candidate = Base32.Parse(value); // When - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.Equal(expected, actual); @@ -253,7 +252,7 @@ public void Base32TryFormatShouldProduceExpectedResultWhenValueWasNotFormattedCo { // Given ISpanFormattable candidate = new Base32(Encoding.UTF8.GetBytes(value)); - Span destination = stackalloc char[0]; + Span destination = []; // When bool result = candidate.TryFormat(destination, out int charsWritten, [], null); @@ -274,7 +273,7 @@ public void Base32TryParseShouldProduceTheExpectedResultWhenStringIsParsedSucces { // When bool result = Base32.TryParse(value, null, out Base32 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.True(result); @@ -287,7 +286,7 @@ public void Base32TryParseShouldProduceTheExpectedResultWhenStringIsNotParsedSuc { // When bool result = Base32.TryParse(value, null, out Base32 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.False(result); @@ -304,7 +303,7 @@ public void Base32TryParseShouldProduceTheExpectedResultWhenReadOnlySpanOfCharIs { // When bool result = Base32.TryParse(value.AsSpan(), null, out Base32 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.True(result); @@ -317,7 +316,7 @@ public void Base32TryParseShouldProduceTheExpectedResultWhenReadOnlySpanOfCharIs { // When bool result = Base32.TryParse(value.AsSpan(), null, out Base32 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.False(result); diff --git a/OnixLabs.Core.UnitTests/Text/Base58Tests.cs b/OnixLabs.Core.UnitTests/Text/Base58Tests.cs index 8ab240c..aa23322 100644 --- a/OnixLabs.Core.UnitTests/Text/Base58Tests.cs +++ b/OnixLabs.Core.UnitTests/Text/Base58Tests.cs @@ -42,7 +42,7 @@ public void Base58ShouldBeImplicitlyConstructableFromReadOnlySpanOfByte() { // Given const string expected = "qBLgTCSW82Hg"; - ReadOnlySpan value = "ABCabc123".ToByteArray().AsSpan(); + ReadOnlySpan value = "ABCabc123".ToByteArray(); // When Base58 candidate = value; @@ -61,7 +61,7 @@ public void Base58ShouldBeImplicitlyConstructableFromReadOnlySequenceOfByte() // When Base58 candidate = value; - byte[] actual = candidate.ToByteArray(); + ReadOnlySpan actual = candidate.AsReadOnlySpan(); // Then Assert.Equal(expected, actual); @@ -136,8 +136,7 @@ public void Base58ShouldNotChangeWhenModifyingObtainedByteArray() const string expected = "qBLgTCSW82Hg"; // When - byte[] bytes = candidate.ToByteArray(); - bytes[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then @@ -200,7 +199,7 @@ public void Base58ParseShouldProduceExpectedResult(string value, string expected Base58 candidate = Base58.Parse(value); // When - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.Equal(expected, actual); @@ -253,7 +252,7 @@ public void Base58TryFormatShouldProduceExpectedResultWhenValueWasNotFormattedCo { // Given ISpanFormattable candidate = new Base58(Encoding.UTF8.GetBytes(value)); - Span destination = stackalloc char[0]; + Span destination = []; // When bool result = candidate.TryFormat(destination, out int charsWritten, [], null); @@ -274,7 +273,7 @@ public void Base58TryParseShouldProduceTheExpectedResultWhenStringIsParsedSucces { // When bool result = Base58.TryParse(value, null, out Base58 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.True(result); @@ -287,7 +286,7 @@ public void Base58TryParseShouldProduceTheExpectedResultWhenStringIsNotParsedSuc { // When bool result = Base58.TryParse(value, null, out Base58 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.False(result); @@ -304,7 +303,7 @@ public void Base58TryParseShouldProduceTheExpectedResultWhenReadOnlySpanOfCharIs { // When bool result = Base58.TryParse(value.AsSpan(), null, out Base58 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.True(result); @@ -317,7 +316,7 @@ public void Base58TryParseShouldProduceTheExpectedResultWhenReadOnlySpanOfCharIs { // When bool result = Base58.TryParse(value.AsSpan(), null, out Base58 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.False(result); diff --git a/OnixLabs.Core.UnitTests/Text/Base64Tests.cs b/OnixLabs.Core.UnitTests/Text/Base64Tests.cs index c76da20..8257353 100644 --- a/OnixLabs.Core.UnitTests/Text/Base64Tests.cs +++ b/OnixLabs.Core.UnitTests/Text/Base64Tests.cs @@ -42,7 +42,7 @@ public void Base64ShouldBeImplicitlyConstructableFromReadOnlySpanOfByte() { // Given const string expected = "QUJDYWJjMTIz"; - ReadOnlySpan value = "ABCabc123".ToByteArray().AsSpan(); + ReadOnlySpan value = "ABCabc123".ToByteArray(); // When Base64 candidate = value; @@ -106,7 +106,7 @@ public void Base64ShouldBeImplicitlyConstructableFromReadOnlySequenceOfByte() // When Base64 candidate = value; - byte[] actual = candidate.ToByteArray(); + ReadOnlySpan actual = candidate.AsReadOnlySpan(); // Then Assert.Equal(expected, actual); @@ -136,8 +136,7 @@ public void Base64ShouldNotChangeWhenModifyingObtainedByteArray() const string expected = "QUJDYWJjMTIz"; // When - byte[] bytes = candidate.ToByteArray(); - bytes[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then @@ -200,7 +199,7 @@ public void Base64ParseShouldProduceExpectedResult(string value, string expected Base64 candidate = Base64.Parse(value); // When - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.Equal(expected, actual); @@ -253,7 +252,7 @@ public void Base64TryFormatShouldProduceExpectedResultWhenValueWasNotFormattedCo { // Given ISpanFormattable candidate = new Base64(Encoding.UTF8.GetBytes(value)); - Span destination = stackalloc char[0]; + Span destination = []; // When bool result = candidate.TryFormat(destination, out int charsWritten, [], null); @@ -274,7 +273,7 @@ public void Base64TryParseShouldProduceTheExpectedResultWhenStringIsParsedSucces { // When bool result = Base64.TryParse(value, null, out Base64 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.True(result); @@ -287,7 +286,7 @@ public void Base64TryParseShouldProduceTheExpectedResultWhenStringIsNotParsedSuc { // When bool result = Base64.TryParse(value, null, out Base64 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.False(result); @@ -304,7 +303,7 @@ public void Base64TryParseShouldProduceTheExpectedResultWhenReadOnlySpanOfCharIs { // When bool result = Base64.TryParse(value.AsSpan(), null, out Base64 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.True(result); @@ -317,7 +316,7 @@ public void Base64TryParseShouldProduceTheExpectedResultWhenReadOnlySpanOfCharIs { // When bool result = Base64.TryParse(value.AsSpan(), null, out Base64 candidate); - string actual = Encoding.UTF8.GetString(candidate.ToByteArray()); + string actual = Encoding.UTF8.GetString(candidate.AsReadOnlySpan()); // Then Assert.False(result); diff --git a/OnixLabs.Core.UnitTests/Text/ExtensionTests.cs b/OnixLabs.Core.UnitTests/Text/ExtensionTests.cs index 2ab7e38..61e4c26 100644 --- a/OnixLabs.Core.UnitTests/Text/ExtensionTests.cs +++ b/OnixLabs.Core.UnitTests/Text/ExtensionTests.cs @@ -46,7 +46,7 @@ public void ByteArrayToBase16ShouldProduceExpectedResult(string value, string ex public void ReadOnlySpanOfByteToBase16ShouldProduceExpectedResult(string value, string expected) { // Given - ReadOnlySpan source = value.ToByteArray().AsSpan(); + ReadOnlySpan source = value.ToByteArray(); // When Base16 result = source.ToBase16(); @@ -82,7 +82,7 @@ public void ByteArrayToBase32ShouldProduceExpectedResult(string value, string ex public void ReadOnlySpanOfByteToBase32ShouldProduceExpectedResult(string value, string expected) { // Given - ReadOnlySpan source = value.ToByteArray().AsSpan(); + ReadOnlySpan source = value.ToByteArray(); // When Base32 result = source.ToBase32(); @@ -118,7 +118,7 @@ public void ByteArrayToBase58ShouldProduceExpectedResult(string value, string ex public void ReadOnlySpanOfByteToBase58ShouldProduceExpectedResult(string value, string expected) { // Given - ReadOnlySpan source = value.ToByteArray().AsSpan(); + ReadOnlySpan source = value.ToByteArray(); // When Base58 result = source.ToBase58(); @@ -154,7 +154,7 @@ public void ByteArrayToBase64ShouldProduceExpectedResult(string value, string ex public void ReadOnlySpanOfByteToBase64ShouldProduceExpectedResult(string value, string expected) { // Given - ReadOnlySpan source = value.ToByteArray().AsSpan(); + ReadOnlySpan source = value.ToByteArray(); // When Base64 result = source.ToBase64(); diff --git a/OnixLabs.Core/Collections/Collection.Of.cs b/OnixLabs.Core/Collections/Collection.Of.cs index 7f25058..c24d077 100644 --- a/OnixLabs.Core/Collections/Collection.Of.cs +++ b/OnixLabs.Core/Collections/Collection.Of.cs @@ -26,7 +26,7 @@ public static partial class Collection /// The items which will populate the enumerable. /// The underlying type of the enumerable. /// Returns an enumerable populated with the specified items. - public static IEnumerable EnumerableOf(params T[] items) => items; + public static IEnumerable EnumerableOf(params IEnumerable items) => items; /// /// Creates an array of the specified items. @@ -42,7 +42,7 @@ public static partial class Collection /// The items which will populate the immutable array. /// The underlying type of the immutable array. /// Returns an immutable array populated with the specified items. - public static ImmutableArray ImmutableArrayOf(params T[] items) => [..items]; + public static ImmutableArray ImmutableArrayOf(params ImmutableArray items) => items; /// /// Creates a list of the specified items. @@ -50,7 +50,7 @@ public static partial class Collection /// The items which will populate the list. /// The underlying type of the list. /// Returns a list populated with the specified items. - public static List ListOf(params T[] items) => [..items]; + public static List ListOf(params List items) => items; /// /// Creates an immutable list of the specified items. @@ -58,7 +58,71 @@ public static partial class Collection /// The items which will populate the immutable list. /// The underlying type of the immutable list. /// Returns an immutable list populated with the specified items. - public static ImmutableList ImmutableListOf(params T[] items) => [..items]; + public static ImmutableList ImmutableListOf(params ImmutableList items) => items; + + /// + /// Creates a hash set of the specified items. + /// + /// The items which will populate the hash set. + /// The underlying type of the hash set. + /// Returns a hash set populated with the specified items. + public static HashSet HashSetOf(params HashSet items) => items; + + /// + /// Creates an immutable hash set of the specified items. + /// + /// The items which will populate the immutable hash set. + /// The underlying type of the immutable hash set. + /// Returns an immutable hash set populated with the specified items. + public static ImmutableHashSet ImmutableHashSetOf(params ImmutableHashSet items) => items; + + /// + /// Creates a sorted set of the specified items. + /// + /// The items which will populate the sorted set. + /// The underlying type of the sorted set. + /// Returns a sorted set populated with the specified items. + public static SortedSet SortedSetOf(params SortedSet items) => items; + + /// + /// Creates an immutable sorted set of the specified items. + /// + /// The items which will populate the immutable sorted set. + /// The underlying type of the immutable sorted set. + /// Returns an immutable sorted set populated with the specified items. + public static ImmutableSortedSet ImmutableSortedSetOf(params ImmutableSortedSet items) => items; + + /// + /// Creates a stack of the specified items. + /// + /// The items which will populate the stack. + /// The underlying type of the stack. + /// Returns a stack populated with the specified items. + public static Stack StackOf(params IEnumerable items) => new(items); + + /// + /// Creates an immutable stack of the specified items. + /// + /// The items which will populate the immutable stack. + /// The underlying type of the immutable stack. + /// Returns an immutable stack populated with the specified items. + public static ImmutableStack ImmutableStackOf(params ImmutableStack items) => items; + + /// + /// Creates a queue of the specified items. + /// + /// The items which will populate the queue. + /// The underlying type of the queue. + /// Returns a queue populated with the specified items. + public static Queue QueueOf(params IEnumerable items) => new(items); + + /// + /// Creates an immutable queue of the specified items. + /// + /// The items which will populate the immutable queue. + /// The underlying type of the immutable queue. + /// Returns an immutable queue populated with the specified items. + public static ImmutableQueue ImmutableQueueOf(params ImmutableQueue items) => items; /// /// Create a dictionary of the specified items. @@ -67,7 +131,8 @@ public static partial class Collection /// The underlying type of the dictionary key. /// The underlying type of the dictionary value. /// Returns a dictionary populated with the specified items. - public static Dictionary DictionaryOf(params KeyValuePair[] items) where TKey : notnull => new(items); + public static Dictionary DictionaryOf + (params IEnumerable> items) where TKey : notnull => new(items); /// /// Create a dictionary of the specified items. @@ -76,8 +141,9 @@ public static partial class Collection /// The underlying type of the dictionary key. /// The underlying type of the dictionary value. /// Returns a dictionary populated with the specified items. - public static Dictionary DictionaryOf(params (TKey key, TValue value)[] items) where TKey : notnull => - DictionaryOf(items.Select(item => new KeyValuePair(item.key, item.value)).ToArray()); + public static Dictionary DictionaryOf + (params IEnumerable<(TKey key, TValue value)> items) where TKey : notnull => + DictionaryOf(items.Select(item => new KeyValuePair(item.key, item.value))); /// /// Create an immutable dictionary of the specified items. @@ -86,8 +152,8 @@ public static Dictionary DictionaryOf(params (TKey k /// The underlying type of the immutable dictionary key. /// The underlying type of the immutable dictionary value. /// Returns an immutable dictionary populated with the specified items. - public static ImmutableDictionary ImmutableDictionaryOf(params KeyValuePair[] items) where TKey : notnull => - ImmutableDictionary.CreateRange(items); + public static ImmutableDictionary ImmutableDictionaryOf + (params IEnumerable> items) where TKey : notnull => ImmutableDictionary.CreateRange(items); /// /// Create an immutable dictionary of the specified items. @@ -96,7 +162,8 @@ public static ImmutableDictionary ImmutableDictionaryOfThe underlying type of the immutable dictionary key. /// The underlying type of the immutable dictionary value. /// Returns an immutable dictionary populated with the specified items. - public static ImmutableDictionary ImmutableDictionaryOf(params (TKey key, TValue value)[] items) where TKey : notnull => + public static ImmutableDictionary ImmutableDictionaryOf + (params IEnumerable<(TKey key, TValue value)> items) where TKey : notnull => ImmutableDictionary.CreateRange(items.Select(item => new KeyValuePair(item.key, item.value))); /// @@ -106,8 +173,8 @@ public static ImmutableDictionary ImmutableDictionaryOfThe underlying type of the sorted dictionary key. /// The underlying type of the sorted dictionary value. /// Returns a sorted dictionary populated with the specified items. - public static SortedDictionary SortedDictionaryOf(params KeyValuePair[] items) where TKey : notnull => - new(DictionaryOf(items)); + public static SortedDictionary SortedDictionaryOf + (params IEnumerable> items) where TKey : notnull => new(DictionaryOf(items)); /// /// Create a sorted dictionary of the specified items. @@ -116,8 +183,8 @@ public static SortedDictionary SortedDictionaryOf(pa /// The underlying type of the sorted dictionary key. /// The underlying type of the sorted dictionary value. /// Returns a sorted dictionary populated with the specified items. - public static SortedDictionary SortedDictionaryOf(params (TKey key, TValue value)[] items) where TKey : notnull => - new(DictionaryOf(items)); + public static SortedDictionary SortedDictionaryOf + (params IEnumerable<(TKey key, TValue value)> items) where TKey : notnull => new(DictionaryOf(items)); /// /// Create an immutable sorted dictionary of the specified items. @@ -126,8 +193,8 @@ public static SortedDictionary SortedDictionaryOf(pa /// The underlying type of the immutable sorted dictionary key. /// The underlying type of the immutable sorted dictionary value. /// Returns an immutable sorted dictionary populated with the specified items. - public static ImmutableSortedDictionary ImmutableSortedDictionaryOf(params KeyValuePair[] items) where TKey : notnull => - ImmutableSortedDictionary.CreateRange(items); + public static ImmutableSortedDictionary ImmutableSortedDictionaryOf + (params IEnumerable> items) where TKey : notnull => ImmutableSortedDictionary.CreateRange(items); /// /// Create an immutable sorted dictionary of the specified items. @@ -136,70 +203,7 @@ public static ImmutableSortedDictionary ImmutableSortedDictionaryO /// The underlying type of the immutable sorted dictionary key. /// The underlying type of the immutable sorted dictionary value. /// Returns an immutable sorted dictionary populated with the specified items. - public static ImmutableSortedDictionary ImmutableSortedDictionaryOf(params (TKey key, TValue value)[] items) where TKey : notnull => + public static ImmutableSortedDictionary ImmutableSortedDictionaryOf + (params IEnumerable<(TKey key, TValue value)> items) where TKey : notnull => ImmutableSortedDictionary.CreateRange(items.Select(item => new KeyValuePair(item.key, item.value))); - - /// - /// Creates a hash set of the specified items. - /// - /// The items which will populate the hash set. - /// The underlying type of the hash set. - /// Returns a hash set populated with the specified items. - public static HashSet HashSetOf(params T[] items) => [..items]; - - /// - /// Creates an immutable hash set of the specified items. - /// - /// The items which will populate the immutable hash set. - /// The underlying type of the immutable hash set. - /// Returns an immutable hash set populated with the specified items. - public static ImmutableHashSet ImmutableHashSetOf(params T[] items) => [..items]; - - /// - /// Creates a sorted set of the specified items. - /// - /// The items which will populate the sorted set. - /// The underlying type of the sorted set. - /// Returns a sorted set populated with the specified items. - public static SortedSet SortedSetOf(params T[] items) => [..items]; - - /// - /// Creates an immutable sorted set of the specified items. - /// - /// The items which will populate the immutable sorted set. - /// The underlying type of the immutable sorted set. - /// Returns an immutable sorted set populated with the specified items. - public static ImmutableSortedSet ImmutableSortedSetOf(params T[] items) => [..items]; - - /// - /// Creates a stack of the specified items. - /// - /// The items which will populate the stack. - /// The underlying type of the stack. - /// Returns a stack populated with the specified items. - public static Stack StackOf(params T[] items) => new(items); - - /// - /// Creates an immutable stack of the specified items. - /// - /// The items which will populate the immutable stack. - /// The underlying type of the immutable stack. - /// Returns an immutable stack populated with the specified items. - public static ImmutableStack ImmutableStackOf(params T[] items) => [..items]; - - /// - /// Creates a queue of the specified items. - /// - /// The items which will populate the queue. - /// The underlying type of the queue. - /// Returns a queue populated with the specified items. - public static Queue QueueOf(params T[] items) => new(items); - - /// - /// Creates an immutable queue of the specified items. - /// - /// The items which will populate the immutable queue. - /// The underlying type of the immutable queue. - /// Returns an immutable queue populated with the specified items. - public static ImmutableQueue ImmutableQueueOf(params T[] items) => [..items]; } diff --git a/OnixLabs.Core/IBinaryConvertible.cs b/OnixLabs.Core/IBinaryConvertible.cs index e4cdd78..74b07a6 100644 --- a/OnixLabs.Core/IBinaryConvertible.cs +++ b/OnixLabs.Core/IBinaryConvertible.cs @@ -17,11 +17,4 @@ namespace OnixLabs.Core; /// /// Defines a type that is convertible to an instance of . /// -public interface IBinaryConvertible -{ - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - byte[] ToByteArray(); -} +public interface IBinaryConvertible : ISpanBinaryConvertible, IMemoryBinaryConvertible; diff --git a/OnixLabs.Core/IMemoryBinaryConvertible.cs b/OnixLabs.Core/IMemoryBinaryConvertible.cs new file mode 100644 index 0000000..9e7a447 --- /dev/null +++ b/OnixLabs.Core/IMemoryBinaryConvertible.cs @@ -0,0 +1,29 @@ +// Copyright 2020-2024 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; + +namespace OnixLabs.Core; + +/// +/// Defines a type that is convertible to an instance of . +/// +public interface IMemoryBinaryConvertible +{ + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + ReadOnlyMemory AsReadOnlyMemory(); +} diff --git a/OnixLabs.Core/ISpanBinaryConvertible.cs b/OnixLabs.Core/ISpanBinaryConvertible.cs index 99ad776..1a6386c 100644 --- a/OnixLabs.Core/ISpanBinaryConvertible.cs +++ b/OnixLabs.Core/ISpanBinaryConvertible.cs @@ -19,11 +19,11 @@ namespace OnixLabs.Core; /// /// Defines a type that is convertible to an instance of . /// -public interface ISpanBinaryConvertible : IBinaryConvertible +public interface ISpanBinaryConvertible { /// /// Gets the underlying representation of the current instance as a new instance. /// /// Return the underlying representation of the current instance as a new instance. - ReadOnlySpan ToReadOnlySpan(); + ReadOnlySpan AsReadOnlySpan(); } diff --git a/OnixLabs.Core/OnixLabs.Core.csproj b/OnixLabs.Core/OnixLabs.Core.csproj index cdcf998..9c6bbcf 100644 --- a/OnixLabs.Core/OnixLabs.Core.csproj +++ b/OnixLabs.Core/OnixLabs.Core.csproj @@ -1,15 +1,7 @@ - net8.0 - 12 - enable - true OnixLabs.Core - ONIXLabs ONIXLabs Core API for .NET - en - Copyright © ONIXLabs 2020 - https://github.com/onix-labs/onixlabs-dotnet $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb diff --git a/OnixLabs.Core/Reflection/Extensions.Type.cs b/OnixLabs.Core/Reflection/Extensions.Type.cs index 7cadcdf..48bb80d 100644 --- a/OnixLabs.Core/Reflection/Extensions.Type.cs +++ b/OnixLabs.Core/Reflection/Extensions.Type.cs @@ -14,8 +14,6 @@ using System; using System.ComponentModel; -using System.Text; -using OnixLabs.Core.Text; namespace OnixLabs.Core.Reflection; @@ -25,49 +23,6 @@ namespace OnixLabs.Core.Reflection; [EditorBrowsable(EditorBrowsableState.Never)] public static class TypeExtensions { - private const char GenericTypeIdentifierMarker = '`'; - private const char GenericTypeOpenBracket = '<'; - private const char GenericTypeCloseBracket = '>'; - private const string GenericTypeSeparator = ", "; - private const string TypeNullExceptionMessage = "Type must not be null."; - - /// - /// Gets the formatted type name from the current instance. - /// - /// The current instance from which to obtain the formatted type name. - /// The type name flags that will be used to format the type name. - /// Returns the formatted type name from the current instance. - [Obsolete("This method has been replaced with GetCSharpTypeDeclaration and will be removed in version 10.0.0")] - public static string GetName(this Type type, TypeNameFlags flags = default) - { - RequireNotNull(type, TypeNullExceptionMessage, nameof(type)); - RequireIsDefined(flags, nameof(flags)); - - // ReSharper disable once HeapView.ObjectAllocation.Evident - StringBuilder builder = new(); - - builder.Append(type.GetName((flags & TypeNameFlags.UseFullNames) is not 0)); - - if (!type.IsGenericType || (flags & TypeNameFlags.UseGenericTypeArguments) is 0) - return builder.ToString(); - - builder.Append(GenericTypeOpenBracket); - - foreach (Type argument in type.GenericTypeArguments) - builder.Append(argument.GetName(flags)).Append(GenericTypeSeparator); - - return builder.TrimEnd(GenericTypeSeparator).Append(GenericTypeCloseBracket).ToString(); - } - - /// - /// Gets the simple type name from the current instance. - /// - /// The current instance from which to obtain the simple type name. - /// Determines whether the current 's full name or short name should be returned. - /// Returns the simple type name from the current instance. - private static string GetName(this Type type, bool useFullName) => - (useFullName ? type.FullName ?? type.Name : type.Name).SubstringBeforeFirst(GenericTypeIdentifierMarker); - /// /// Gets the type declaration for the current instance. /// diff --git a/OnixLabs.Core/Reflection/TypeNameFlags.cs b/OnixLabs.Core/Reflection/TypeNameFlags.cs deleted file mode 100644 index cce7c2e..0000000 --- a/OnixLabs.Core/Reflection/TypeNameFlags.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2020 ONIXLabs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; - -namespace OnixLabs.Core.Reflection; - -/// -/// Specifies flags that control how a type name is formatted. -/// -[Flags, Obsolete("This enumeration has been replaced with TypeDeclarationFlags and will be removed in version 10.0.0")] -public enum TypeNameFlags -{ - /// - /// Specifies that no type name flags are applied. - /// - None = default, - - /// - /// Specifies that type names should be formatted with their full name, where applicable. - /// - UseFullNames = 1, - - /// - /// Specifies that if a type is generic, it should be formatted with its generic type arguments. - /// - UseGenericTypeArguments = 2, - - /// - /// Specifies that type names should be formatted with their full name, where applicable, and that if a type is generic, it should be formatted with its generic type arguments. - /// - All = UseFullNames | UseGenericTypeArguments -} diff --git a/OnixLabs.Core/Text/Base16.Convertible.cs b/OnixLabs.Core/Text/Base16.Convertible.cs index e33f3d7..34873de 100644 --- a/OnixLabs.Core/Text/Base16.Convertible.cs +++ b/OnixLabs.Core/Text/Base16.Convertible.cs @@ -20,6 +20,18 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base16 { + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => value; + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => value; + /// /// Create a new instance from the specified value. /// diff --git a/OnixLabs.Core/Text/Base16.To.cs b/OnixLabs.Core/Text/Base16.To.cs index c675d9c..1a14859 100644 --- a/OnixLabs.Core/Text/Base16.To.cs +++ b/OnixLabs.Core/Text/Base16.To.cs @@ -18,18 +18,6 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base16 { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => value.Copy(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => value; - /// /// Returns a that represents the current object. /// diff --git a/OnixLabs.Core/Text/Base32.Convertible.cs b/OnixLabs.Core/Text/Base32.Convertible.cs index aa3b242..3b65a27 100644 --- a/OnixLabs.Core/Text/Base32.Convertible.cs +++ b/OnixLabs.Core/Text/Base32.Convertible.cs @@ -20,6 +20,18 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base32 { + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => value; + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => value; + /// /// Create a new instance from the specified value. /// diff --git a/OnixLabs.Core/Text/Base32.To.cs b/OnixLabs.Core/Text/Base32.To.cs index e553c06..87bb96c 100644 --- a/OnixLabs.Core/Text/Base32.To.cs +++ b/OnixLabs.Core/Text/Base32.To.cs @@ -18,18 +18,6 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base32 { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => value.Copy(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => value; - /// /// Returns a that represents the current object. /// diff --git a/OnixLabs.Core/Text/Base58.Convertible.cs b/OnixLabs.Core/Text/Base58.Convertible.cs index f3c83f6..c7ae568 100644 --- a/OnixLabs.Core/Text/Base58.Convertible.cs +++ b/OnixLabs.Core/Text/Base58.Convertible.cs @@ -20,6 +20,18 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base58 { + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => value; + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => value; + /// /// Create a new instance from the specified value. /// diff --git a/OnixLabs.Core/Text/Base58.To.cs b/OnixLabs.Core/Text/Base58.To.cs index 6231994..23b562f 100644 --- a/OnixLabs.Core/Text/Base58.To.cs +++ b/OnixLabs.Core/Text/Base58.To.cs @@ -18,18 +18,6 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base58 { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => value.Copy(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => value; - /// /// Returns a that represents the current object. /// diff --git a/OnixLabs.Core/Text/Base64.Convertible.cs b/OnixLabs.Core/Text/Base64.Convertible.cs index 8696df7..44784ff 100644 --- a/OnixLabs.Core/Text/Base64.Convertible.cs +++ b/OnixLabs.Core/Text/Base64.Convertible.cs @@ -20,6 +20,18 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base64 { + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => value; + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => value; + /// /// Create a new instance from the specified value. /// diff --git a/OnixLabs.Core/Text/Base64.To.cs b/OnixLabs.Core/Text/Base64.To.cs index a8a4c53..7e1722a 100644 --- a/OnixLabs.Core/Text/Base64.To.cs +++ b/OnixLabs.Core/Text/Base64.To.cs @@ -18,18 +18,6 @@ namespace OnixLabs.Core.Text; public readonly partial struct Base64 { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => value.Copy(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => value; - /// /// Returns a that represents the current object. /// diff --git a/OnixLabs.Core/Text/IBaseValue.cs b/OnixLabs.Core/Text/IBaseValue.cs index f6d15c8..103c244 100644 --- a/OnixLabs.Core/Text/IBaseValue.cs +++ b/OnixLabs.Core/Text/IBaseValue.cs @@ -19,7 +19,7 @@ namespace OnixLabs.Core.Text; /// /// Defines a Base-N value. /// -public interface IBaseValue : ISpanBinaryConvertible, ISpanFormattable +public interface IBaseValue : IBinaryConvertible, ISpanFormattable { /// /// Formats the value of the current instance using the specified format. diff --git a/OnixLabs.DependencyInjection.UnitTests.Data/OnixLabs.DependencyInjection.UnitTests.Data.csproj b/OnixLabs.DependencyInjection.UnitTests.Data/OnixLabs.DependencyInjection.UnitTests.Data.csproj index c9dc86e..6742cca 100644 --- a/OnixLabs.DependencyInjection.UnitTests.Data/OnixLabs.DependencyInjection.UnitTests.Data.csproj +++ b/OnixLabs.DependencyInjection.UnitTests.Data/OnixLabs.DependencyInjection.UnitTests.Data.csproj @@ -1,21 +1,25 @@ - net8.0 - enable - enable false + false - - - - + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + - + diff --git a/OnixLabs.DependencyInjection.UnitTests/IServiceCollectionExtensionTests.cs b/OnixLabs.DependencyInjection.UnitTests/IServiceCollectionExtensionTests.cs index 8ebfa58..8948f8a 100644 --- a/OnixLabs.DependencyInjection.UnitTests/IServiceCollectionExtensionTests.cs +++ b/OnixLabs.DependencyInjection.UnitTests/IServiceCollectionExtensionTests.cs @@ -1,3 +1,5 @@ +using System; +using System.Linq; using Microsoft.Extensions.DependencyInjection; using OnixLabs.DependencyInjection.UnitTests.Data; diff --git a/OnixLabs.DependencyInjection.UnitTests/OnixLabs.DependencyInjection.UnitTests.csproj b/OnixLabs.DependencyInjection.UnitTests/OnixLabs.DependencyInjection.UnitTests.csproj index a22eb62..c263cff 100644 --- a/OnixLabs.DependencyInjection.UnitTests/OnixLabs.DependencyInjection.UnitTests.csproj +++ b/OnixLabs.DependencyInjection.UnitTests/OnixLabs.DependencyInjection.UnitTests.csproj @@ -1,23 +1,25 @@ - net8.0 - enable - enable - false true - - - - + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + - + diff --git a/OnixLabs.DependencyInjection/OnixLabs.DependencyInjection.csproj b/OnixLabs.DependencyInjection/OnixLabs.DependencyInjection.csproj index 341ab4d..4e7c01c 100644 --- a/OnixLabs.DependencyInjection/OnixLabs.DependencyInjection.csproj +++ b/OnixLabs.DependencyInjection/OnixLabs.DependencyInjection.csproj @@ -1,15 +1,7 @@  - net8.0 - 12 - enable - true OnixLabs.DependencyInjection - ONIXLabs ONIXLabs Dependency Injection API for .NET - en - Copyright © ONIXLabs 2020 - https://github.com/onix-labs/onixlabs-dotnet $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb @@ -32,17 +24,17 @@ true - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticAbsDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticAbsDataAttribute.cs index 1481511..ddf48ef 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticAbsDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticAbsDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticAdditionDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticAdditionDataAttribute.cs index b31cea4..bccf91c 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticAdditionDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticAdditionDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticDivisionDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticDivisionDataAttribute.cs index 22c87f6..0a083a6 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticDivisionDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticDivisionDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticModulusDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticModulusDataAttribute.cs index 85be7d2..d2de390 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticModulusDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticModulusDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticMultiplicationDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticMultiplicationDataAttribute.cs index a35d844..f4b24a2 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticMultiplicationDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticMultiplicationDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticPowDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticPowDataAttribute.cs index 8affc1d..d0cd52d 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticPowDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticPowDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticRoundDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticRoundDataAttribute.cs index be55d9b..53e70b9 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticRoundDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticRoundDataAttribute.cs @@ -12,6 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; +using System.Linq; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticScaleDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticScaleDataAttribute.cs index b582a74..2addac6 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticScaleDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticScaleDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticSubtractionDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticSubtractionDataAttribute.cs index 7eec7e1..054a4f3 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticSubtractionDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticSubtractionDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticTrimDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticTrimDataAttribute.cs index 59dbb6f..6c3585b 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticTrimDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticTrimDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticTruncateDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticTruncateDataAttribute.cs index 925df4f..882d2c0 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticTruncateDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticTruncateDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticUnaryAdditionDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticUnaryAdditionDataAttribute.cs index 6d6189b..f98652d 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticUnaryAdditionDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticUnaryAdditionDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticUnarySubtractionDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticUnarySubtractionDataAttribute.cs index d345e19..72165be 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticUnarySubtractionDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalArithmeticUnarySubtractionDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalIeee754BinaryDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalIeee754BinaryDataAttribute.cs index 1ab8a0f..debb068 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalIeee754BinaryDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalIeee754BinaryDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalIeee754DecimalDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalIeee754DecimalDataAttribute.cs index ffdf9cc..d28c69b 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalIeee754DecimalDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalIeee754DecimalDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalIsDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalIsDataAttribute.cs index 4fc0778..5eeed7a 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalIsDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalIsDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/BigDecimalWriteDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/BigDecimalWriteDataAttribute.cs index c7b6849..73ded2f 100644 --- a/OnixLabs.Numerics.UnitTests.Data/BigDecimalWriteDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/BigDecimalWriteDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumberFormatDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/NumberFormatDataAttribute.cs index 5d34aec..94311a1 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumberFormatDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumberFormatDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Globalization; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumberInfoEqualityComparerDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/NumberInfoEqualityComparerDataAttribute.cs index e1d8280..a14d2ed 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumberInfoEqualityComparerDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumberInfoEqualityComparerDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumberInfoOrdinalityComparerDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/NumberInfoOrdinalityComparerDataAttribute.cs index 851ab30..58150a6 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumberInfoOrdinalityComparerDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumberInfoOrdinalityComparerDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/FullNumericDataProvider.cs b/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/FullNumericDataProvider.cs index 85260e6..4ab4b4f 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/FullNumericDataProvider.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/FullNumericDataProvider.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Globalization; namespace OnixLabs.Numerics.UnitTests.Data.NumericDataProviders; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/INumericDataProvider.cs b/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/INumericDataProvider.cs index a4ca340..4cb40ac 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/INumericDataProvider.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/INumericDataProvider.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Globalization; namespace OnixLabs.Numerics.UnitTests.Data.NumericDataProviders; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/SlimNumericDataProvider.cs b/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/SlimNumericDataProvider.cs index 63a3cef..e618098 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/SlimNumericDataProvider.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumericDataProviders/SlimNumericDataProvider.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Globalization; namespace OnixLabs.Numerics.UnitTests.Data.NumericDataProviders; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToDecimalDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToDecimalDataAttribute.cs index 7b663d3..fb45033 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToDecimalDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToDecimalDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoDecimalDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoDecimalDataAttribute.cs index d1c4518..0deb811 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoDecimalDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoDecimalDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Numerics; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoDoubleDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoDoubleDataAttribute.cs index 4790706..2758ce6 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoDoubleDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoDoubleDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Numerics; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoFloatDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoFloatDataAttribute.cs index e162940..5224432 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoFloatDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoFloatDataAttribute.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System.Collections.Generic; using System.Numerics; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoIntegerDataAttribute.cs b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoIntegerDataAttribute.cs index c83d471..eb456d2 100644 --- a/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoIntegerDataAttribute.cs +++ b/OnixLabs.Numerics.UnitTests.Data/NumericsExtensionsToNumberInfoIntegerDataAttribute.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Numerics; using System.Reflection; using Xunit.Sdk; diff --git a/OnixLabs.Numerics.UnitTests.Data/OnixLabs.Numerics.UnitTests.Data.csproj b/OnixLabs.Numerics.UnitTests.Data/OnixLabs.Numerics.UnitTests.Data.csproj index db6aa9d..0965ed3 100644 --- a/OnixLabs.Numerics.UnitTests.Data/OnixLabs.Numerics.UnitTests.Data.csproj +++ b/OnixLabs.Numerics.UnitTests.Data/OnixLabs.Numerics.UnitTests.Data.csproj @@ -1,15 +1,12 @@ - net8.0 - enable - enable false false - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -19,9 +16,9 @@ - + - + diff --git a/OnixLabs.Numerics.UnitTests.Data/TestDataGenerator.cs b/OnixLabs.Numerics.UnitTests.Data/TestDataGenerator.cs index 733bb04..02c227d 100644 --- a/OnixLabs.Numerics.UnitTests.Data/TestDataGenerator.cs +++ b/OnixLabs.Numerics.UnitTests.Data/TestDataGenerator.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Globalization; using OnixLabs.Numerics.UnitTests.Data.NumericDataProviders; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticAdditionTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticAdditionTests.cs index 80fd93e..7a55ce0 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticAdditionTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticAdditionTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticDivisionTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticDivisionTests.cs index e08a57b..4b22954 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticDivisionTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticDivisionTests.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; +using System.Collections.Generic; using System.Numerics; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticModulusTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticModulusTests.cs index b31f53d..319cade 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticModulusTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticModulusTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticMultiplicationTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticMultiplicationTests.cs index fc3f252..1e65663 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticMultiplicationTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticMultiplicationTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticRoundTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticRoundTests.cs index 27bf4d1..a8f0f29 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticRoundTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticRoundTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticScaleTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticScaleTests.cs index aebc0f6..7cbc755 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticScaleTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticScaleTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticSubtractionTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticSubtractionTests.cs index 8d11e93..ef96856 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticSubtractionTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticSubtractionTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticTruncateTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticTruncateTests.cs index 1caffc6..f4a803d 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticTruncateTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalArithmeticTruncateTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalEqualityComparerTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalEqualityComparerTests.cs index 757cfca..4e1a42a 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalEqualityComparerTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalEqualityComparerTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalFormatTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalFormatTests.cs index 388556a..4559c53 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalFormatTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalFormatTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Globalization; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalIsTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalIsTests.cs index 4ecbf3c..374b51d 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalIsTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalIsTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalOrdinalityComparerTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalOrdinalityComparerTests.cs index 91f1f04..f1a703d 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalOrdinalityComparerTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalOrdinalityComparerTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalParseTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalParseTests.cs index ddb774a..4a265dc 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalParseTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalParseTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Globalization; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/BigDecimalToStringTests.cs b/OnixLabs.Numerics.UnitTests/BigDecimalToStringTests.cs index b8f12c3..c2562ec 100644 --- a/OnixLabs.Numerics.UnitTests/BigDecimalToStringTests.cs +++ b/OnixLabs.Numerics.UnitTests/BigDecimalToStringTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Globalization; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/NumberInfoEqualityComparerTests.cs b/OnixLabs.Numerics.UnitTests/NumberInfoEqualityComparerTests.cs index f0613e5..61324a5 100644 --- a/OnixLabs.Numerics.UnitTests/NumberInfoEqualityComparerTests.cs +++ b/OnixLabs.Numerics.UnitTests/NumberInfoEqualityComparerTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/NumberInfoOrdinalityComparerTests.cs b/OnixLabs.Numerics.UnitTests/NumberInfoOrdinalityComparerTests.cs index 2138fcd..8733fa5 100644 --- a/OnixLabs.Numerics.UnitTests/NumberInfoOrdinalityComparerTests.cs +++ b/OnixLabs.Numerics.UnitTests/NumberInfoOrdinalityComparerTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/NumberInfoParseTests.cs b/OnixLabs.Numerics.UnitTests/NumberInfoParseTests.cs index 3861b3c..25459de 100644 --- a/OnixLabs.Numerics.UnitTests/NumberInfoParseTests.cs +++ b/OnixLabs.Numerics.UnitTests/NumberInfoParseTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Globalization; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/NumberInfoToStringTests.cs b/OnixLabs.Numerics.UnitTests/NumberInfoToStringTests.cs index 10814e0..d7e83d9 100644 --- a/OnixLabs.Numerics.UnitTests/NumberInfoToStringTests.cs +++ b/OnixLabs.Numerics.UnitTests/NumberInfoToStringTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Globalization; using OnixLabs.Numerics.UnitTests.Data; using Xunit; diff --git a/OnixLabs.Numerics.UnitTests/NumericsExtensionsTests.cs b/OnixLabs.Numerics.UnitTests/NumericsExtensionsTests.cs index 0bf7256..4fc4ee4 100644 --- a/OnixLabs.Numerics.UnitTests/NumericsExtensionsTests.cs +++ b/OnixLabs.Numerics.UnitTests/NumericsExtensionsTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Globalization; using System.Numerics; using OnixLabs.Numerics.UnitTests.Data; diff --git a/OnixLabs.Numerics.UnitTests/OnixLabs.Numerics.UnitTests.csproj b/OnixLabs.Numerics.UnitTests/OnixLabs.Numerics.UnitTests.csproj index 2ac9c1a..412809f 100644 --- a/OnixLabs.Numerics.UnitTests/OnixLabs.Numerics.UnitTests.csproj +++ b/OnixLabs.Numerics.UnitTests/OnixLabs.Numerics.UnitTests.csproj @@ -1,16 +1,12 @@ - net8.0 - enable - enable - false true - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -20,10 +16,10 @@ - - + + - + diff --git a/OnixLabs.Numerics/BigDecimal.Format.cs b/OnixLabs.Numerics/BigDecimal.Format.cs index 9d7ea0d..9210b11 100644 --- a/OnixLabs.Numerics/BigDecimal.Format.cs +++ b/OnixLabs.Numerics/BigDecimal.Format.cs @@ -36,7 +36,7 @@ bool ISpanFormattable.TryFormat(Span destination, out int charsWritten, Re return false; } - formatted.AsSpan().CopyTo(destination); + formatted.CopyTo(destination); charsWritten = formatted.Length; return true; } diff --git a/OnixLabs.Numerics/OnixLabs.Numerics.csproj b/OnixLabs.Numerics/OnixLabs.Numerics.csproj index c1653c2..f094c39 100644 --- a/OnixLabs.Numerics/OnixLabs.Numerics.csproj +++ b/OnixLabs.Numerics/OnixLabs.Numerics.csproj @@ -1,15 +1,7 @@  - net8.0 OnixLabs.Numerics - ONIXLabs ONIXLabs Numerics API for .NET - en - enable - true - Copyright © ONIXLabs 2020 - https://github.com/onix-labs/onixlabs-dotnet - 12 $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb diff --git a/OnixLabs.Playground/OnixLabs.Playground.csproj b/OnixLabs.Playground/OnixLabs.Playground.csproj index 345aa1f..3b2ceee 100644 --- a/OnixLabs.Playground/OnixLabs.Playground.csproj +++ b/OnixLabs.Playground/OnixLabs.Playground.csproj @@ -1,9 +1,6 @@ Exe - net8.0 - enable - 12 true @@ -13,7 +10,7 @@ - + diff --git a/OnixLabs.Security.Cryptography.UnitTests.Data/BinaryConvertible.cs b/OnixLabs.Security.Cryptography.UnitTests.Data/BinaryConvertible.cs index 0233cae..db60500 100644 --- a/OnixLabs.Security.Cryptography.UnitTests.Data/BinaryConvertible.cs +++ b/OnixLabs.Security.Cryptography.UnitTests.Data/BinaryConvertible.cs @@ -12,18 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using OnixLabs.Core; namespace OnixLabs.Security.Cryptography.UnitTests.Data; public class BinaryConvertible(byte[] data) : IBinaryConvertible { - public byte[] ToByteArray() => data; - public ReadOnlySpan ToReadOnlySpan() => data; -} - -public class SpanBinaryConvertible(byte[] data) : ISpanBinaryConvertible -{ - public byte[] ToByteArray() => data; - public ReadOnlySpan ToReadOnlySpan() => data; + public ReadOnlyMemory AsReadOnlyMemory() => data; + public ReadOnlySpan AsReadOnlySpan() => data; } diff --git a/OnixLabs.Security.Cryptography.UnitTests.Data/MerkleNode.cs b/OnixLabs.Security.Cryptography.UnitTests.Data/MerkleNode.cs index 43e0b6a..d8c929b 100644 --- a/OnixLabs.Security.Cryptography.UnitTests.Data/MerkleNode.cs +++ b/OnixLabs.Security.Cryptography.UnitTests.Data/MerkleNode.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Security.Cryptography; namespace OnixLabs.Security.Cryptography.UnitTests.Data; diff --git a/OnixLabs.Security.Cryptography.UnitTests.Data/OnixLabs.Security.Cryptography.UnitTests.Data.csproj b/OnixLabs.Security.Cryptography.UnitTests.Data/OnixLabs.Security.Cryptography.UnitTests.Data.csproj index 73046a2..4337676 100644 --- a/OnixLabs.Security.Cryptography.UnitTests.Data/OnixLabs.Security.Cryptography.UnitTests.Data.csproj +++ b/OnixLabs.Security.Cryptography.UnitTests.Data/OnixLabs.Security.Cryptography.UnitTests.Data.csproj @@ -1,16 +1,12 @@ - net8.0 - enable - enable false - 12 false - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -20,9 +16,9 @@ - + - + diff --git a/OnixLabs.Security.Cryptography.UnitTests.Data/TestPrivateKey.cs b/OnixLabs.Security.Cryptography.UnitTests.Data/TestPrivateKey.cs index 4491b69..efc15bd 100644 --- a/OnixLabs.Security.Cryptography.UnitTests.Data/TestPrivateKey.cs +++ b/OnixLabs.Security.Cryptography.UnitTests.Data/TestPrivateKey.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; + namespace OnixLabs.Security.Cryptography.UnitTests.Data; public sealed class TestPrivateKey(ReadOnlySpan value) : PrivateKey(value) diff --git a/OnixLabs.Security.Cryptography.UnitTests.Data/TestPublicKey.cs b/OnixLabs.Security.Cryptography.UnitTests.Data/TestPublicKey.cs index 3fad571..c8a6f9a 100644 --- a/OnixLabs.Security.Cryptography.UnitTests.Data/TestPublicKey.cs +++ b/OnixLabs.Security.Cryptography.UnitTests.Data/TestPublicKey.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; + namespace OnixLabs.Security.Cryptography.UnitTests.Data; public sealed class TestPublicKey(ReadOnlySpan value) : PublicKey(value) diff --git a/OnixLabs.Security.Cryptography.UnitTests/DigitalSignatureTests.cs b/OnixLabs.Security.Cryptography.UnitTests/DigitalSignatureTests.cs index 1e1a468..05c3008 100644 --- a/OnixLabs.Security.Cryptography.UnitTests/DigitalSignatureTests.cs +++ b/OnixLabs.Security.Cryptography.UnitTests/DigitalSignatureTests.cs @@ -57,8 +57,7 @@ public void DigitalSignatureValueShouldNotBeModifiedWhenAlteringTheObtainedByteA const string expected = "01020304"; // When - byte[] value = candidate.ToByteArray(); - value[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then diff --git a/OnixLabs.Security.Cryptography.UnitTests/EcdsaKeyTests.cs b/OnixLabs.Security.Cryptography.UnitTests/EcdsaKeyTests.cs index 9e4f654..ebefe38 100644 --- a/OnixLabs.Security.Cryptography.UnitTests/EcdsaKeyTests.cs +++ b/OnixLabs.Security.Cryptography.UnitTests/EcdsaKeyTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Security.Cryptography; using Xunit; @@ -23,10 +24,10 @@ public sealed class EcdsaKeyTests public void EcdsaSignAndVerifyWithTwoIdenticalKeysShouldSucceed() { // Given - byte[] data = Salt.CreateNonZero(2048).ToByteArray(); + ReadOnlySpan data = Salt.CreateNonZero(2048).AsReadOnlySpan(); using HashAlgorithm algorithm = SHA256.Create(); IEcdsaPrivateKey privateKey1 = EcdsaPrivateKey.Create(); - IEcdsaPrivateKey privateKey2 = new EcdsaPrivateKey(privateKey1.ToByteArray()); + IEcdsaPrivateKey privateKey2 = new EcdsaPrivateKey(privateKey1.AsReadOnlySpan()); IEcdsaPublicKey publicKey1 = privateKey1.GetPublicKey(); IEcdsaPublicKey publicKey2 = privateKey2.GetPublicKey(); @@ -45,7 +46,7 @@ public void EcdsaSignAndVerifyWithTwoIdenticalKeysShouldSucceed() public void EcdsaPkcs8RoundTripSignAndVerifyShouldSucceed() { // Given - byte[] data = Salt.CreateNonZero(2048).ToByteArray(); + ReadOnlySpan data = Salt.CreateNonZero(2048).AsReadOnlySpan(); using HashAlgorithm algorithm = SHA256.Create(); PbeParameters parameters = new(PbeEncryptionAlgorithm.Aes256Cbc, HashAlgorithmName.SHA256, 10); byte[] exportedPrivateKey = EcdsaPrivateKey.Create().ExportPkcs8PrivateKey("Password", parameters); diff --git a/OnixLabs.Security.Cryptography.UnitTests/HashTests.cs b/OnixLabs.Security.Cryptography.UnitTests/HashTests.cs index 4200c65..4024f98 100644 --- a/OnixLabs.Security.Cryptography.UnitTests/HashTests.cs +++ b/OnixLabs.Security.Cryptography.UnitTests/HashTests.cs @@ -78,8 +78,7 @@ public void HashValueShouldNotBeModifiedWhenAlteringTheObtainedByteArray() const string expected = "01020304"; // When - byte[] value = candidate.ToByteArray(); - value[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then @@ -243,7 +242,7 @@ public void HashComputeShouldProduceTheExpectedHashUsingAByteArray(string data, public void HashComputeShouldProduceTheExpectedHashUsingASpan(string data, string algorithmName, string expected) { // Given - ReadOnlySpan bytes = data.ToByteArray().AsSpan(); + ReadOnlySpan bytes = data.ToByteArray(); HashAlgorithm algorithm = algorithmName switch { "MD5" => MD5.Create(), @@ -299,7 +298,7 @@ public void HashComputeShouldProduceTheExpectedHashUsingAByteArrayWithTwoRounds( public void HashComputeShouldProduceTheExpectedHashUsingASpanWithTwoRounds(string data, string algorithmName, string expected) { // Given - ReadOnlySpan bytes = data.ToByteArray().AsSpan(); + ReadOnlySpan bytes = data.ToByteArray(); HashAlgorithm algorithm = algorithmName switch { "MD5" => MD5.Create(), @@ -355,7 +354,7 @@ public void HashComputeShouldProduceTheExpectedHashUsingAByteArrayWithAnOffsetAn public void HashComputeShouldProduceTheExpectedHashUsingASpanWithAnOffsetAndCount(string data, int offset, int count, string algorithmName, string expected) { // Given - ReadOnlySpan bytes = data.ToByteArray().AsSpan(); + ReadOnlySpan bytes = data.ToByteArray(); HashAlgorithm algorithm = algorithmName switch { "MD5" => MD5.Create(), @@ -411,7 +410,7 @@ public void HashComputeShouldProduceTheExpectedHashUsingAByteArrayWithAnOffsetCo public void HashComputeShouldProduceTheExpectedHashUsingASpanWithAnOffsetCountAndTwoRounds(string data, int offset, int count, string algorithmName, string expected) { // Given - ReadOnlySpan bytes = data.ToByteArray().AsSpan(); + ReadOnlySpan bytes = data.ToByteArray(); HashAlgorithm algorithm = algorithmName switch { "MD5" => MD5.Create(), @@ -523,7 +522,7 @@ public void HashComputeShouldProduceTheExpectedHashUsingAnIBinaryConvertible(str public void HashComputeShouldProduceTheExpectedHashUsingAnISpanBinaryConvertible(string data, string algorithmName, string expected) { // Given - SpanBinaryConvertible bytes = new(data.ToByteArray()); + BinaryConvertible bytes = new(data.ToByteArray()); HashAlgorithm algorithm = algorithmName switch { "MD5" => MD5.Create(), diff --git a/OnixLabs.Security.Cryptography.UnitTests/OnixLabs.Security.Cryptography.UnitTests.csproj b/OnixLabs.Security.Cryptography.UnitTests/OnixLabs.Security.Cryptography.UnitTests.csproj index a7cb4fc..1ecb1f1 100644 --- a/OnixLabs.Security.Cryptography.UnitTests/OnixLabs.Security.Cryptography.UnitTests.csproj +++ b/OnixLabs.Security.Cryptography.UnitTests/OnixLabs.Security.Cryptography.UnitTests.csproj @@ -1,13 +1,12 @@ - net8.0 false - 12 + true - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -17,10 +16,10 @@ - - + + - + diff --git a/OnixLabs.Security.Cryptography.UnitTests/PrivateKeyTests.cs b/OnixLabs.Security.Cryptography.UnitTests/PrivateKeyTests.cs index 0987f69..e3c64f7 100644 --- a/OnixLabs.Security.Cryptography.UnitTests/PrivateKeyTests.cs +++ b/OnixLabs.Security.Cryptography.UnitTests/PrivateKeyTests.cs @@ -58,8 +58,7 @@ public void PrivateKeyValueShouldNotBeModifiedWhenAlteringTheObtainedByteArray() const string expected = "01020304"; // When - byte[] value = candidate.ToByteArray(); - value[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then diff --git a/OnixLabs.Security.Cryptography.UnitTests/PublicKeyTests.cs b/OnixLabs.Security.Cryptography.UnitTests/PublicKeyTests.cs index 162f1b1..db84a85 100644 --- a/OnixLabs.Security.Cryptography.UnitTests/PublicKeyTests.cs +++ b/OnixLabs.Security.Cryptography.UnitTests/PublicKeyTests.cs @@ -58,8 +58,7 @@ public void PublicKeyValueShouldNotBeModifiedWhenAlteringTheObtainedByteArray() const string expected = "01020304"; // When - byte[] value = candidate.ToByteArray(); - value[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then diff --git a/OnixLabs.Security.Cryptography.UnitTests/RsaKeyTests.cs b/OnixLabs.Security.Cryptography.UnitTests/RsaKeyTests.cs index b1ff679..7d28b30 100644 --- a/OnixLabs.Security.Cryptography.UnitTests/RsaKeyTests.cs +++ b/OnixLabs.Security.Cryptography.UnitTests/RsaKeyTests.cs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Security.Cryptography; using Xunit; @@ -23,11 +24,11 @@ public sealed class RsaKeyTests public void RsaSignAndVerifyWithTwoIdenticalKeysShouldSucceed() { // Given - byte[] data = Salt.CreateNonZero(2048).ToByteArray(); + ReadOnlySpan data = Salt.CreateNonZero(2048).AsReadOnlySpan(); HashAlgorithmName algorithm = HashAlgorithmName.SHA256; RSASignaturePadding padding = RSASignaturePadding.Pkcs1; IRsaPrivateKey privateKey1 = RsaPrivateKey.Create(); - IRsaPrivateKey privateKey2 = new RsaPrivateKey(privateKey1.ToByteArray()); + IRsaPrivateKey privateKey2 = new RsaPrivateKey(privateKey1.AsReadOnlySpan()); IRsaPublicKey publicKey1 = privateKey1.GetPublicKey(); IRsaPublicKey publicKey2 = privateKey2.GetPublicKey(); @@ -46,7 +47,7 @@ public void RsaSignAndVerifyWithTwoIdenticalKeysShouldSucceed() public void EcdsaPkcs8RoundTripSignAndVerifyShouldSucceed() { // Given - byte[] data = Salt.CreateNonZero(2048).ToByteArray(); + ReadOnlySpan data = Salt.CreateNonZero(2048).AsReadOnlySpan(); HashAlgorithmName algorithm = HashAlgorithmName.SHA256; RSASignaturePadding padding = RSASignaturePadding.Pkcs1; PbeParameters parameters = new(PbeEncryptionAlgorithm.Aes256Cbc, HashAlgorithmName.SHA256, 10); diff --git a/OnixLabs.Security.Cryptography.UnitTests/SaltTests.cs b/OnixLabs.Security.Cryptography.UnitTests/SaltTests.cs index 042655c..49de23c 100644 --- a/OnixLabs.Security.Cryptography.UnitTests/SaltTests.cs +++ b/OnixLabs.Security.Cryptography.UnitTests/SaltTests.cs @@ -58,8 +58,7 @@ public void SaltValueShouldNotBeModifiedWhenAlteringTheObtainedByteArray() const string expected = "01020304"; // When - byte[] value = candidate.ToByteArray(); - value[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then @@ -149,7 +148,7 @@ public void SaltCreateShouldProduceASaltOfTheSpecifiedLength() Salt candidate = Salt.Create(expected); // Then - Assert.Equal(expected, candidate.ToByteArray().Length); + Assert.Equal(expected, candidate.AsReadOnlySpan().Length); } [Fact(DisplayName = "Salt.CreateNonZero should produce a salt of the specified length of non-zero bytes")] @@ -160,7 +159,7 @@ public void SaltCreateNonZeroShouldProduceASaltOfTheSpecifiedLengthOfNonZeroByte Salt candidate = Salt.CreateNonZero(expected); // Then - Assert.Equal(expected, candidate.ToByteArray().Length); - Assert.True(candidate.ToByteArray().None(value => value is 0)); + Assert.Equal(expected, candidate.AsReadOnlySpan().Length); + Assert.True(candidate.AsReadOnlySpan().ToArray().None(value => value is 0)); } } diff --git a/OnixLabs.Security.Cryptography.UnitTests/SecretTests.cs b/OnixLabs.Security.Cryptography.UnitTests/SecretTests.cs index fe3c54c..f3cc531 100644 --- a/OnixLabs.Security.Cryptography.UnitTests/SecretTests.cs +++ b/OnixLabs.Security.Cryptography.UnitTests/SecretTests.cs @@ -62,8 +62,7 @@ public void SecretValueShouldNotBeModifiedWhenAlteringTheObtainedByteArray() const string expected = "01020304"; // When - byte[] value = candidate.ToByteArray(); - value[0] = 0; + candidate.AsReadOnlySpan().ToArray()[0] = 0; string actual = candidate.ToString(); // Then @@ -132,10 +131,10 @@ public void SecretShouldBeConstructableFromString() // Given const string value = "test"; Secret candidate = value; - byte[] expected = Encoding.UTF8.GetBytes(value); + ReadOnlySpan expected = Encoding.UTF8.GetBytes(value); // When - byte[] actual = candidate.ToByteArray(); + ReadOnlySpan actual = candidate.AsReadOnlySpan(); // Then Assert.Equal(expected, actual); @@ -147,10 +146,10 @@ public void SecretShouldBeConstructableFromCharArray() // Given char[] value = ['t', 'e', 's', 't']; Secret candidate = value; - byte[] expected = Encoding.UTF8.GetBytes(value); + ReadOnlySpan expected = Encoding.UTF8.GetBytes(value); // When - byte[] actual = candidate.ToByteArray(); + ReadOnlySpan actual = candidate.AsReadOnlySpan(); // Then Assert.Equal(expected, actual); @@ -160,12 +159,12 @@ public void SecretShouldBeConstructableFromCharArray() public void SecretShouldBeConstructableFromReadOnlySequence() { // Given - ReadOnlySequence value = new ReadOnlySequence(new char[] { 't', 'e', 's', 't' }); + ReadOnlySequence value = new(['t', 'e', 's', 't']); Secret candidate = value; - byte[] expected = Encoding.UTF8.GetBytes(value.ToArray()); + ReadOnlySpan expected = Encoding.UTF8.GetBytes(value); // When - byte[] actual = candidate.ToByteArray(); + ReadOnlySpan actual = candidate.AsReadOnlySpan(); // Then Assert.Equal(expected, actual); diff --git a/OnixLabs.Security.Cryptography/DigitalSignature.Convertible.cs b/OnixLabs.Security.Cryptography/DigitalSignature.Convertible.cs index dfd13c4..0b34664 100644 --- a/OnixLabs.Security.Cryptography/DigitalSignature.Convertible.cs +++ b/OnixLabs.Security.Cryptography/DigitalSignature.Convertible.cs @@ -19,6 +19,18 @@ namespace OnixLabs.Security.Cryptography; public readonly partial struct DigitalSignature { + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => value; + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => value; + /// /// Create a new instance from the specified value. /// diff --git a/OnixLabs.Security.Cryptography/DigitalSignature.To.cs b/OnixLabs.Security.Cryptography/DigitalSignature.To.cs index 50b7bca..0869c01 100644 --- a/OnixLabs.Security.Cryptography/DigitalSignature.To.cs +++ b/OnixLabs.Security.Cryptography/DigitalSignature.To.cs @@ -20,24 +20,12 @@ namespace OnixLabs.Security.Cryptography; public readonly partial struct DigitalSignature { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => value.Copy(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => value; - /// /// Returns a that represents the current object. /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => IBaseCodec.GetString(ToByteArray(), provider); + public string ToString(IFormatProvider provider) => IBaseCodec.GetString(AsReadOnlySpan(), provider); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.Cryptography/DigitalSignature.cs b/OnixLabs.Security.Cryptography/DigitalSignature.cs index fa5d25d..c119792 100644 --- a/OnixLabs.Security.Cryptography/DigitalSignature.cs +++ b/OnixLabs.Security.Cryptography/DigitalSignature.cs @@ -22,7 +22,7 @@ namespace OnixLabs.Security.Cryptography; /// Represents a cryptographic digital signature. /// /// The underlying value of the cryptographic digital signature. -public readonly partial struct DigitalSignature(ReadOnlySpan value) : ICryptoPrimitive, ISpanParsable, ISpanBinaryConvertible +public readonly partial struct DigitalSignature(ReadOnlySpan value) : ICryptoPrimitive, ISpanParsable { /// /// Initializes a new instance of the struct. diff --git a/OnixLabs.Security.Cryptography/EcdhPrivateKey.Derive.cs b/OnixLabs.Security.Cryptography/EcdhPrivateKey.Derive.cs index 0464fc9..8d28dd7 100644 --- a/OnixLabs.Security.Cryptography/EcdhPrivateKey.Derive.cs +++ b/OnixLabs.Security.Cryptography/EcdhPrivateKey.Derive.cs @@ -27,7 +27,7 @@ public Secret DeriveSharedSecret(IEcdhPublicKey publicKey) { using ECDiffieHellman ourKey = ImportKeyData(); using ECDiffieHellman theirKey = ECDiffieHellman.Create(); - theirKey.ImportSubjectPublicKeyInfo(publicKey.ToByteArray(), out int _); + theirKey.ImportSubjectPublicKeyInfo(publicKey.AsReadOnlySpan(), out int _); byte[] secretData = ourKey.DeriveKeyMaterial(theirKey.PublicKey); return new Secret(secretData); } diff --git a/OnixLabs.Security.Cryptography/EcdhPrivateKey.Import.cs b/OnixLabs.Security.Cryptography/EcdhPrivateKey.Import.cs index a40b166..a7a6c57 100644 --- a/OnixLabs.Security.Cryptography/EcdhPrivateKey.Import.cs +++ b/OnixLabs.Security.Cryptography/EcdhPrivateKey.Import.cs @@ -18,7 +18,6 @@ namespace OnixLabs.Security.Cryptography; -// ReSharper disable HeapView.ObjectAllocation.Evident public sealed partial class EcdhPrivateKey { /// @@ -58,7 +57,7 @@ public static EcdhPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data) => /// The number of bytes read from the input data. /// Returns a new EC Diffie-Hellman cryptographic private key from the imported data. public static EcdhPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data, out int bytesRead) => - ImportPkcs8PrivateKey(data.ToByteArray(), out bytesRead); + ImportPkcs8PrivateKey(data.AsReadOnlySpan(), out bytesRead); /// /// Imports the EC Diffie-Hellman cryptographic private key data in encrypted PKCS #8 format. @@ -101,7 +100,7 @@ public static EcdhPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data, Read /// The number of bytes read from the input data. /// Returns a new EC Diffie-Hellman cryptographic private key from the imported data. public static EcdhPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data, ReadOnlySpan password, out int bytesRead) => - ImportPkcs8PrivateKey(data.ToByteArray(), password, out bytesRead); + ImportPkcs8PrivateKey(data.AsReadOnlySpan(), password, out bytesRead); /// /// Imports the key data into a new instance. diff --git a/OnixLabs.Security.Cryptography/EcdhPrivateKey.To.cs b/OnixLabs.Security.Cryptography/EcdhPrivateKey.To.cs index 7dc98a3..68a9251 100644 --- a/OnixLabs.Security.Cryptography/EcdhPrivateKey.To.cs +++ b/OnixLabs.Security.Cryptography/EcdhPrivateKey.To.cs @@ -16,6 +16,8 @@ namespace OnixLabs.Security.Cryptography; public sealed partial class EcdhPrivateKey { + private const string KeyName = "ECDH"; + /// /// Creates a new from the current instance. /// diff --git a/OnixLabs.Security.Cryptography/EcdhPublicKey.To.cs b/OnixLabs.Security.Cryptography/EcdhPublicKey.To.cs index 8b598e5..ecffd5f 100644 --- a/OnixLabs.Security.Cryptography/EcdhPublicKey.To.cs +++ b/OnixLabs.Security.Cryptography/EcdhPublicKey.To.cs @@ -16,9 +16,11 @@ namespace OnixLabs.Security.Cryptography; public sealed partial class EcdhPublicKey { + private const string KeyName = "ECDH"; + /// /// Creates a new from the current instance. /// /// Returns a new from the current instance. - public override NamedPublicKey ToNamedPublicKey() => new(this, "ECDH"); + public override NamedPublicKey ToNamedPublicKey() => new(this, KeyName); } diff --git a/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Import.cs b/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Import.cs index 6f3a80e..ccd3659 100644 --- a/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Import.cs +++ b/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Import.cs @@ -58,7 +58,7 @@ public static EcdsaPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data) => /// The number of bytes read from the input data. /// Returns a new instance from the imported cryptographic private key data. public static EcdsaPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data, out int bytesRead) => - ImportPkcs8PrivateKey(data.ToByteArray(), out bytesRead); + ImportPkcs8PrivateKey(data.AsReadOnlySpan(), out bytesRead); /// /// Imports the ECDSA cryptographic private key data in encrypted PKCS #8 format. @@ -101,7 +101,7 @@ public static EcdsaPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data, Rea /// The number of bytes read from the input data. /// Returns a new instance from the imported cryptographic private key data. public static EcdsaPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data, ReadOnlySpan password, out int bytesRead) => - ImportPkcs8PrivateKey(data.ToByteArray(), password, out bytesRead); + ImportPkcs8PrivateKey(data.AsReadOnlySpan(), password, out bytesRead); /// /// Imports the key data into a new instance. diff --git a/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Sign.cs b/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Sign.cs index 652c2d7..d35b0de 100644 --- a/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Sign.cs +++ b/OnixLabs.Security.Cryptography/EcdsaPrivateKey.Sign.cs @@ -71,7 +71,7 @@ public byte[] SignData(Stream data, HashAlgorithm algorithm, DSASignatureFormat /// Returns a new instance containing the cryptographic digital signature. public byte[] SignData(IBinaryConvertible data, HashAlgorithm algorithm, DSASignatureFormat format = default) { - byte[] hash = algorithm.ComputeHash(data.ToByteArray()); + byte[] hash = algorithm.ComputeHash(data.AsReadOnlySpan()); return SignHash(hash, format); } @@ -126,7 +126,7 @@ public byte[] SignData(Stream data, HashAlgorithmName algorithm, DSASignatureFor public byte[] SignData(IBinaryConvertible data, HashAlgorithmName algorithm, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.SignData(data.ToByteArray(), algorithm, format); + return key.SignData(data.AsReadOnlySpan(), algorithm, format); } /// @@ -138,7 +138,7 @@ public byte[] SignData(IBinaryConvertible data, HashAlgorithmName algorithm, DSA public byte[] SignHash(Hash hash, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.SignHash(hash.ToByteArray(), format); + return key.SignHash(hash.AsReadOnlySpan(), format); } /// diff --git a/OnixLabs.Security.Cryptography/EcdsaPrivateKey.To.cs b/OnixLabs.Security.Cryptography/EcdsaPrivateKey.To.cs index 21b0b16..9fe17b6 100644 --- a/OnixLabs.Security.Cryptography/EcdsaPrivateKey.To.cs +++ b/OnixLabs.Security.Cryptography/EcdsaPrivateKey.To.cs @@ -16,9 +16,11 @@ namespace OnixLabs.Security.Cryptography; public sealed partial class EcdsaPrivateKey { + private const string KeyName = "ECDSA"; + /// /// Creates a new from the current instance. /// /// Returns a new from the current instance. - public override NamedPrivateKey ToNamedPrivateKey() => new(this, "ECDSA"); + public override NamedPrivateKey ToNamedPrivateKey() => new(this, KeyName); } diff --git a/OnixLabs.Security.Cryptography/EcdsaPublicKey.To.cs b/OnixLabs.Security.Cryptography/EcdsaPublicKey.To.cs index 5c230e6..1c0f95c 100644 --- a/OnixLabs.Security.Cryptography/EcdsaPublicKey.To.cs +++ b/OnixLabs.Security.Cryptography/EcdsaPublicKey.To.cs @@ -16,9 +16,11 @@ namespace OnixLabs.Security.Cryptography; public sealed partial class EcdsaPublicKey { + private const string KeyName = "ECDSA"; + /// /// Creates a new from the current instance. /// /// Returns a new from the current instance. - public override NamedPublicKey ToNamedPublicKey() => new(this, "ECDSA"); + public override NamedPublicKey ToNamedPublicKey() => new(this, KeyName); } diff --git a/OnixLabs.Security.Cryptography/EcdsaPublicKey.Verify.cs b/OnixLabs.Security.Cryptography/EcdsaPublicKey.Verify.cs index 1191106..75a59c6 100644 --- a/OnixLabs.Security.Cryptography/EcdsaPublicKey.Verify.cs +++ b/OnixLabs.Security.Cryptography/EcdsaPublicKey.Verify.cs @@ -91,7 +91,7 @@ public bool IsDataValid(ReadOnlySpan signature, Stream data, HashAlgorithm /// public bool IsDataValid(ReadOnlySpan signature, IBinaryConvertible data, HashAlgorithm algorithm, DSASignatureFormat format = default) { - byte[] hash = algorithm.ComputeHash(data.ToByteArray()); + byte[] hash = algorithm.ComputeHash(data.AsReadOnlySpan()); return IsHashValid(signature, hash, format); } @@ -166,7 +166,7 @@ public bool IsDataValid(ReadOnlySpan signature, Stream data, HashAlgorithm public bool IsDataValid(ReadOnlySpan signature, IBinaryConvertible data, HashAlgorithmName algorithm, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.VerifyData(data.ToByteArray(), signature, algorithm, format); + return key.VerifyData(data.AsReadOnlySpan(), signature, algorithm, format); } /// @@ -239,7 +239,7 @@ public bool IsDataValid(DigitalSignature signature, Stream data, HashAlgorithm a /// public bool IsDataValid(DigitalSignature signature, IBinaryConvertible data, HashAlgorithm algorithm, DSASignatureFormat format = default) { - byte[] hash = algorithm.ComputeHash(data.ToByteArray()); + byte[] hash = algorithm.ComputeHash(data.AsReadOnlySpan()); return IsHashValid(signature, hash, format); } @@ -258,7 +258,7 @@ public bool IsDataValid(DigitalSignature signature, IBinaryConvertible data, Has public bool IsDataValid(DigitalSignature signature, ReadOnlySpan data, HashAlgorithmName algorithm, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.VerifyData(data, signature.ToByteArray(), algorithm, format); + return key.VerifyData(data, signature.AsReadOnlySpan(), algorithm, format); } /// @@ -278,7 +278,8 @@ public bool IsDataValid(DigitalSignature signature, ReadOnlySpan data, Has public bool IsDataValid(DigitalSignature signature, ReadOnlySpan data, int offset, int count, HashAlgorithmName algorithm, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.VerifyData(data.ToArray(), offset, count, signature.ToByteArray(), algorithm, format); + // TODO : Spans for data and signature are inefficiently converted back to an array. + return key.VerifyData(data.ToArray(), offset, count, signature.AsReadOnlySpan().ToArray(), algorithm, format); } /// @@ -296,7 +297,8 @@ public bool IsDataValid(DigitalSignature signature, ReadOnlySpan data, int public bool IsDataValid(DigitalSignature signature, Stream data, HashAlgorithmName algorithm, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.VerifyData(data, signature.ToByteArray(), algorithm, format); + // TODO : Span for signature is inefficiently converted back to an array. + return key.VerifyData(data, signature.AsReadOnlySpan().ToArray(), algorithm, format); } /// @@ -314,7 +316,7 @@ public bool IsDataValid(DigitalSignature signature, Stream data, HashAlgorithmNa public bool IsDataValid(DigitalSignature signature, IBinaryConvertible data, HashAlgorithmName algorithm, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.VerifyData(data.ToByteArray(), signature.ToByteArray(), algorithm, format); + return key.VerifyData(data.AsReadOnlySpan(), signature.AsReadOnlySpan(), algorithm, format); } /// @@ -331,7 +333,7 @@ public bool IsDataValid(DigitalSignature signature, IBinaryConvertible data, Has public bool IsHashValid(ReadOnlySpan signature, Hash hash, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.VerifyHash(hash.ToByteArray(), signature, format); + return key.VerifyHash(hash.AsReadOnlySpan(), signature, format); } /// @@ -365,7 +367,7 @@ public bool IsHashValid(ReadOnlySpan signature, ReadOnlySpan hash, D public bool IsHashValid(DigitalSignature signature, Hash hash, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.VerifyHash(hash.ToByteArray(), signature.ToByteArray(), format); + return key.VerifyHash(hash.AsReadOnlySpan(), signature.AsReadOnlySpan(), format); } /// @@ -382,7 +384,7 @@ public bool IsHashValid(DigitalSignature signature, Hash hash, DSASignatureForma public bool IsHashValid(DigitalSignature signature, ReadOnlySpan hash, DSASignatureFormat format = default) { using ECDsa key = ImportKeyData(); - return key.VerifyHash(hash, signature.ToByteArray(), format); + return key.VerifyHash(hash, signature.AsReadOnlySpan(), format); } /// diff --git a/OnixLabs.Security.Cryptography/Extensions.HashAlgorithm.cs b/OnixLabs.Security.Cryptography/Extensions.HashAlgorithm.cs index d3172d5..f651029 100644 --- a/OnixLabs.Security.Cryptography/Extensions.HashAlgorithm.cs +++ b/OnixLabs.Security.Cryptography/Extensions.HashAlgorithm.cs @@ -90,7 +90,7 @@ public static byte[] ComputeHash(this HashAlgorithm algorithm, ReadOnlySpanReturns the computed hash value. /// If the hash could not be computed for the specified input data. public static byte[] ComputeHash(this HashAlgorithm algorithm, IBinaryConvertible data, int rounds = 1) => - algorithm.ComputeHash(data.ToByteArray(), rounds); + algorithm.ComputeHash(data.AsReadOnlySpan(), rounds); /// /// Computes the hash value for the specified value. @@ -103,7 +103,7 @@ public static byte[] ComputeHash(this HashAlgorithm algorithm, IBinaryConvertibl /// Returns the computed hash value. /// If the hash could not be computed for the specified input data. public static byte[] ComputeHash(this HashAlgorithm algorithm, IBinaryConvertible data, int offset, int count, int rounds = 1) => - algorithm.ComputeHash(data.ToByteArray(), offset, count, rounds); + algorithm.ComputeHash(data.AsReadOnlySpan(), offset, count, rounds); /// /// Computes the hash value for the specified value. @@ -114,7 +114,7 @@ public static byte[] ComputeHash(this HashAlgorithm algorithm, IBinaryConvertibl /// Returns the computed hash value. /// If the hash could not be computed for the specified input data. public static byte[] ComputeHash(this HashAlgorithm algorithm, ISpanBinaryConvertible data, int rounds = 1) => - algorithm.ComputeHash(data.ToReadOnlySpan(), rounds); + algorithm.ComputeHash(data.AsReadOnlySpan(), rounds); /// /// Computes the hash value for the specified value. @@ -127,7 +127,7 @@ public static byte[] ComputeHash(this HashAlgorithm algorithm, ISpanBinaryConver /// Returns the computed hash value. /// If the hash could not be computed for the specified input data. public static byte[] ComputeHash(this HashAlgorithm algorithm, ISpanBinaryConvertible data, int offset, int count, int rounds = 1) => - algorithm.ComputeHash(data.ToReadOnlySpan(), offset, count, rounds); + algorithm.ComputeHash(data.AsReadOnlySpan(), offset, count, rounds); /// /// Computes the hash value for the specified value. diff --git a/OnixLabs.Security.Cryptography/Hash.Compute.cs b/OnixLabs.Security.Cryptography/Hash.Compute.cs index b8e9204..5ba6484 100644 --- a/OnixLabs.Security.Cryptography/Hash.Compute.cs +++ b/OnixLabs.Security.Cryptography/Hash.Compute.cs @@ -94,7 +94,7 @@ public static Hash Compute(HashAlgorithm algorithm, IBinaryConvertible data, int /// The number of rounds that the input data should be hashed. /// Returns a cryptographic hash of the specified data. public static Hash Compute(HashAlgorithm algorithm, ISpanBinaryConvertible data, int rounds = 1) => - algorithm.ComputeHash(data.ToReadOnlySpan(), rounds); + algorithm.ComputeHash(data.AsReadOnlySpan(), rounds); /// /// Computes the hash value for the specified . diff --git a/OnixLabs.Security.Cryptography/Hash.Concatenate.cs b/OnixLabs.Security.Cryptography/Hash.Concatenate.cs index c87ac9b..0c0dc46 100644 --- a/OnixLabs.Security.Cryptography/Hash.Concatenate.cs +++ b/OnixLabs.Security.Cryptography/Hash.Concatenate.cs @@ -13,7 +13,6 @@ // limitations under the License. using System.Security.Cryptography; -using OnixLabs.Core; namespace OnixLabs.Security.Cryptography; @@ -28,7 +27,7 @@ public readonly partial struct Hash /// Returns a cryptographic hash representing the concatenation of the left-hand and right-hand hash values. public static Hash Concatenate(HashAlgorithm algorithm, Hash left, Hash right) { - byte[] data = left.ToByteArray().ConcatenateWith(right.ToByteArray()); + byte[] data = [..left.AsReadOnlySpan(), ..right.AsReadOnlySpan()]; byte[] hash = algorithm.ComputeHash(data); return new Hash(hash); } diff --git a/OnixLabs.Security.Cryptography/Hash.Convertible.cs b/OnixLabs.Security.Cryptography/Hash.Convertible.cs index cf12206..a73e4f2 100644 --- a/OnixLabs.Security.Cryptography/Hash.Convertible.cs +++ b/OnixLabs.Security.Cryptography/Hash.Convertible.cs @@ -19,6 +19,18 @@ namespace OnixLabs.Security.Cryptography; public readonly partial struct Hash { + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => value; + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => value; + /// /// Create a new instance from the specified value. /// diff --git a/OnixLabs.Security.Cryptography/Hash.To.cs b/OnixLabs.Security.Cryptography/Hash.To.cs index 7556dcc..18ce488 100644 --- a/OnixLabs.Security.Cryptography/Hash.To.cs +++ b/OnixLabs.Security.Cryptography/Hash.To.cs @@ -14,25 +14,12 @@ using System; using System.Security.Cryptography; -using OnixLabs.Core; using OnixLabs.Core.Text; namespace OnixLabs.Security.Cryptography; public readonly partial struct Hash { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => value.Copy(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => value; - /// /// Creates a new from the current instance. /// @@ -52,7 +39,7 @@ public readonly partial struct Hash /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => IBaseCodec.GetString(ToByteArray(), provider); + public string ToString(IFormatProvider provider) => IBaseCodec.GetString(AsReadOnlySpan(), provider); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.Cryptography/MerkleTree.Convertible.cs b/OnixLabs.Security.Cryptography/MerkleTree.Convertible.cs new file mode 100644 index 0000000..e0d9a49 --- /dev/null +++ b/OnixLabs.Security.Cryptography/MerkleTree.Convertible.cs @@ -0,0 +1,32 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; + +namespace OnixLabs.Security.Cryptography; + +public abstract partial class MerkleTree +{ + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => Hash.AsReadOnlyMemory(); + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => Hash.AsReadOnlySpan(); +} diff --git a/OnixLabs.Security.Cryptography/MerkleTree.To.cs b/OnixLabs.Security.Cryptography/MerkleTree.To.cs index 1c41968..6d50ee9 100644 --- a/OnixLabs.Security.Cryptography/MerkleTree.To.cs +++ b/OnixLabs.Security.Cryptography/MerkleTree.To.cs @@ -19,24 +19,12 @@ namespace OnixLabs.Security.Cryptography; public abstract partial class MerkleTree { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => Hash.ToByteArray(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => Hash.ToReadOnlySpan(); - /// /// Returns a that represents the current object. /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => IBaseCodec.GetString(ToByteArray(), provider); + public string ToString(IFormatProvider provider) => IBaseCodec.GetString(AsReadOnlySpan(), provider); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.Cryptography/NamedHash.Convertible.cs b/OnixLabs.Security.Cryptography/NamedHash.Convertible.cs new file mode 100644 index 0000000..1e99c9b --- /dev/null +++ b/OnixLabs.Security.Cryptography/NamedHash.Convertible.cs @@ -0,0 +1,35 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using OnixLabs.Core.Text; + +namespace OnixLabs.Security.Cryptography; + +public readonly partial record struct NamedHash +{ + /// + /// Gets the underlying representation of the underlying instance as a new instance. + /// This method only obtains the bytes representing the hash value. The name of the hash will not be encoded into the resulting span. + /// + /// Return the underlying representation of the underlying instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => Hash.AsReadOnlyMemory(); + + /// + /// Gets the underlying representation of the underlying instance as a new instance. + /// This method only obtains the bytes representing the hash value. The name of the hash will not be encoded into the resulting span. + /// + /// Return the underlying representation of the underlying instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => Hash.AsReadOnlySpan(); +} diff --git a/OnixLabs.Security.Cryptography/NamedHash.To.cs b/OnixLabs.Security.Cryptography/NamedHash.To.cs index 880b472..d92d1e0 100644 --- a/OnixLabs.Security.Cryptography/NamedHash.To.cs +++ b/OnixLabs.Security.Cryptography/NamedHash.To.cs @@ -19,26 +19,12 @@ namespace OnixLabs.Security.Cryptography; public readonly partial record struct NamedHash { - /// - /// Gets the underlying representation of the underlying instance. - /// This method only obtains the bytes representing the hash value. The name of the hash will not be encoded into the resulting byte array. - /// - /// Return the underlying representation of the underlying instance. - public byte[] ToByteArray() => Hash.ToByteArray(); - - /// - /// Gets the underlying representation of the underlying instance as a new instance. - /// This method only obtains the bytes representing the hash value. The name of the hash will not be encoded into the resulting span. - /// - /// Return the underlying representation of the underlying instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => Hash.ToReadOnlySpan(); - /// /// Returns a that represents the current object. /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => string.Concat(AlgorithmName, Separator, IBaseCodec.GetString(ToByteArray(), provider)); + public string ToString(IFormatProvider provider) => string.Concat(AlgorithmName, Separator, IBaseCodec.GetString(AsReadOnlySpan(), provider)); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.Cryptography/NamedPrivateKey.Convertible.cs b/OnixLabs.Security.Cryptography/NamedPrivateKey.Convertible.cs new file mode 100644 index 0000000..005b46b --- /dev/null +++ b/OnixLabs.Security.Cryptography/NamedPrivateKey.Convertible.cs @@ -0,0 +1,35 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using OnixLabs.Core.Text; + +namespace OnixLabs.Security.Cryptography; + +public readonly partial record struct NamedPrivateKey +{ + /// + /// Gets the underlying representation of the underlying instance as a new instance. + /// This method only obtains the bytes representing the private key value. The name of the private key will not be encoded into the resulting span. + /// + /// Return the underlying representation of the underlying instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => PrivateKey.AsReadOnlyMemory(); + + /// + /// Gets the underlying representation of the underlying instance as a new instance. + /// This method only obtains the bytes representing the private key value. The name of the private key will not be encoded into the resulting span. + /// + /// Return the underlying representation of the underlying instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => PrivateKey.AsReadOnlySpan(); +} diff --git a/OnixLabs.Security.Cryptography/NamedPrivateKey.To.cs b/OnixLabs.Security.Cryptography/NamedPrivateKey.To.cs index 61f9488..338f4d1 100644 --- a/OnixLabs.Security.Cryptography/NamedPrivateKey.To.cs +++ b/OnixLabs.Security.Cryptography/NamedPrivateKey.To.cs @@ -19,18 +19,12 @@ namespace OnixLabs.Security.Cryptography; public readonly partial record struct NamedPrivateKey { - /// - /// Gets the underlying representation of the underlying instance. - /// - /// Return the underlying representation of the underlying instance. - public byte[] ToByteArray() => PrivateKey.ToByteArray(); - /// /// Returns a that represents the current object. /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => string.Concat(AlgorithmName, Separator, IBaseCodec.GetString(ToByteArray(), provider)); + public string ToString(IFormatProvider provider) => string.Concat(AlgorithmName, Separator, IBaseCodec.GetString(AsReadOnlySpan(), provider)); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.Cryptography/NamedPublicKey.Convertible.cs b/OnixLabs.Security.Cryptography/NamedPublicKey.Convertible.cs new file mode 100644 index 0000000..d440af5 --- /dev/null +++ b/OnixLabs.Security.Cryptography/NamedPublicKey.Convertible.cs @@ -0,0 +1,35 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using OnixLabs.Core.Text; + +namespace OnixLabs.Security.Cryptography; + +public readonly partial record struct NamedPublicKey +{ + /// + /// Gets the underlying representation of the current instance as a new instance. + /// This method only obtains the bytes representing the public key value. The name of the public key will not be encoded into the resulting span. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => PublicKey.AsReadOnlyMemory(); + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// This method only obtains the bytes representing the public key value. The name of the public key will not be encoded into the resulting span. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => PublicKey.AsReadOnlySpan(); +} diff --git a/OnixLabs.Security.Cryptography/NamedPublicKey.To.cs b/OnixLabs.Security.Cryptography/NamedPublicKey.To.cs index db64c4e..8e13ec1 100644 --- a/OnixLabs.Security.Cryptography/NamedPublicKey.To.cs +++ b/OnixLabs.Security.Cryptography/NamedPublicKey.To.cs @@ -19,26 +19,12 @@ namespace OnixLabs.Security.Cryptography; public readonly partial record struct NamedPublicKey { - /// - /// Gets the underlying representation of the underlying instance. - /// This method only obtains the bytes representing the public key value. The name of the public key will not be encoded into the resulting byte array. - /// - /// Return the underlying representation of the underlying instance. - public byte[] ToByteArray() => PublicKey.ToByteArray(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// This method only obtains the bytes representing the public key value. The name of the public key will not be encoded into the resulting span. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => PublicKey.ToReadOnlySpan(); - /// /// Returns a that represents the current object. /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => string.Concat(AlgorithmName, Separator, IBaseCodec.GetString(ToByteArray(), provider)); + public string ToString(IFormatProvider provider) => string.Concat(AlgorithmName, Separator, IBaseCodec.GetString(AsReadOnlySpan(), provider)); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.Cryptography/OnixLabs.Security.Cryptography.csproj b/OnixLabs.Security.Cryptography/OnixLabs.Security.Cryptography.csproj index dc5ff6f..e98c97a 100644 --- a/OnixLabs.Security.Cryptography/OnixLabs.Security.Cryptography.csproj +++ b/OnixLabs.Security.Cryptography/OnixLabs.Security.Cryptography.csproj @@ -1,15 +1,7 @@ - net8.0 OnixLabs.Security.Cryptography - ONIXLabs ONIXLabs Cryptography API for .NET - en - enable - true - Copyright © ONIXLabs 2020 - https://github.com/onix-labs/onixlabs-dotnet - 12 $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb diff --git a/OnixLabs.Security.Cryptography/PrivateKey.Convertible.cs b/OnixLabs.Security.Cryptography/PrivateKey.Convertible.cs new file mode 100644 index 0000000..8424aeb --- /dev/null +++ b/OnixLabs.Security.Cryptography/PrivateKey.Convertible.cs @@ -0,0 +1,33 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using OnixLabs.Core.Text; + +namespace OnixLabs.Security.Cryptography; + +public abstract partial class PrivateKey +{ + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => KeyData; + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => KeyData; +} diff --git a/OnixLabs.Security.Cryptography/PrivateKey.Equatable.cs b/OnixLabs.Security.Cryptography/PrivateKey.Equatable.cs index 6d0effe..491e7cb 100644 --- a/OnixLabs.Security.Cryptography/PrivateKey.Equatable.cs +++ b/OnixLabs.Security.Cryptography/PrivateKey.Equatable.cs @@ -25,13 +25,11 @@ public abstract partial class PrivateKey /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(PrivateKey? other) - { - return ReferenceEquals(this, other) - || other is not null - && other.GetType() == GetType() - && other.KeyData.SequenceEqual(KeyData); - } + public bool Equals(PrivateKey? other) => + ReferenceEquals(this, other) + || other is not null + && other.GetType() == GetType() + && other.KeyData.SequenceEqual(KeyData); /// /// Checks for equality between the current instance and another object. diff --git a/OnixLabs.Security.Cryptography/PrivateKey.To.cs b/OnixLabs.Security.Cryptography/PrivateKey.To.cs index 41f0a45..c37db8a 100644 --- a/OnixLabs.Security.Cryptography/PrivateKey.To.cs +++ b/OnixLabs.Security.Cryptography/PrivateKey.To.cs @@ -13,19 +13,12 @@ // limitations under the License. using System; -using OnixLabs.Core; using OnixLabs.Core.Text; namespace OnixLabs.Security.Cryptography; public abstract partial class PrivateKey { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => KeyData.Copy(); - /// /// Creates a new from the current instance. /// @@ -37,7 +30,7 @@ public abstract partial class PrivateKey /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => IBaseCodec.GetString(ToByteArray(), provider); + public string ToString(IFormatProvider provider) => IBaseCodec.GetString(AsReadOnlySpan(), provider); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.Cryptography/ProtectedData.cs b/OnixLabs.Security.Cryptography/ProtectedData.cs index a36b4b7..3ffddbc 100644 --- a/OnixLabs.Security.Cryptography/ProtectedData.cs +++ b/OnixLabs.Security.Cryptography/ProtectedData.cs @@ -25,8 +25,8 @@ namespace OnixLabs.Security.Cryptography; // ReSharper disable HeapView.ObjectAllocation.Evident internal sealed class ProtectedData { - private readonly byte[] key = Salt.CreateNonZero(32).ToByteArray(); - private readonly byte[] iv = Salt.CreateNonZero(16).ToByteArray(); + private readonly byte[] key = Salt.CreateNonZero(32).AsReadOnlySpan().ToArray(); + private readonly byte[] iv = Salt.CreateNonZero(16).AsReadOnlySpan().ToArray(); /// /// Encrypted the specified data. diff --git a/OnixLabs.Security.Cryptography/PublicKey.Convertible.cs b/OnixLabs.Security.Cryptography/PublicKey.Convertible.cs new file mode 100644 index 0000000..44a5ec6 --- /dev/null +++ b/OnixLabs.Security.Cryptography/PublicKey.Convertible.cs @@ -0,0 +1,34 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using System.ComponentModel; +using OnixLabs.Core.Text; + +namespace OnixLabs.Security.Cryptography; + +public abstract partial class PublicKey +{ + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => KeyData; + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => KeyData; +} diff --git a/OnixLabs.Security.Cryptography/PublicKey.Equatable.cs b/OnixLabs.Security.Cryptography/PublicKey.Equatable.cs index a945851..e7011b7 100644 --- a/OnixLabs.Security.Cryptography/PublicKey.Equatable.cs +++ b/OnixLabs.Security.Cryptography/PublicKey.Equatable.cs @@ -25,13 +25,11 @@ public abstract partial class PublicKey /// /// An object to compare with the current object. /// Returns if the current object is equal to the other parameter; otherwise, . - public bool Equals(PublicKey? other) - { - return ReferenceEquals(this, other) - || other is not null - && other.GetType() == GetType() - && other.KeyData.SequenceEqual(KeyData); - } + public bool Equals(PublicKey? other) => + ReferenceEquals(this, other) + || other is not null + && other.GetType() == GetType() + && other.KeyData.SequenceEqual(KeyData); /// /// Checks for equality between the current instance and another object. diff --git a/OnixLabs.Security.Cryptography/PublicKey.To.cs b/OnixLabs.Security.Cryptography/PublicKey.To.cs index e303706..f412cc1 100644 --- a/OnixLabs.Security.Cryptography/PublicKey.To.cs +++ b/OnixLabs.Security.Cryptography/PublicKey.To.cs @@ -14,34 +14,12 @@ using System; using System.ComponentModel; -using OnixLabs.Core; using OnixLabs.Core.Text; namespace OnixLabs.Security.Cryptography; public abstract partial class PublicKey { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => KeyData.Copy(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => KeyData; - - /// - /// Creates a new from the current instance. - /// - /// The name of the algorithm that was used to produce the associated public key. - /// Returns a new from the current instance. - [EditorBrowsable(EditorBrowsableState.Never)] - [Obsolete("Passing custom algorithm names can lead to named keys. Use the parameterless ToNamedPublicKey method instead.")] - public NamedPublicKey ToNamedPublicKey(string algorithmName) => new(this, algorithmName); - /// /// Creates a new from the current instance. /// @@ -53,7 +31,7 @@ public abstract partial class PublicKey /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => IBaseCodec.GetString(ToByteArray(), provider); + public string ToString(IFormatProvider provider) => IBaseCodec.GetString(AsReadOnlySpan(), provider); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.Cryptography/RsaPrivateKey.Import.cs b/OnixLabs.Security.Cryptography/RsaPrivateKey.Import.cs index 5c7f65b..68fb460 100644 --- a/OnixLabs.Security.Cryptography/RsaPrivateKey.Import.cs +++ b/OnixLabs.Security.Cryptography/RsaPrivateKey.Import.cs @@ -58,7 +58,7 @@ public static RsaPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data) => /// The number of bytes read from the input data. /// Returns a new instance from the imported cryptographic private key data. public static RsaPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data, out int bytesRead) => - ImportPkcs8PrivateKey(data.ToByteArray(), out bytesRead); + ImportPkcs8PrivateKey(data.AsReadOnlySpan(), out bytesRead); /// /// Imports the RSA cryptographic private key data in encrypted PKCS #8 format. @@ -101,7 +101,7 @@ public static RsaPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data, ReadO /// The number of bytes read from the input data. /// Returns a new instance from the imported cryptographic private key data. public static RsaPrivateKey ImportPkcs8PrivateKey(IBinaryConvertible data, ReadOnlySpan password, out int bytesRead) => - ImportPkcs8PrivateKey(data.ToByteArray(), password, out bytesRead); + ImportPkcs8PrivateKey(data.AsReadOnlySpan(), password, out bytesRead); /// /// Imports the key data into a new instance. diff --git a/OnixLabs.Security.Cryptography/RsaPrivateKey.Sign.cs b/OnixLabs.Security.Cryptography/RsaPrivateKey.Sign.cs index f1908fb..40a68f1 100644 --- a/OnixLabs.Security.Cryptography/RsaPrivateKey.Sign.cs +++ b/OnixLabs.Security.Cryptography/RsaPrivateKey.Sign.cs @@ -72,7 +72,7 @@ public byte[] SignData(Stream data, HashAlgorithmName algorithm, RSASignaturePad public byte[] SignData(IBinaryConvertible data, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.SignData(data.ToByteArray(), algorithm, padding); + return key.SignData(data.AsReadOnlySpan(), algorithm, padding); } /// @@ -85,7 +85,7 @@ public byte[] SignData(IBinaryConvertible data, HashAlgorithmName algorithm, RSA public byte[] SignHash(Hash hash, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.SignHash(hash.ToByteArray(), algorithm, padding); + return key.SignHash(hash.AsReadOnlySpan(), algorithm, padding); } /// diff --git a/OnixLabs.Security.Cryptography/RsaPrivateKey.To.cs b/OnixLabs.Security.Cryptography/RsaPrivateKey.To.cs index dd289ed..4ae9ecf 100644 --- a/OnixLabs.Security.Cryptography/RsaPrivateKey.To.cs +++ b/OnixLabs.Security.Cryptography/RsaPrivateKey.To.cs @@ -16,9 +16,11 @@ namespace OnixLabs.Security.Cryptography; public sealed partial class RsaPrivateKey { + private const string KeyName = "RSA"; + /// /// Creates a new from the current instance. /// /// Returns a new from the current instance. - public override NamedPrivateKey ToNamedPrivateKey() => new(this, "RSA"); + public override NamedPrivateKey ToNamedPrivateKey() => new(this, KeyName); } diff --git a/OnixLabs.Security.Cryptography/RsaPublicKey.To.cs b/OnixLabs.Security.Cryptography/RsaPublicKey.To.cs index bdc7ef2..0ba2a7f 100644 --- a/OnixLabs.Security.Cryptography/RsaPublicKey.To.cs +++ b/OnixLabs.Security.Cryptography/RsaPublicKey.To.cs @@ -16,9 +16,11 @@ namespace OnixLabs.Security.Cryptography; public sealed partial class RsaPublicKey { + private const string KeyName = "RSA"; + /// /// Creates a new from the current instance. /// /// Returns a new from the current instance. - public override NamedPublicKey ToNamedPublicKey() => new(this, "RSA"); + public override NamedPublicKey ToNamedPublicKey() => new(this, KeyName); } diff --git a/OnixLabs.Security.Cryptography/RsaPublicKey.Verify.cs b/OnixLabs.Security.Cryptography/RsaPublicKey.Verify.cs index c383d76..952f2af 100644 --- a/OnixLabs.Security.Cryptography/RsaPublicKey.Verify.cs +++ b/OnixLabs.Security.Cryptography/RsaPublicKey.Verify.cs @@ -92,7 +92,7 @@ public bool IsDataValid(ReadOnlySpan signature, Stream data, HashAlgorithm public bool IsDataValid(ReadOnlySpan signature, IBinaryConvertible data, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.VerifyData(data.ToByteArray(), signature, algorithm, padding); + return key.VerifyData(data.AsReadOnlySpan(), signature, algorithm, padding); } /// @@ -110,7 +110,7 @@ public bool IsDataValid(ReadOnlySpan signature, IBinaryConvertible data, H public bool IsDataValid(DigitalSignature signature, ReadOnlySpan data, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.VerifyData(data, signature.ToByteArray(), algorithm, padding); + return key.VerifyData(data, signature.AsReadOnlySpan(), algorithm, padding); } /// @@ -130,7 +130,7 @@ public bool IsDataValid(DigitalSignature signature, ReadOnlySpan data, Has public bool IsDataValid(DigitalSignature signature, ReadOnlySpan data, int offset, int count, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.VerifyData(data.Slice(offset, count), signature.ToByteArray(), algorithm, padding); + return key.VerifyData(data.Slice(offset, count), signature.AsReadOnlySpan(), algorithm, padding); } /// @@ -148,7 +148,8 @@ public bool IsDataValid(DigitalSignature signature, ReadOnlySpan data, int public bool IsDataValid(DigitalSignature signature, Stream data, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.VerifyData(data, signature.ToByteArray(), algorithm, padding); + // TODO : Span for signature is inefficiently converted back to an array. + return key.VerifyData(data, signature.AsReadOnlySpan().ToArray(), algorithm, padding); } /// @@ -166,7 +167,7 @@ public bool IsDataValid(DigitalSignature signature, Stream data, HashAlgorithmNa public bool IsDataValid(DigitalSignature signature, IBinaryConvertible data, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.VerifyData(data.ToByteArray(), signature.ToByteArray(), algorithm, padding); + return key.VerifyData(data.AsReadOnlySpan(), signature.AsReadOnlySpan(), algorithm, padding); } /// @@ -202,7 +203,7 @@ public bool IsHashValid(ReadOnlySpan signature, ReadOnlySpan hash, H public bool IsHashValid(DigitalSignature signature, ReadOnlySpan hash, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.VerifyHash(hash, signature.ToByteArray(), algorithm, padding); + return key.VerifyHash(hash, signature.AsReadOnlySpan(), algorithm, padding); } /// @@ -220,7 +221,7 @@ public bool IsHashValid(DigitalSignature signature, ReadOnlySpan hash, Has public bool IsHashValid(ReadOnlySpan signature, Hash hash, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.VerifyHash(hash.ToByteArray(), signature, algorithm, padding); + return key.VerifyHash(hash.AsReadOnlySpan(), signature, algorithm, padding); } /// @@ -238,7 +239,7 @@ public bool IsHashValid(ReadOnlySpan signature, Hash hash, HashAlgorithmNa public bool IsHashValid(DigitalSignature signature, Hash hash, HashAlgorithmName algorithm, RSASignaturePadding padding) { using RSA key = ImportKeyData(); - return key.VerifyHash(hash.ToByteArray(), signature.ToByteArray(), algorithm, padding); + return key.VerifyHash(hash.AsReadOnlySpan(), signature.AsReadOnlySpan(), algorithm, padding); } /// diff --git a/OnixLabs.Security.Cryptography/Salt.Convertible.cs b/OnixLabs.Security.Cryptography/Salt.Convertible.cs new file mode 100644 index 0000000..1c86d1a --- /dev/null +++ b/OnixLabs.Security.Cryptography/Salt.Convertible.cs @@ -0,0 +1,32 @@ +// Copyright 2020 ONIXLabs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; + +namespace OnixLabs.Security.Cryptography; + +public readonly partial struct Salt +{ + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => value; + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => value; +} diff --git a/OnixLabs.Security.Cryptography/Salt.To.cs b/OnixLabs.Security.Cryptography/Salt.To.cs index e7668bb..a23319e 100644 --- a/OnixLabs.Security.Cryptography/Salt.To.cs +++ b/OnixLabs.Security.Cryptography/Salt.To.cs @@ -13,31 +13,18 @@ // limitations under the License. using System; -using OnixLabs.Core; using OnixLabs.Core.Text; namespace OnixLabs.Security.Cryptography; public readonly partial struct Salt { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => value.Copy(); - - /// - /// Gets the underlying representation of the current instance as a new instance. - /// - /// Return the underlying representation of the current instance as a new instance. - public ReadOnlySpan ToReadOnlySpan() => value; - /// /// Returns a that represents the current object. /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => IBaseCodec.GetString(ToByteArray(), provider); + public string ToString(IFormatProvider provider) => IBaseCodec.GetString(AsReadOnlySpan(), provider); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.Cryptography/Secret.Convertible.cs b/OnixLabs.Security.Cryptography/Secret.Convertible.cs index a4b16f1..64d047e 100644 --- a/OnixLabs.Security.Cryptography/Secret.Convertible.cs +++ b/OnixLabs.Security.Cryptography/Secret.Convertible.cs @@ -20,6 +20,18 @@ namespace OnixLabs.Security.Cryptography; public readonly partial struct Secret { + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlyMemory AsReadOnlyMemory() => protectedData.Decrypt(encryptedValue); + + /// + /// Gets the underlying representation of the current instance as a new instance. + /// + /// Return the underlying representation of the current instance as a new instance. + public ReadOnlySpan AsReadOnlySpan() => protectedData.Decrypt(encryptedValue); + /// /// Create a new instance from the specified value. /// diff --git a/OnixLabs.Security.Cryptography/Secret.To.cs b/OnixLabs.Security.Cryptography/Secret.To.cs index 3f0178c..76bdcfe 100644 --- a/OnixLabs.Security.Cryptography/Secret.To.cs +++ b/OnixLabs.Security.Cryptography/Secret.To.cs @@ -20,25 +20,19 @@ namespace OnixLabs.Security.Cryptography; public readonly partial struct Secret { - /// - /// Gets the underlying representation of the current instance. - /// - /// Return the underlying representation of the current instance. - public byte[] ToByteArray() => protectedData.Decrypt(encryptedValue); - /// /// Returns a that represents the current object. /// /// The encoding that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(Encoding encoding) => encoding.GetString(ToByteArray()); + public string ToString(Encoding encoding) => encoding.GetString(AsReadOnlySpan()); /// /// Returns a that represents the current object. /// /// The format provider that will be used to determine the format of the string. /// Returns a that represents the current object. - public string ToString(IFormatProvider provider) => IBaseCodec.GetString(ToByteArray(), provider); + public string ToString(IFormatProvider provider) => IBaseCodec.GetString(AsReadOnlySpan(), provider); /// /// Returns a that represents the current object. diff --git a/OnixLabs.Security.UnitTests/OnixLabs.Security.UnitTests.csproj b/OnixLabs.Security.UnitTests/OnixLabs.Security.UnitTests.csproj index bb58237..fdb9b73 100644 --- a/OnixLabs.Security.UnitTests/OnixLabs.Security.UnitTests.csproj +++ b/OnixLabs.Security.UnitTests/OnixLabs.Security.UnitTests.csproj @@ -1,33 +1,29 @@ - net8.0 - enable - enable - false true - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive - + - + diff --git a/OnixLabs.Security.UnitTests/SecurityTokenBuilderTests.cs b/OnixLabs.Security.UnitTests/SecurityTokenBuilderTests.cs index 2a30a0f..68f7202 100644 --- a/OnixLabs.Security.UnitTests/SecurityTokenBuilderTests.cs +++ b/OnixLabs.Security.UnitTests/SecurityTokenBuilderTests.cs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; + namespace OnixLabs.Security.UnitTests; public sealed class SecurityTokenBuilderTests diff --git a/OnixLabs.Security/OnixLabs.Security.csproj b/OnixLabs.Security/OnixLabs.Security.csproj index 6613c04..b9d3386 100644 --- a/OnixLabs.Security/OnixLabs.Security.csproj +++ b/OnixLabs.Security/OnixLabs.Security.csproj @@ -1,15 +1,7 @@  - net8.0 OnixLabs.Security - ONIXLabs ONIXLabs Security API for .NET - en - enable - true - Copyright © ONIXLabs 2020 - https://github.com/onix-labs/onixlabs-dotnet - 12 $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb