Skip to content

Commit

Permalink
Fix interface inconsistency SecurableDuplexPipe (#240)
Browse files Browse the repository at this point in the history
* Fix interface inconsistency SecurableDuplexPipe

* Update CustomEndpointListenerExample.cs
  • Loading branch information
tinohager authored Oct 3, 2024
1 parent ba859f6 commit ed310ba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
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;
}
}

0 comments on commit ed310ba

Please sign in to comment.