feat(HashAlgorithmNameConverter): Erstellt für benutzerfreundlichere json de/serilization.
- DI-Erweiterungsmethoden hinzugefügt
This commit is contained in:
parent
8076efb934
commit
2e68a37944
@ -5,11 +5,23 @@ using Microsoft.Extensions.Configuration;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace DigitalData.Core.Security
|
namespace DigitalData.Core.Security
|
||||||
{
|
{
|
||||||
public static class DIExtensions
|
public static class DIExtensions
|
||||||
{
|
{
|
||||||
|
public static JsonSerializerOptions TryAddCryptographerConverter(this JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
if (!options.Converters.OfType<HashAlgorithmNameConverter>().Any())
|
||||||
|
options.Converters.Add(new HashAlgorithmNameConverter());
|
||||||
|
|
||||||
|
if (!options.Converters.OfType<JsonStringEnumConverter>().Any())
|
||||||
|
options.Converters.Add(new JsonStringEnumConverter());
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
private static IServiceCollection AddAsymCryptService<TAsymCryptParams>(this IServiceCollection services)
|
private static IServiceCollection AddAsymCryptService<TAsymCryptParams>(this IServiceCollection services)
|
||||||
where TAsymCryptParams : AsymCryptParams
|
where TAsymCryptParams : AsymCryptParams
|
||||||
{
|
{
|
||||||
|
|||||||
13
DigitalData.Core.Security/HashAlgorithmNameConverter.cs
Normal file
13
DigitalData.Core.Security/HashAlgorithmNameConverter.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace DigitalData.Core.Security
|
||||||
|
{
|
||||||
|
public class HashAlgorithmNameConverter : JsonConverter<HashAlgorithmName>
|
||||||
|
{
|
||||||
|
public override HashAlgorithmName Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => new(reader.GetString() ?? string.Empty);
|
||||||
|
|
||||||
|
public override void Write(Utf8JsonWriter writer, HashAlgorithmName value, JsonSerializerOptions options) => writer.WriteStringValue(value.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user