Skip to content

Commit 571fcf7

Browse files
committed
Changed StringExt.cs HmacSha256 to public from internal
1 parent 502a56f commit 571fcf7

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/Klean.EntityFrameworkCore.DataProtection/Extensions/StringExt.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
using System.Security.Cryptography;
22
using System.Text;
33

4-
namespace EntityFrameworkCore.DataProtection.Extensions;
4+
// ReSharper disable once CheckNamespace
5+
namespace System;
56

67
/// <summary>
78
/// Provides extensions for the <see cref="string"/> type.
89
/// </summary>
9-
internal static class StringExt
10+
public static class StringExt
1011
{
11-
internal const string EnvKey = "EFCORE_DATA_PROTECTION__HASHING_SALT";
12+
/// <summary>
13+
/// The environment variable key for the hashing salt. `EFCORE_DATA_PROTECTION__HASHING_SALT`
14+
/// </summary>
15+
public const string HashingSaltKey = "EFCORE_DATA_PROTECTION__HASHING_SALT";
1216

13-
internal static string HmacSha256Hash(this string value)
17+
/// <summary>
18+
/// Hashes the string using HMACSHA256
19+
/// </summary>
20+
/// <param name="value">The value to hash</param>
21+
/// <returns>Hashed value as hex lowercase</returns>
22+
/// <exception cref="InvalidOperationException">If `EFCORE_DATA_PROTECTION__HASHING_SALT` is not present in the environment</exception>
23+
public static string HmacSha256Hash(this string value)
1424
{
1525
var salt =
16-
Environment.GetEnvironmentVariable(EnvKey)
17-
?? throw new InvalidOperationException($"{EnvKey} is not present in the environment, please set it to a strong value and keep it safe, otherwise querying will not work.");
26+
Environment.GetEnvironmentVariable(HashingSaltKey)
27+
?? throw new InvalidOperationException($"{HashingSaltKey} is not present in the environment, please set it to a strong value and keep it safe, otherwise querying will not work.");
1828

1929
var saltBytes = Encoding.UTF8.GetBytes(salt);
2030
var payloadBytes = Encoding.UTF8.GetBytes(value);

src/Klean.EntityFrameworkCore.DataProtection/Klean.EntityFrameworkCore.DataProtection.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>1.2.0</Version>
4+
<Version>1.2.1</Version>
55
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>

test/Klean.EntityFrameworkCore.DataProtection.Test/DbContext.Test.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ internal sealed class DbContextTests
1010
[OneTimeSetUp]
1111
public void InitializeEnv()
1212
{
13-
var value = Environment.GetEnvironmentVariable(StringExt.EnvKey);
14-
Environment.SetEnvironmentVariable(StringExt.EnvKey, value ?? Guid.NewGuid().ToString());
13+
var value = Environment.GetEnvironmentVariable(StringExt.HashingSaltKey);
14+
Environment.SetEnvironmentVariable(StringExt.HashingSaltKey, value ?? Guid.NewGuid().ToString());
1515
}
1616

1717
[Test]

test/Klean.EntityFrameworkCore.DataProtection.Test/StringExt.Test.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ internal sealed class StringExtTests
88
[OneTimeSetUp]
99
public void InitializeEnv()
1010
{
11-
var value = Environment.GetEnvironmentVariable(StringExt.EnvKey);
12-
Environment.SetEnvironmentVariable(StringExt.EnvKey, value ?? Guid.NewGuid().ToString());
11+
var value = Environment.GetEnvironmentVariable(StringExt.HashingSaltKey);
12+
Environment.SetEnvironmentVariable(StringExt.HashingSaltKey, value ?? Guid.NewGuid().ToString());
1313
}
1414

1515
[Test]

0 commit comments

Comments
 (0)