Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMatthewLayton committed Sep 30, 2021
2 parents 4fcb88b + 36877f7 commit 0b63d69
Show file tree
Hide file tree
Showing 21 changed files with 272 additions and 51 deletions.
6 changes: 1 addition & 5 deletions OnixLabs.Core/Enumeration.Equatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ public override bool Equals(object? obj)
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode()
{
return new HashCode()
.AddItem(GetType())
.AddItem(Name)
.AddItem(Value)
.ToHashCode();
return HashCode.Combine(GetType(), Name, Value);
}
}
}
11 changes: 11 additions & 0 deletions OnixLabs.Core/Linq/IEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ public static bool AnyEqualBy<TElement, TProperty>(
return elements.Any(element => Equals(first, selector(element)));
}

/// <summary>
/// Computes the content hash code of the elements of this <see cref="IEnumerable{T}"/>.
/// </summary>
/// <param name="enumerable">The <see cref="IEnumerable{T}"/> from which to compute a content hash code.</param>
/// <typeparam name="T">The underlying type of the <see cref="IEnumerable{T}"/>.</typeparam>
/// <returns>Returns the computed content hash code of this <see cref="IEnumerable{T}"/>.</returns>
public static int ComputeContentHashCode<T>(this IEnumerable<T> enumerable)
{
return new HashCode().AddItems(enumerable).ToHashCode();
}

/// <summary>
/// Performs the specified <see cref="Action{T}"/> for each element of this <see cref="IEnumerable{T}"/>.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion OnixLabs.Core/OnixLabs.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<NeutralLanguage>en</NeutralLanguage>
<Copyright>Copyright © ONIXLabs 2020-2021</Copyright>
<RepositoryUrl>https://github.com/onix-labs/onixlabs-dotnet</RepositoryUrl>
<PackageVersion>3.0.0</PackageVersion>
<PackageVersion>3.1.0</PackageVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
34 changes: 34 additions & 0 deletions OnixLabs.Core/Text/Base16.Empty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020-2021 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.Text
{
public readonly partial struct Base16
{
/// <summary>
/// Gets an empty Base-16 value.
/// </summary>
public static readonly Base16 Empty;

/// <summary>
/// Initializes static members of the <see cref="Base16"/> class.
/// </summary>
static Base16()
{
Empty = FromByteArray(Array.Empty<byte>());
}
}
}
5 changes: 2 additions & 3 deletions OnixLabs.Core/Text/Base16.Equatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using System;
using System.Linq;
using OnixLabs.Core.Linq;

namespace OnixLabs.Core.Text
{
Expand Down Expand Up @@ -67,9 +68,7 @@ public override bool Equals(object? obj)
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode()
{
return new HashCode()
.AddItems(Value)
.ToHashCode();
return HashCode.Combine(Value.ComputeContentHashCode());
}
}
}
34 changes: 34 additions & 0 deletions OnixLabs.Core/Text/Base32.Empty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020-2021 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.Text
{
public readonly partial struct Base32
{
/// <summary>
/// Gets an empty Base-32 value.
/// </summary>
public static readonly Base32 Empty;

/// <summary>
/// Initializes static members of the <see cref="Base32"/> class.
/// </summary>
static Base32()
{
Empty = FromByteArray(Array.Empty<byte>());
}
}
}
5 changes: 2 additions & 3 deletions OnixLabs.Core/Text/Base32.Equatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using System;
using System.Linq;
using OnixLabs.Core.Linq;

namespace OnixLabs.Core.Text
{
Expand Down Expand Up @@ -69,9 +70,7 @@ public override bool Equals(object? obj)
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode()
{
return new HashCode()
.AddItems(Value)
.ToHashCode();
return HashCode.Combine(Value.ComputeContentHashCode());
}
}
}
34 changes: 34 additions & 0 deletions OnixLabs.Core/Text/Base58.Empty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020-2021 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.Text
{
public readonly partial struct Base58
{
/// <summary>
/// Gets an empty Base-58 value.
/// </summary>
public static readonly Base58 Empty;

/// <summary>
/// Initializes static members of the <see cref="Base58"/> class.
/// </summary>
static Base58()
{
Empty = FromByteArray(Array.Empty<byte>());
}
}
}
5 changes: 2 additions & 3 deletions OnixLabs.Core/Text/Base58.Equatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using System;
using System.Linq;
using OnixLabs.Core.Linq;

