Skip to content

Commit 5e39fbd

Browse files
committed
Small correction and simplification
1 parent 9023982 commit 5e39fbd

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

src/MongoDB.Driver.Encryption/KmsRequest.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,9 @@ public Binary GetMessage()
9595

9696
/// <summary>
9797
/// Indicates a network-level failure.
98-
/// It will set an error status if the request should not be retried.
9998
/// </summary>
100-
public void Fail()
101-
{
102-
Check(Library.mongocrypt_kms_ctx_fail(_id));
103-
}
99+
/// <returns>A boolean indicating whether the failed request may be retried.</returns>
100+
public bool Fail() => Library.mongocrypt_kms_ctx_fail(_id);
104101

105102
/// <summary>
106103
/// Feeds the response back to the libmongocrypt

src/MongoDB.Driver.Encryption/LibMongoCryptControllerBase.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -306,38 +306,40 @@ private async Task SendKmsRequestAsync(KmsRequest request, CancellationToken can
306306

307307
var tlsStreamSettings = GetTlsStreamSettings(request.KmsProvider);
308308
var sslStreamFactory = new SslStreamFactory(tlsStreamSettings, _networkStreamFactory);
309-
using (var sslStream = await sslStreamFactory.CreateStreamAsync(endpoint, cancellation).ConfigureAwait(false))
310-
using (var binary = request.GetMessage())
311-
{
312-
var requestBytes = binary.ToArray();
309+
using var sslStream = await sslStreamFactory.CreateStreamAsync(endpoint, cancellation).ConfigureAwait(false);
310+
using var binary = request.GetMessage();
313311

314-
var sleepMs = request.Sleep;
315-
if (sleepMs > 0)
316-
{
317-
await Task.Delay(sleepMs, cancellation).ConfigureAwait(false);
318-
}
312+
var requestBytes = binary.ToArray();
319313

320-
await sslStream.WriteAsync(requestBytes, 0, requestBytes.Length).ConfigureAwait(false);
314+
var sleepMs = request.Sleep;
315+
if (sleepMs > 0)
316+
{
317+
await Task.Delay(sleepMs, cancellation).ConfigureAwait(false);
318+
}
321319

322-
while (request.BytesNeeded > 0)
323-
{
324-
var buffer = new byte[request.BytesNeeded]; // BytesNeeded is the maximum number of bytes that libmongocrypt wants to receive.
325-
var count = await sslStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
320+
await sslStream.WriteAsync(requestBytes, 0, requestBytes.Length).ConfigureAwait(false);
326321

327-
if (count == 0)
328-
{
329-
throw new IOException();
330-
}
322+
while (request.BytesNeeded > 0)
323+
{
324+
var buffer = new byte[request.BytesNeeded]; // BytesNeeded is the maximum number of bytes that libmongocrypt wants to receive.
325+
var count = await sslStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
331326

332-
var responseBytes = new byte[count];
333-
Buffer.BlockCopy(buffer, 0, responseBytes, 0, count);
334-
request.Feed(responseBytes);
327+
if (count == 0)
328+
{
329+
throw new IOException();
335330
}
331+
332+
var responseBytes = new byte[count];
333+
Buffer.BlockCopy(buffer, 0, responseBytes, 0, count);
334+
request.Feed(responseBytes);
336335
}
337336
}
338337
catch (Exception ex) when (ex is IOException or SocketException)
339338
{
340-
request.Fail();
339+
if (!request.Fail())
340+
{
341+
throw;
342+
}
341343
}
342344
}
343345

tests/MongoDB.Driver.Tests/Specifications/client-side-encryption/prose-tests/ClientEncryptionProseTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,8 @@ HttpClient GetClient()
15221522
{
15231523
ClientCertificates =
15241524
{
1525-
new X509Certificate2(Environment.GetEnvironmentVariable("MONGO_X509_CLIENT_CERTIFICATE_PATH")!)
1525+
new X509Certificate2(Environment.GetEnvironmentVariable("MONGO_X509_CLIENT_CERTIFICATE_PATH")!,
1526+
Environment.GetEnvironmentVariable("MONGO_X509_CLIENT_CERTIFICATE_PASSWORD"))
15261527
},
15271528
};
15281529

0 commit comments

Comments
 (0)