Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,11 @@ internal static int Encrypt(SafeSslHandle context, ReadOnlySpan<byte> input, ref
int retVal;
Exception? innerError = null;

lock (context)
{
retVal = Ssl.SslWrite(context, ref MemoryMarshal.GetReference(input), input.Length);
retVal = Ssl.SslWrite(context, ref MemoryMarshal.GetReference(input), input.Length);

if (retVal != input.Length)
{
errorCode = GetSslError(context, retVal, out innerError);
}
if (retVal != input.Length)
{
errorCode = GetSslError(context, retVal, out innerError);
}

if (retVal != input.Length)
Expand Down Expand Up @@ -390,30 +387,27 @@ internal static int Decrypt(SafeSslHandle context, byte[] outBuffer, int offset,
int retVal = BioWrite(context.InputBio!, outBuffer, offset, count);
Exception? innerError = null;

lock (context)
if (retVal == count)
{
if (retVal == count)
unsafe
{
unsafe
fixed (byte* fixedBuffer = outBuffer)
{
fixed (byte* fixedBuffer = outBuffer)
{
retVal = Ssl.SslRead(context, fixedBuffer + offset, outBuffer.Length);
}
}

if (retVal > 0)
{
count = retVal;
retVal = Ssl.SslRead(context, fixedBuffer + offset, outBuffer.Length);
}
}

if (retVal != count)
if (retVal > 0)
{
errorCode = GetSslError(context, retVal, out innerError);
count = retVal;
}
}

if (retVal != count)
{
errorCode = GetSslError(context, retVal, out innerError);
}

if (retVal != count)
{
retVal = 0;
Expand Down
1 change: 1 addition & 0 deletions src/libraries/Common/src/System/Net/SecurityStatusPal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal enum SecurityStatusPalErrorCode
ContextExpired,
CredentialsNeeded,
Renegotiate,
TryAgain,

// Errors
OutOfMemory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ public partial class SslStream
private interface ISslIOAdapter
{
ValueTask<int> ReadAsync(Memory<byte> buffer);
ValueTask<int> ReadLockAsync(Memory<byte> buffer);
Task WriteLockAsync();
ValueTask WriteAsync(byte[] buffer, int offset, int count);
Task WaitAsync(TaskCompletionSource<bool> waiter);
CancellationToken CancellationToken { get; }
}

Expand All @@ -31,12 +30,10 @@ public AsyncSslIOAdapter(SslStream sslStream, CancellationToken cancellationToke

public ValueTask<int> ReadAsync(Memory<byte> buffer) => _sslStream.InnerStream.ReadAsync(buffer, _cancellationToken);

public ValueTask<int> ReadLockAsync(Memory<byte> buffer) => _sslStream.CheckEnqueueReadAsync(buffer);

public Task WriteLockAsync() => _sslStream.CheckEnqueueWriteAsync();

public ValueTask WriteAsync(byte[] buffer, int offset, int count) => _sslStream.InnerStream.WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), _cancellationToken);

public Task WaitAsync(TaskCompletionSource<bool> waiter) => waiter.Task;

public CancellationToken CancellationToken => _cancellationToken;
}

Expand All @@ -48,17 +45,15 @@ public AsyncSslIOAdapter(SslStream sslStream, CancellationToken cancellationToke

public ValueTask<int> ReadAsync(Memory<byte> buffer) => new ValueTask<int>(_sslStream.InnerStream.Read(buffer.Span));

public ValueTask<int> ReadLockAsync(Memory<byte> buffer) => new ValueTask<int>(_sslStream.CheckEnqueueRead(buffer));

public ValueTask WriteAsync(byte[] buffer, int offset, int count)
{
_sslStream.InnerStream.Write(buffer, offset, count);
return default;
}

public Task WriteLockAsync()
public Task WaitAsync(TaskCompletionSource<bool> waiter)
{
_sslStream.CheckEnqueueWrite();
waiter.Task.Wait();
return Task.CompletedTask;
}

Expand Down
Loading