namespace OnixLabs.Core.Text
{
Expand Down Expand Up @@ -68,9 +69,7 @@ public override bool Equals(object? obj)
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode()
{
return new HashCode()
.AddItems(Value)
.ToHashCode();
return HashCode.Combine(Value.ComputeContentHashCode());
}
}
}
34 changes: 34 additions & 0 deletions OnixLabs.Core/Text/Base64.Empty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020-2021 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.Text
{
public readonly partial struct Base64
{
/// <summary>
/// Gets an empty Base-64 value.
/// </summary>
public static readonly Base64 Empty;

/// <summary>
/// Initializes static members of the <see cref="Base64"/> class.
/// </summary>
static Base64()
{
Empty = FromByteArray(Array.Empty<byte>());
}
}
}
5 changes: 2 additions & 3 deletions OnixLabs.Core/Text/Base64.Equatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using System;
using System.Linq;
using OnixLabs.Core.Linq;

namespace OnixLabs.Core.Text
{
Expand Down Expand Up @@ -67,9 +68,7 @@ public override bool Equals(object? obj)
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode()
{
return new HashCode()
.AddItems(Value)
.ToHashCode();
return HashCode.Combine(Value.ComputeContentHashCode());
}
}
}
34 changes: 34 additions & 0 deletions OnixLabs.Security.Cryptography/DigitalSignature.Empty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020-2021 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 DigitalSignature
{
/// <summary>
/// Gets an empty digital signature value.
/// </summary>
public static readonly DigitalSignature Empty;

/// <summary>
/// Initializes static members of the <see cref="DigitalSignature"/> class.
/// </summary>
static DigitalSignature()
{
Empty = FromByteArray(Array.Empty<byte>());
}
}
}
6 changes: 2 additions & 4 deletions OnixLabs.Security.Cryptography/DigitalSignature.Equatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

using System;
using System.Linq;
using OnixLabs.Core;
using OnixLabs.Core.Linq;

namespace OnixLabs.Security.Cryptography
{
Expand Down Expand Up @@ -68,9 +68,7 @@ public override bool Equals(object? obj)
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode()
{
return new HashCode()
.AddItems(Value)
.ToHashCode();
return HashCode.Combine(Value.ComputeContentHashCode());
}
}
}
34 changes: 34 additions & 0 deletions OnixLabs.Security.Cryptography/Hash.Empty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2020-2021 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 Hash
{
/// <summary>
/// Gets an empty hash value.
/// </summary>
public static readonly Hash Empty;

/// <summary>
/// Initializes static members of the <see cref="Hash"/> class.
/// </summary>
static Hash()
{
Empty = FromByteArray(Array.Empty<byte>(), HashAlgorithmType.Unknown);
}
}
}
9 changes: 3 additions & 6 deletions OnixLabs.Security.Cryptography/Hash.Equatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

using System;
using System.Linq;
using OnixLabs.Core;
using OnixLabs.Core.Linq;

namespace OnixLabs.Security.Cryptography
{
Expand Down Expand Up @@ -49,7 +49,7 @@ namespace OnixLabs.Security.Cryptography
/// <returns>true if the object is equal to this instance; otherwise, false.</returns>
public bool Equals(Hash other)
{
return other.AlgorithmType == AlgorithmType
return other.AlgorithmType == AlgorithmType
&& other.Value.SequenceEqual(Value);
}

Expand All @@ -69,10 +69,7 @@ public override bool Equals(object? obj)
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode()
{
return new HashCode()
.AddItem(AlgorithmType)
.AddItems(Value)
.ToHashCode();
return HashCode.Combine(AlgorithmType, Value.ComputeContentHashCode());
}
}
}
Loading

0 comments on commit 0b63d69

Please sign in to comment.