Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix interface inconsistency SecurableDuplexPipe #240

Merged
merged 2 commits into from
Oct 3, 2024
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
4 changes: 4 additions & 0 deletions Examples/SampleApp/Examples/CustomEndpointListenerExample.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.IO.Pipelines;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
Expand Down Expand Up @@ -95,6 +96,9 @@ public void Dispose()
public PipeWriter Output => _securableDuplexPipe.Output;

public bool IsSecure => _securableDuplexPipe.IsSecure;

/// <inheritdoc />
public SslProtocols SslProtocol => (_securableDuplexPipe as SslStream)?.SslProtocol ?? SslProtocols.None;
}

public sealed class LoggingPipeReader : PipeReader
Expand Down
5 changes: 5 additions & 0 deletions Src/SmtpServer/IO/ISecurableDuplexPipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ public interface ISecurableDuplexPipe : IDuplexPipe, IDisposable
/// Returns a value indicating whether or not the current pipeline is secure.
/// </summary>
bool IsSecure { get; }

/// <summary>
/// Returns the used SslProtocol of a secure pipeline
/// </summary>
SslProtocols SslProtocol { get; }
}
}
16 changes: 3 additions & 13 deletions Src/SmtpServer/IO/SecurableDuplexPipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ internal SecurableDuplexPipe(Stream stream, Action disposeAction)
Output = PipeWriter.Create(_stream);
}

/// <summary>
/// Upgrade to a secure pipeline.
/// </summary>
/// <param name="certificate">The X509Certificate used to authenticate the server.</param>
/// <param name="protocols">The value that represents the protocol used for authentication.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>A task that asynchronously performs the operation.</returns>
/// <inheritdoc />
public async Task UpgradeAsync(X509Certificate certificate, SslProtocols protocols, CancellationToken cancellationToken = default)
{
var sslStream = new SslStream(_stream, true);
Expand Down Expand Up @@ -100,14 +94,10 @@ public void Dispose()
/// </summary>
public PipeWriter Output { get; private set; }

/// <summary>
/// Returns a value indicating whether or not the current pipeline is secure.
/// </summary>
/// <inheritdoc />
public bool IsSecure => _stream is SslStream;

/// <summary>
/// Returns the used SslProtocol of a secure pipeline
/// </summary>
/// <inheritdoc />
public SslProtocols SslProtocol => (_stream as SslStream)?.SslProtocol ?? SslProtocols.None;
}
}
Loading