Beispiel #1
0
        private static async Task <Dictionary <string, SslExtension> > ReadExtensions(int majorVersion, int minorVersion, CustomBufferedPeekStream peekStream)
        {
            Dictionary <string, SslExtension> extensions = null;

            if (majorVersion > 3 || majorVersion == 3 && minorVersion >= 1)
            {
                if (await peekStream.EnsureBufferLength(2))
                {
                    int extensionsLength = peekStream.ReadInt16();

                    if (await peekStream.EnsureBufferLength(extensionsLength))
                    {
                        extensions = new Dictionary <string, SslExtension>();
                        int idx = 0;
                        while (extensionsLength > 3)
                        {
                            int    id        = peekStream.ReadInt16();
                            int    length    = peekStream.ReadInt16();
                            byte[] data      = peekStream.ReadBytes(length);
                            var    extension = SslExtensions.GetExtension(id, data, idx++);
                            extensions[extension.Name] = extension;
                            extensionsLength          -= 4 + length;
                        }
                    }
                }
            }

            return(extensions);
        }
Beispiel #2
0
        private static async Task <List <SslExtension> > ReadExtensions(int majorVersion, int minorVersion, CustomBufferedPeekStream peekStream)
        {
            List <SslExtension> extensions = null;

            if (majorVersion > 3 || majorVersion == 3 && minorVersion >= 1)
            {
                if (await peekStream.EnsureBufferLength(2))
                {
                    int extensionsLength = peekStream.ReadInt16();

                    if (await peekStream.EnsureBufferLength(extensionsLength))
                    {
                        extensions = new List <SslExtension>();
                        while (extensionsLength > 3)
                        {
                            int    id     = peekStream.ReadInt16();
                            int    length = peekStream.ReadInt16();
                            byte[] data   = peekStream.ReadBytes(length);
                            extensions.Add(SslExtensions.GetExtension(id, data));
                            extensionsLength -= 4 + length;
                        }
                    }
                }
            }

            return(extensions);
        }