< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 64
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
OnContextInitialized()100%110%
Handshake()100%110%
Read(...)100%110%
Write(...)100%110%
Shutdown()100%110%
RequestClientCertificate()100%110%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Net.Security/src/System/Net/Security/TlsSocketSession.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics.CodeAnalysis;
 5using System.Net.Sockets;
 6
 7namespace System.Net.Security
 8{
 9    /// <summary>
 10    /// Non-blocking TLS session bound to a caller-supplied non-blocking
 11    /// <see cref="SafeSocketHandle"/>. The session performs its own ciphertext
 12    /// I/O on the socket via <see cref="Handshake"/>, <see cref="Read"/>,
 13    /// <see cref="Write"/>, <see cref="Shutdown"/>, and
 14    /// <see cref="RequestClientCertificate"/>. The socket must be configured
 15    /// non-blocking; behavior on a blocking socket is unspecified.
 16    /// </summary>
 17    /// <remarks>
 18    /// The session takes ownership of the supplied socket and disposes it with
 19    /// the session. Call <see cref="TlsSession.SetContext"/> with a client or
 20    /// server <see cref="TlsContext"/> before invoking any operation.
 21    /// </remarks>
 22    [Experimental(Experimentals.LowLevelTlsDiagId, UrlFormat = Experimentals.SharedUrlFormat)]
 23    public sealed class TlsSocketSession : TlsSession
 24    {
 25        private readonly SafeSocketHandle _socket;
 26
 027        public TlsSocketSession(SafeSocketHandle socket)
 028        {
 029            ArgumentNullException.ThrowIfNull(socket);
 030            _socket = socket;
 031        }
 32
 33        internal override void OnContextInitialized()
 034        {
 035            AttachSocket(_socket);
 036        }
 37
 38        /// <summary>The socket the session is bound to. Owned by the session.</summary>
 039        public SafeSocketHandle Socket => _socket;
 40
 41        /// <summary>Drives the TLS handshake to completion, sending and receiving via the socket.</summary>
 042        public TlsOperationStatus Handshake() => HandshakeSocketCore();
 43
 44        /// <summary>Reads decrypted application bytes from the socket into <paramref name="buffer"/>.</summary>
 45        public TlsOperationStatus Read(Span<byte> buffer, out int bytesRead)
 046            => ReadSocketCore(buffer, out bytesRead);
 47
 48        /// <summary>Encrypts and sends <paramref name="buffer"/> as one or more TLS records over the socket.</summary>
 49        public TlsOperationStatus Write(ReadOnlySpan<byte> buffer, out int bytesWritten)
 050            => WriteSocketCore(buffer, out bytesWritten);
 51
 52        /// <summary>Sends a TLS <c>close_notify</c> alert on the socket.</summary>
 053        public TlsOperationStatus Shutdown() => ShutdownSocketCore();
 54
 55        /// <summary>Server-side only. Requests a client certificate on the socket: a <c>CertificateRequest</c> for TLS 
 56        /// <remarks>
 57        /// If the TLS 1.3 client did not offer post-handshake authentication, no request is sent:
 58        /// the method returns <see cref="TlsOperationStatus.Complete"/>, the handshake stays complete, no client
 59        /// certificate is received, and the session remains usable.
 60        /// </remarks>
 061        public TlsOperationStatus RequestClientCertificate() => RequestClientCertificateSocketCore();
 62    }
 63}
 64