From 792aa0b92251efcfb235768d329c8197101553c0 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 1 Oct 2024 16:44:46 +0200 Subject: [PATCH] =?UTF-8?q?feat(decode):=20Methoden=20zur=20Konvertierung?= =?UTF-8?q?=20des=20dekodierten=20Arrays=20in=20eine=20Umschlag-Empf=C3=A4?= =?UTF-8?q?nger-ID=20und=20eine=20Nur-Lese-ID=20mit=20Ausnahmewirkung=20hi?= =?UTF-8?q?nzugef=C3=BCgt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EnvelopeGeneratorExtensions.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/EnvelopeGenerator.Application/EnvelopeGeneratorExtensions.cs b/EnvelopeGenerator.Application/EnvelopeGeneratorExtensions.cs index b2a7475c..51daee31 100644 --- a/EnvelopeGenerator.Application/EnvelopeGeneratorExtensions.cs +++ b/EnvelopeGenerator.Application/EnvelopeGeneratorExtensions.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using System.Security.Cryptography; using System.Text; namespace EnvelopeGenerator.Application @@ -81,13 +80,23 @@ namespace EnvelopeGenerator.Application return true; } - public static EncodeType GetEncodeType(string[] decoded) => decoded.Length switch + public static EncodeType GetEncodeType(this string[] decoded) => decoded.Length switch { 2 => EncodeType.EnvelopeReceiver, - 3 => EncodeType.ReadOnly, + 3 => long.TryParse(decoded[1], out var _) ? EncodeType.ReadOnly : EncodeType.Undefined, _ => EncodeType.Undefined, }; - + + public static (string? EnvelopeUuid, string? ReceiverSignature) ToEnvelopeReceiverId(this string[] decoded) + => decoded.GetEncodeType() == EncodeType.EnvelopeReceiver + ? (EnvelopeUuid: decoded[0], ReceiverSignature: decoded[1]) + : throw new InvalidOperationException("Attempted to convert a decoded other than type EnvelopeReceiver to EnvelopeReceiver. "); + + public static long ToReadOnlyId(this string[] decoded) + => decoded.GetEncodeType() == EncodeType.ReadOnly + ? long.Parse(decoded[1]) + : throw new InvalidOperationException("Attempted to convert a decoded other than type EnvelopeReceiver to EnvelopeReceiver. "); + /// /// Decodes the envelope receiver ID and extracts the envelope UUID and receiver signature. ///