feat(EncodeType): Enum zur Klassifizierung von Kodierungstypen erstellt.

- Erweiterungsmethoden hinzugefügt, um zu versuchen, String mit out-keyworld zu dekodieren.

- Erweiterungsmethode hinzugefügt, um den Typ des Kodierungstyps des dekodierten String-Arrays zu finden.
This commit is contained in:
Developer 02 2024-10-01 16:04:44 +02:00
parent 54e86b421c
commit 6847b74095
2 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,9 @@
namespace EnvelopeGenerator.Application
{
public enum EncodeType
{
EnvelopeReceiver,
ReadOnly,
Undefined
}
}

View File

@ -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<string>();
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,
};
/// <summary>
/// Decodes the envelope receiver ID and extracts the envelope UUID and receiver signature.
/// </summary>
@ -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)