in AwsEncryptionSDK/runtimes/net/TestVectorsNative/TestVectors/TestVectors.cs [75:124]
public override IEnumerator<object[]> GetEnumerator()
{
long count = 0;
foreach(var vectorEntry in VectorMap) {
if (!TargetVector(vectorEntry))
{
continue;
}
DecryptVector vector = vectorEntry.Value;
byte[] plaintext = null;
if (vector.Result is {Output: not null})
{
if (vector.Result.Output.Plaintext != null)
{
string plaintextPath = Utils.ManifestUriToPath(vector.Result.Output.Plaintext, VectorRoot);
if (!File.Exists(plaintextPath))
{
throw new ArgumentException($"Could not find plaintext file at path: {plaintextPath}");
}
plaintext = File.ReadAllBytes(plaintextPath);
}
}
string errorMessage = null;
if (vector.Result != null && vector.Result.Error != null)
{
errorMessage = vector.Result.Error.ErrorMessage;
}
string ciphertextPath = Utils.ManifestUriToPath(vector.Ciphertext, VectorRoot);
if (!File.Exists(ciphertextPath)) {
throw new ArgumentException($"Could not find ciphertext file at path: {ciphertextPath}");
}
byte[] ciphertext = File.ReadAllBytes(Utils.ManifestUriToPath(vector.Ciphertext, VectorRoot));
MemoryStream ciphertextStream = new MemoryStream(ciphertext);
yield return new object[] { vectorEntry.Key, vector, KeyMap, plaintext, errorMessage, ciphertextStream, _netV400RetryPolicy };
count++;
}
// If nothing gets `yield return`-ed, xUnit gives an unclear error message. This error is better.
if (count == 0)
{
throw new Exception("No targeted vectors found");
}
}