Skip to content

Commit

Permalink
Fix Bedrock.Framework nullability issues. (#163)
Browse files Browse the repository at this point in the history
* Fix Bedrock.Framework nullability issues. And introduced a property to store whether the `ProtocolReadResult` was faulty or not.

* Remove IsFaulted
  • Loading branch information
TheVeryStarlk authored Nov 18, 2024
1 parent 336929d commit a911300
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Bedrock.Framework/Middleware/Tls/TlsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public TlsOptions()
/// If the certificate has an Extended Key Usage extension, the usages must include Server Authentication (OID 1.3.6.1.5.5.7.3.1).
/// </para>
/// </summary>
public X509Certificate2 LocalCertificate { get; set; }
public X509Certificate2? LocalCertificate { get; set; }

/// <summary>
/// <para>
Expand All @@ -45,7 +45,7 @@ public TlsOptions()
/// If the certificate has an Extended Key Usage extension, the usages must include Server Authentication (OID 1.3.6.1.5.5.7.3.1).
/// </para>
/// </summary>
public Func<ConnectionContext, string, X509Certificate2> LocalServerCertificateSelector { get; set; }
public Func<ConnectionContext, string, X509Certificate2>? LocalServerCertificateSelector { get; set; }

/// <summary>
/// Specifies the remote endpoint certificate requirements for a TLS connection. Defaults to <see cref="RemoteCertificateMode.RequireCertificate"/>.
Expand All @@ -56,7 +56,7 @@ public TlsOptions()
/// Specifies a callback for additional remote certificate validation that will be invoked during authentication. This will be ignored
/// if <see cref="AllowAnyRemoteCertificate"/> is called after this callback is set.
/// </summary>
public RemoteCertificateValidator RemoteCertificateValidation { get; set; }
public RemoteCertificateValidator? RemoteCertificateValidation { get; set; }

/// <summary>
/// Specifies allowable SSL protocols. Defaults to <see cref="System.Security.Authentication.SslProtocols.Tls12" /> and <see cref="System.Security.Authentication.SslProtocols.Tls11"/>.
Expand Down Expand Up @@ -85,13 +85,13 @@ public void AllowAnyRemoteCertificate()
/// Provides direct configuration of the <see cref="SslServerAuthenticationOptions"/> on a per-connection basis.
/// This is called after all of the other settings have already been applied.
/// </summary>
public Action<ConnectionContext, SslServerAuthenticationOptions> OnAuthenticateAsServer { get; set; }
public Action<ConnectionContext, SslServerAuthenticationOptions>? OnAuthenticateAsServer { get; set; }

/// <summary>
/// Provides direct configuration of the <see cref="SslClientAuthenticationOptions"/> on a per-connection basis.
/// This is called after all of the other settings have already been applied.
/// </summary>
public Action<ConnectionContext, SslClientAuthenticationOptions> OnAuthenticateAsClient { get; set; }
public Action<ConnectionContext, SslClientAuthenticationOptions>? OnAuthenticateAsClient { get; set; }

/// <summary>
/// Specifies the maximum amount of time allowed for the TLS/SSL handshake. This must be positive and finite.
Expand Down
15 changes: 15 additions & 0 deletions src/Bedrock.Framework/Protocols/ProtocolReadResult.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace Bedrock.Framework.Protocols
{
/// <summary>
/// Represents a reading result from <see cref="ProtocolReader"/>.
/// </summary>
/// <typeparam name="TMessage">The read message.</typeparam>
public readonly struct ProtocolReadResult<TMessage>
{
public ProtocolReadResult(TMessage message, bool isCanceled, bool isCompleted)
Expand All @@ -9,8 +13,19 @@ public ProtocolReadResult(TMessage message, bool isCanceled, bool isCompleted)
IsCompleted = isCompleted;
}

/// <summary>
/// The read message.
/// </summary>
public TMessage Message { get; }

/// <summary>
/// Whether the reading operation was cancelled (true) or not (false).
/// </summary>
public bool IsCanceled { get; }

/// <summary>
/// Whether the reading operation was completed (true) or not (false).
/// </summary>
public bool IsCompleted { get; }
}
}

0 comments on commit a911300

Please sign in to comment.