namespace EnvelopeGenerator.Application.Services
{
///
/// Provides extension methods for decoding and extracting information from an envelope receiver ID.
///
public static class EnvelopeGeneratorExtensions
{
///
/// Decodes the envelope receiver ID and extracts the envelope UUID and receiver signature.
///
/// The base64 encoded string containing the envelope UUID and receiver signature.
/// A tuple containing the envelope UUID and receiver signature.
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);
}
///
/// Gets the envelope UUID from the decoded envelope receiver ID.
///
/// The base64 encoded string to decode.
/// The envelope UUID.
public static string GetEnvelopeUuid(this string envelopeReceiverId) => envelopeReceiverId.DecodeEnvelopeReceiverId().EnvelopeUuid;
///
/// Gets the receiver signature from the decoded envelope receiver ID.
///
/// The base64 encoded string to decode.
/// The receiver signature.
public static string GetReceiverSignature(this string envelopeReceiverId) => envelopeReceiverId.DecodeEnvelopeReceiverId().ReceiverSignature;
}
}