39 lines
2.0 KiB
C#
39 lines
2.0 KiB
C#
namespace EnvelopeGenerator.Application.Services
|
|
{
|
|
/// <summary>
|
|
/// Provides extension methods for decoding and extracting information from an envelope receiver ID.
|
|
/// </summary>
|
|
public static class EnvelopeGeneratorExtensions
|
|
{
|
|
/// <summary>
|
|
/// Decodes the envelope receiver ID and extracts the envelope UUID and receiver signature.
|
|
/// </summary>
|
|
/// <param name="envelopeReceiverId">The base64 encoded string containing the envelope UUID and receiver signature.</param>
|
|
/// <returns>A tuple containing the envelope UUID and receiver signature.</returns>
|
|
public static (string EnvelopeUuid, string ReceiverSignature) DecodeEnvelopeReceiverId(this string envelopeReceiverId)
|
|
{
|
|
byte[] bytes = Convert.FromBase64String(envelopeReceiverId);
|
|
string decodedString = System.Text.Encoding.UTF8.GetString(bytes);
|
|
string[] parts = decodedString.Split(new string[] { "::" }, StringSplitOptions.None);
|
|
|
|
if (parts.Length > 1)
|
|
return (EnvelopeUuid: parts[0], ReceiverSignature: parts[1]);
|
|
else
|
|
return (string.Empty, string.Empty);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the envelope UUID from the decoded envelope receiver ID.
|
|
/// </summary>
|
|
/// <param name="envelopeReceiverId">The base64 encoded string to decode.</param>
|
|
/// <returns>The envelope UUID.</returns>
|
|
public static string GetEnvelopeUuid(this string envelopeReceiverId) => envelopeReceiverId.DecodeEnvelopeReceiverId().EnvelopeUuid;
|
|
|
|
/// <summary>
|
|
/// Gets the receiver signature from the decoded envelope receiver ID.
|
|
/// </summary>
|
|
/// <param name="envelopeReceiverId">The base64 encoded string to decode.</param>
|
|
/// <returns>The receiver signature.</returns>
|
|
public static string GetReceiverSignature(this string envelopeReceiverId) => envelopeReceiverId.DecodeEnvelopeReceiverId().ReceiverSignature;
|
|
}
|
|
} |