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. ///