System.Net.Security.SslStreamPal.EncryptDecryptHelper C# (CSharp) Method

EncryptDecryptHelper() private static method

private static EncryptDecryptHelper ( System.Net.Security.SafeDeleteContext securityContext, byte input, int offset, int size, bool encrypt, byte &output, int &resultSize ) : SecurityStatusPal
securityContext System.Net.Security.SafeDeleteContext
input byte
offset int
size int
encrypt bool
output byte
resultSize int
return SecurityStatusPal
        private static SecurityStatusPal EncryptDecryptHelper(SafeDeleteContext securityContext, byte[] input, int offset, int size, bool encrypt, ref byte[] output, out int resultSize)
        {
            resultSize = 0;
            try
            {
                Interop.Ssl.SslErrorCode errorCode = Interop.Ssl.SslErrorCode.SSL_ERROR_NONE;
                SafeSslHandle scHandle = ((SafeDeleteSslContext)securityContext).SslContext;

                if (encrypt)
                {
                    resultSize = Interop.OpenSsl.Encrypt(scHandle, input, offset, size, ref output, out errorCode);
                }
                else
                {
                    Debug.Assert(offset == 0, "Expected offset 0 when decrypting");
                    Debug.Assert(ReferenceEquals(input, output), "Expected input==output when decrypting");
                    resultSize = Interop.OpenSsl.Decrypt(scHandle, input, size, out errorCode);
                }

                switch (errorCode)
                {
                    case Interop.Ssl.SslErrorCode.SSL_ERROR_RENEGOTIATE:
                        return new SecurityStatusPal(SecurityStatusPalErrorCode.Renegotiate);
                    case Interop.Ssl.SslErrorCode.SSL_ERROR_ZERO_RETURN:
                        return new SecurityStatusPal(SecurityStatusPalErrorCode.ContextExpired);
                    case Interop.Ssl.SslErrorCode.SSL_ERROR_NONE:
                    case Interop.Ssl.SslErrorCode.SSL_ERROR_WANT_READ:
                        return new SecurityStatusPal(SecurityStatusPalErrorCode.OK);
                    default:
                        return new SecurityStatusPal(SecurityStatusPalErrorCode.InternalError, new Interop.OpenSsl.SslException((int)errorCode));
                }
            }
            catch (Exception ex)
            {
                return new SecurityStatusPal(SecurityStatusPalErrorCode.InternalError, ex);
            }
        }