KeePassLib.Cryptography.HashingStreamEx.HashingStreamEx C# (CSharp) Method

HashingStreamEx() public method

public HashingStreamEx ( Stream sBaseStream, bool bWriting, HashAlgorithm hashAlgorithm ) : System
sBaseStream Stream
bWriting bool
hashAlgorithm System.Security.Cryptography.HashAlgorithm
return System
        public HashingStreamEx(Stream sBaseStream, bool bWriting, HashAlgorithm hashAlgorithm)
        {
            if(sBaseStream == null) throw new ArgumentNullException("sBaseStream");

            m_sBaseStream = sBaseStream;
            m_bWriting = bWriting;

            #if !KeePassLibSD
            m_hash = (hashAlgorithm ?? new SHA256Managed());
            #else // KeePassLibSD
            m_hash = null;

            try { m_hash = HashAlgorithm.Create("SHA256"); }
            catch(Exception) { }
            try { if(m_hash == null) m_hash = HashAlgorithm.Create(); }
            catch(Exception) { }
            #endif
            if(m_hash == null) { Debug.Assert(false); return; }

            // Validate hash algorithm
            if((!m_hash.CanReuseTransform) || (!m_hash.CanTransformMultipleBlocks) ||
                (m_hash.InputBlockSize != 1) || (m_hash.OutputBlockSize != 1))
            {
            #if DEBUG
                MessageService.ShowWarning("Broken HashAlgorithm object in HashingStreamEx.");
            #endif
                m_hash = null;
            }
        }