diff --git a/EnvelopeGenerator.Application/EncodeType.cs b/EnvelopeGenerator.Application/EncodeType.cs new file mode 100644 index 00000000..677073df --- /dev/null +++ b/EnvelopeGenerator.Application/EncodeType.cs @@ -0,0 +1,9 @@ +namespace EnvelopeGenerator.Application +{ + public enum EncodeType + { + EnvelopeReceiver, + ReadOnly, + Undefined + } +} \ No newline at end of file diff --git a/EnvelopeGenerator.Application/EnvelopeGeneratorExtensions.cs b/EnvelopeGenerator.Application/EnvelopeGeneratorExtensions.cs index 875dad1c..b2a7475c 100644 --- a/EnvelopeGenerator.Application/EnvelopeGeneratorExtensions.cs +++ b/EnvelopeGenerator.Application/EnvelopeGeneratorExtensions.cs @@ -68,6 +68,26 @@ namespace EnvelopeGenerator.Application return input.IndexOf('=') == -1; // No padding allowed except at the end } + public static bool TryDecode(this string encoded, out string[] decoded) + { + if (!encoded.IsBase64String()) + { + decoded = Array.Empty(); + return false; + } + byte[] bytes = Convert.FromBase64String(encoded); + string decodedString = Encoding.UTF8.GetString(bytes); + decoded = decodedString.Split(new string[] { "::" }, StringSplitOptions.None); + return true; + } + + public static EncodeType GetEncodeType(string[] decoded) => decoded.Length switch + { + 2 => EncodeType.EnvelopeReceiver, + 3 => EncodeType.ReadOnly, + _ => EncodeType.Undefined, + }; + /// /// Decodes the envelope receiver ID and extracts the envelope UUID and receiver signature. /// @@ -80,7 +100,7 @@ namespace EnvelopeGenerator.Application return (null, null); } byte[] bytes = Convert.FromBase64String(envelopeReceiverId); - string decodedString = System.Text.Encoding.UTF8.GetString(bytes); + string decodedString = Encoding.UTF8.GetString(bytes); string[] parts = decodedString.Split(new string[] { "::" }, StringSplitOptions.None); if (parts.Length > 1)