CheckUint16() public static method

public static CheckUint16 ( int i ) : void
i int
return void
示例#1
0
        protected internal static void WriteSupplementalData(System.IO.Stream output, IList supplementalData)
        {
            MemoryStream stream     = new MemoryStream();
            IEnumerator  enumerator = supplementalData.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    SupplementalDataEntry current = (SupplementalDataEntry)enumerator.Current;
                    int dataType = current.DataType;
                    TlsUtilities.CheckUint16(dataType);
                    TlsUtilities.WriteUint16(dataType, stream);
                    TlsUtilities.WriteOpaque16(current.Data, stream);
                }
            }
            finally
            {
                if (enumerator is IDisposable disposable)
                {
                    IDisposable disposable;
                    disposable.Dispose();
                }
            }
            TlsUtilities.WriteOpaque24(stream.ToArray(), output);
        }
示例#2
0
 public virtual void Encode(Stream output)
 {
     //IL_001f: Unknown result type (might be due to invalid IL or missing references)
     //IL_0025: Expected O, but got Unknown
     if (mResponderIDList == null || ((global::System.Collections.ICollection)mResponderIDList).get_Count() < 1)
     {
         TlsUtilities.WriteUint16(0, output);
     }
     else
     {
         MemoryStream val = new MemoryStream();
         for (int i = 0; i < ((global::System.Collections.ICollection)mResponderIDList).get_Count(); i++)
         {
             ResponderID responderID = (ResponderID)mResponderIDList.get_Item(i);
             byte[]      encoded     = responderID.GetEncoded("DER");
             TlsUtilities.WriteOpaque16(encoded, (Stream)(object)val);
         }
         TlsUtilities.CheckUint16(((Stream)val).get_Length());
         TlsUtilities.WriteUint16((int)((Stream)val).get_Length(), output);
         val.WriteTo(output);
     }
     if (mRequestExtensions == null)
     {
         TlsUtilities.WriteUint16(0, output);
         return;
     }
     byte[] encoded2 = mRequestExtensions.GetEncoded("DER");
     TlsUtilities.CheckUint16(encoded2.Length);
     TlsUtilities.WriteUint16(encoded2.Length, output);
     output.Write(encoded2, 0, encoded2.Length);
 }
示例#3
0
        public static void EncodeSupportedSignatureAlgorithms(IList supportedSignatureAlgorithms, bool allowAnonymous,
                                                              Stream output)
        {
            if (supportedSignatureAlgorithms == null || supportedSignatureAlgorithms.Count < 1 ||
                supportedSignatureAlgorithms.Count >= (1 << 15))
            {
                throw new ArgumentException("must have length from 1 to (2^15 - 1)", "supportedSignatureAlgorithms");
            }

            // supported_signature_algorithms
            int length = 2 * supportedSignatureAlgorithms.Count;

            TlsUtilities.CheckUint16(length);
            TlsUtilities.WriteUint16(length, output);

            foreach (SignatureAndHashAlgorithm entry in supportedSignatureAlgorithms)
            {
                if (!allowAnonymous && entry.Signature == SignatureAlgorithm.anonymous)
                {
                    /*
                     * RFC 5246 7.4.1.4.1 The "anonymous" value is meaningless in this context but used
                     * in Section 7.4.3. It MUST NOT appear in this extension.
                     */
                    throw new ArgumentException(
                              "SignatureAlgorithm.anonymous MUST NOT appear in the signature_algorithms extension");
                }
                entry.Encode(output);
            }
        }
示例#4
0
        protected internal static void WriteSelectedExtensions(System.IO.Stream output, IDictionary extensions, bool selectEmpty)
        {
            IEnumerator enumerator = extensions.Keys.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    int    current = (int)enumerator.Current;
                    byte[] buf     = (byte[])extensions[current];
                    if (selectEmpty == (buf.Length == 0))
                    {
                        TlsUtilities.CheckUint16(current);
                        TlsUtilities.WriteUint16(current, output);
                        TlsUtilities.WriteOpaque16(buf, output);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable disposable)
                {
                    IDisposable disposable;
                    disposable.Dispose();
                }
            }
        }
 public virtual void Encode(Stream output)
 {
     if ((this.mResponderIDList == null) || (this.mResponderIDList.Count < 1))
     {
         TlsUtilities.WriteUint16(0, output);
     }
     else
     {
         MemoryStream stream = new MemoryStream();
         for (int i = 0; i < this.mResponderIDList.Count; i++)
         {
             ResponderID rid = (ResponderID)this.mResponderIDList[i];
             TlsUtilities.WriteOpaque16(rid.GetEncoded("DER"), stream);
         }
         TlsUtilities.CheckUint16(stream.Length);
         TlsUtilities.WriteUint16((int)stream.Length, output);
         stream.WriteTo(output);
     }
     if (this.mRequestExtensions == null)
     {
         TlsUtilities.WriteUint16(0, output);
     }
     else
     {
         byte[] encoded = this.mRequestExtensions.GetEncoded("DER");
         TlsUtilities.CheckUint16(encoded.Length);
         TlsUtilities.WriteUint16(encoded.Length, output);
         output.Write(encoded, 0, encoded.Length);
     }
 }
示例#6
0
		public virtual void Encode(Stream output)
		{
			if (mResponderIDList == null || mResponderIDList.Count < 1)
			{
				TlsUtilities.WriteUint16(0, output);
			}
			else
			{
				MemoryStream memoryStream = new MemoryStream();
				for (int i = 0; i < mResponderIDList.Count; i++)
				{
					ResponderID responderID = (ResponderID)mResponderIDList[i];
					byte[] encoded = responderID.GetEncoded("DER");
					TlsUtilities.WriteOpaque16(encoded, memoryStream);
				}
				TlsUtilities.CheckUint16(memoryStream.Length);
				TlsUtilities.WriteUint16((int)memoryStream.Length, output);
				memoryStream.WriteTo(output);
			}
			if (mRequestExtensions == null)
			{
				TlsUtilities.WriteUint16(0, output);
			}
			else
			{
				byte[] encoded2 = mRequestExtensions.GetEncoded("DER");
				TlsUtilities.CheckUint16(encoded2.Length);
				TlsUtilities.WriteUint16(encoded2.Length, output);
				output.Write(encoded2, 0, encoded2.Length);
			}
		}
示例#7
0
        protected internal static void WriteExtensions(Stream output, IDictionary extensions)
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0006: Expected O, but got Unknown
            MemoryStream val = new MemoryStream();

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)extensions.get_Keys()).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    int    num = (int)enumerator.get_Current();
                    byte[] buf = (byte[])extensions.get_Item((object)num);
                    TlsUtilities.CheckUint16(num);
                    TlsUtilities.WriteUint16(num, (Stream)(object)val);
                    TlsUtilities.WriteOpaque16(buf, (Stream)(object)val);
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            byte[] buf2 = val.ToArray();
            TlsUtilities.WriteOpaque16(buf2, output);
        }
示例#8
0
        protected internal static void WriteSupplementalData(Stream output, global::System.Collections.IList supplementalData)
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0006: Expected O, but got Unknown
            MemoryStream val = new MemoryStream();

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)supplementalData).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    SupplementalDataEntry supplementalDataEntry = (SupplementalDataEntry)enumerator.get_Current();
                    int dataType = supplementalDataEntry.DataType;
                    TlsUtilities.CheckUint16(dataType);
                    TlsUtilities.WriteUint16(dataType, (Stream)(object)val);
                    TlsUtilities.WriteOpaque16(supplementalDataEntry.Data, (Stream)(object)val);
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            byte[] buf = val.ToArray();
            TlsUtilities.WriteOpaque24(buf, output);
        }
示例#9
0
        public virtual void Encode(Stream output)
        {
            //IL_0000: Unknown result type (might be due to invalid IL or missing references)
            //IL_0006: Expected O, but got Unknown
            MemoryStream val = new MemoryStream();

            global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)ServerNames).GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    ServerName serverName = (ServerName)enumerator.get_Current();
                    serverName.Encode((Stream)(object)val);
                }
            }
            finally
            {
                global::System.IDisposable disposable = enumerator as global::System.IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            TlsUtilities.CheckUint16(((Stream)val).get_Length());
            TlsUtilities.WriteUint16((int)((Stream)val).get_Length(), output);
            val.WriteTo(output);
        }
示例#10
0
        /**
         * Parse a {@link HeartbeatMessage} from a {@link Stream}.
         *
         * @param input
         *            the {@link Stream} to parse from.
         * @return a {@link HeartbeatMessage} object.
         * @throws IOException
         */
        public static HeartbeatMessage Parse(Stream input)
        {
            byte type = TlsUtilities.ReadUint8(input);

            if (!HeartbeatMessageType.IsValid(type))
            {
                throw new TlsFatalAlert(AlertDescription.illegal_parameter);
            }

            int payload_length = TlsUtilities.ReadUint16(input);

            PayloadBuffer buf = new PayloadBuffer();

            Streams.PipeAll(input, buf);

            byte[] payload = buf.ToTruncatedByteArray(payload_length);
            if (payload == null)
            {
                /*
                 * RFC 6520 4. If the payload_length of a received HeartbeatMessage is too large, the
                 * received HeartbeatMessage MUST be discarded silently.
                 */
                return(null);
            }

            TlsUtilities.CheckUint16(buf.Length);
            int padding_length = (int)buf.Length - payload.Length;

            /*
             * RFC 6520 4. The padding of a received HeartbeatMessage message MUST be ignored
             */
            return(new HeartbeatMessage(type, payload, padding_length));
        }
示例#11
0
        public virtual void Encode(Stream output)
        {
            MemoryStream stream = new MemoryStream();

            byte[]      emptyBytes = TlsUtilities.EmptyBytes;
            IEnumerator enumerator = this.ServerNames.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    ServerName current = (ServerName)enumerator.Current;
                    emptyBytes = CheckNameType(emptyBytes, current.NameType);
                    if (emptyBytes == null)
                    {
                        throw new TlsFatalAlert(80);
                    }
                    current.Encode(stream);
                }
            }
            finally
            {
                if (enumerator is IDisposable disposable)
                {
                    IDisposable disposable;
                    disposable.Dispose();
                }
            }
            TlsUtilities.CheckUint16(stream.Length);
            TlsUtilities.WriteUint16((int)stream.Length, output);
            stream.WriteTo(output);
        }
        public virtual void Encode(Stream output)
        {
            if (this.mCertificateTypes == null || this.mCertificateTypes.Length == 0)
            {
                TlsUtilities.WriteUint8(0, output);
            }
            else
            {
                TlsUtilities.WriteUint8ArrayWithUint8Length(this.mCertificateTypes, output);
            }
            if (this.mSupportedSignatureAlgorithms != null)
            {
                TlsUtilities.EncodeSupportedSignatureAlgorithms(this.mSupportedSignatureAlgorithms, false, output);
            }
            if (this.mCertificateAuthorities == null || this.mCertificateAuthorities.Count < 1)
            {
                TlsUtilities.WriteUint16(0, output);
                return;
            }
            IList list = Platform.CreateArrayList(this.mCertificateAuthorities.Count);
            int   num  = 0;

            foreach (Asn1Encodable asn1Encodable in this.mCertificateAuthorities)
            {
                byte[] encoded = asn1Encodable.GetEncoded("DER");
                list.Add(encoded);
                num += encoded.Length + 2;
            }
            TlsUtilities.CheckUint16(num);
            TlsUtilities.WriteUint16(num, output);
            foreach (byte[] buf in list)
            {
                TlsUtilities.WriteOpaque16(buf, output);
            }
        }
示例#13
0
        /**
         * Encode this {@link OcspStatusRequest} to a {@link Stream}.
         *
         * @param output
         *            the {@link Stream} to encode to.
         * @throws IOException
         */
        public virtual void Encode(Stream output)
        {
            if (mResponderIDList == null || mResponderIDList.Count < 1)
            {
                TlsUtilities.WriteUint16(0, output);
            }
            else
            {
                MemoryStream buf = new MemoryStream();
                for (int i = 0; i < mResponderIDList.Count; ++i)
                {
                    ResponderID responderID = (ResponderID)mResponderIDList[i];
                    byte[]      derEncoding = responderID.GetEncoded(Asn1Encodable.Der);
                    TlsUtilities.WriteOpaque16(derEncoding, buf);
                }
                TlsUtilities.CheckUint16(buf.Length);
                TlsUtilities.WriteUint16((int)buf.Length, output);
                buf.WriteTo(output);
            }

            if (mRequestExtensions == null)
            {
                TlsUtilities.WriteUint16(0, output);
            }
            else
            {
                byte[] derEncoding = mRequestExtensions.GetEncoded(Asn1Encodable.Der);
                TlsUtilities.CheckUint16(derEncoding.Length);
                TlsUtilities.WriteUint16(derEncoding.Length, output);
                output.Write(derEncoding, 0, derEncoding.Length);
            }
        }
示例#14
0
 public virtual void Encode(TlsContext context, Stream output)
 {
     TlsUtilities.WriteUint8(mType, output);
     TlsUtilities.CheckUint16(mPayload.Length);
     TlsUtilities.WriteUint16(mPayload.Length, output);
     output.Write(mPayload, 0, mPayload.Length);
     byte[] array = new byte[mPaddingLength];
     context.NonceRandomGenerator.NextBytes(array);
     output.Write(array, 0, array.Length);
 }
示例#15
0
            internal void EncodeTo(Stream output)
            {
                long num = this.Length - 2L;

                TlsUtilities.CheckUint16(num);
                this.Position = 0L;
                TlsUtilities.WriteUint16((int)num, this);
                this.WriteTo(output);
                this.Close();
            }
示例#16
0
            internal void EncodeTo(Stream output)
            {
                long num = ((Stream)this).get_Length() - 2;

                TlsUtilities.CheckUint16(num);
                ((Stream)this).set_Position(0L);
                TlsUtilities.WriteUint16((int)num, (Stream)(object)this);
                ((MemoryStream)this).WriteTo(output);
                Platform.Dispose((Stream)(object)this);
            }
示例#17
0
 public static void WriteNamedECParameters(int namedCurve, Stream output)
 {
     if (!NamedCurve.RefersToASpecificNamedCurve(namedCurve))
     {
         throw new TlsFatalAlert(80);
     }
     TlsUtilities.WriteUint8(3, output);
     TlsUtilities.CheckUint16(namedCurve);
     TlsUtilities.WriteUint16(namedCurve, output);
 }
示例#18
0
            internal void EncodeTo(Stream output)
            {
                // Patch actual length back in
                long length = Length - 2;

                TlsUtilities.CheckUint16(length);
                this.Position = 0;
                TlsUtilities.WriteUint16((int)length, this);
                this.WriteTo(output);
                Platform.Dispose(this);
            }
示例#19
0
        public virtual void Encode(Stream output)
        {
            MemoryStream memoryStream = new MemoryStream();

            foreach (ServerName serverName in ServerNames)
            {
                serverName.Encode(memoryStream);
            }
            TlsUtilities.CheckUint16(memoryStream.Length);
            TlsUtilities.WriteUint16((int)memoryStream.Length, output);
            memoryStream.WriteTo(output);
        }
示例#20
0
        /**
         * Encode this {@link ServerNameList} to a {@link Stream}.
         *
         * @param output
         *            the {@link Stream} to encode to.
         * @throws IOException
         */
        public virtual void Encode(Stream output)
        {
            MemoryStream buf = new MemoryStream();

            foreach (ServerName entry in ServerNames)
            {
                entry.Encode(buf);
            }

            TlsUtilities.CheckUint16(buf.Length);
            TlsUtilities.WriteUint16((int)buf.Length, output);
            buf.WriteTo(output);
        }
示例#21
0
        public static void WriteExplicitECParameters(byte[] ecPointFormats, ECDomainParameters ecParameters,
                                                     Stream output)
        {
            ECCurve curve = ecParameters.Curve;

            if (ECAlgorithms.IsFpCurve(curve))
            {
                TlsUtilities.WriteUint8(ECCurveType.explicit_prime, output);

                WriteECParameter(curve.Field.Characteristic, output);
            }
            else if (ECAlgorithms.IsF2mCurve(curve))
            {
                IPolynomialExtensionField field = (IPolynomialExtensionField)curve.Field;
                int[] exponents = field.MinimalPolynomial.GetExponentsPresent();

                TlsUtilities.WriteUint8(ECCurveType.explicit_char2, output);

                int m = exponents[exponents.Length - 1];
                TlsUtilities.CheckUint16(m);
                TlsUtilities.WriteUint16(m, output);

                if (exponents.Length == 3)
                {
                    TlsUtilities.WriteUint8(ECBasisType.ec_basis_trinomial, output);
                    WriteECExponent(exponents[1], output);
                }
                else if (exponents.Length == 5)
                {
                    TlsUtilities.WriteUint8(ECBasisType.ec_basis_pentanomial, output);
                    WriteECExponent(exponents[1], output);
                    WriteECExponent(exponents[2], output);
                    WriteECExponent(exponents[3], output);
                }
                else
                {
                    throw new ArgumentException("Only trinomial and pentomial curves are supported");
                }
            }
            else
            {
                throw new ArgumentException("'ecParameters' not a known curve type");
            }

            WriteECFieldElement(curve.A, output);
            WriteECFieldElement(curve.B, output);
            TlsUtilities.WriteOpaque8(SerializeECPoint(ecPointFormats, ecParameters.G), output);
            WriteECParameter(ecParameters.N, output);
            WriteECParameter(ecParameters.H, output);
        }
示例#22
0
        protected internal static void WriteSupplementalData(Stream output, IList supplementalData)
        {
            MemoryStream memoryStream = new MemoryStream();

            foreach (SupplementalDataEntry supplementalDataEntry in supplementalData)
            {
                int dataType = supplementalDataEntry.DataType;
                TlsUtilities.CheckUint16(dataType);
                TlsUtilities.WriteUint16(dataType, memoryStream);
                TlsUtilities.WriteOpaque16(supplementalDataEntry.Data, memoryStream);
            }
            byte[] buf = memoryStream.ToArray();
            TlsUtilities.WriteOpaque24(buf, output);
        }
示例#23
0
        protected internal static void WriteExtensions(Stream output, IDictionary extensions)
        {
            MemoryStream memoryStream = new MemoryStream();

            foreach (int num in extensions.Keys)
            {
                byte[] buf = (byte[])extensions[num];
                TlsUtilities.CheckUint16(num);
                TlsUtilities.WriteUint16(num, memoryStream);
                TlsUtilities.WriteOpaque16(buf, memoryStream);
            }
            byte[] buf2 = memoryStream.ToArray();
            TlsUtilities.WriteOpaque16(buf2, output);
        }
示例#24
0
        public static void WriteNamedECParameters(int namedCurve, Stream output)
        {
            if (!NamedCurve.RefersToASpecificNamedCurve(namedCurve))
            {
                /*
                 * RFC 4492 5.4. All those values of NamedCurve are allowed that refer to a specific
                 * curve. Values of NamedCurve that indicate support for a class of explicitly defined
                 * curves are not allowed here [...].
                 */
                throw new TlsFatalAlert(AlertDescription.internal_error);
            }

            TlsUtilities.WriteUint8(ECCurveType.named_curve, output);
            TlsUtilities.CheckUint16(namedCurve);
            TlsUtilities.WriteUint16(namedCurve, output);
        }
示例#25
0
        protected internal static void WriteSupplementalData(Stream output, IList supplementalData)
        {
            MemoryStream buf = new MemoryStream();

            foreach (SupplementalDataEntry entry in supplementalData)
            {
                int supp_data_type = entry.DataType;
                TlsUtilities.CheckUint16(supp_data_type);
                TlsUtilities.WriteUint16(supp_data_type, buf);
                TlsUtilities.WriteOpaque16(entry.Data, buf);
            }

            byte[] supp_data = buf.ToArray();

            TlsUtilities.WriteOpaque24(supp_data, output);
        }
示例#26
0
        protected internal static void WriteExtensions(Stream output, IDictionary extensions)
        {
            MemoryStream buf = new MemoryStream();

            foreach (int extension_type in extensions.Keys)
            {
                byte[] extension_data = (byte[])extensions[extension_type];

                TlsUtilities.CheckUint16(extension_type);
                TlsUtilities.WriteUint16(extension_type, buf);
                TlsUtilities.WriteOpaque16(extension_data, buf);
            }

            byte[] extBytes = buf.ToArray();

            TlsUtilities.WriteOpaque16(extBytes, output);
        }
示例#27
0
        public static void WriteExplicitECParameters(byte[] ecPointFormats, ECDomainParameters ecParameters, Stream output)
        {
            //IL_00b2: Unknown result type (might be due to invalid IL or missing references)
            //IL_00bd: Unknown result type (might be due to invalid IL or missing references)
            ECCurve curve = ecParameters.Curve;

            if (ECAlgorithms.IsFpCurve(curve))
            {
                TlsUtilities.WriteUint8(1, output);
                WriteECParameter(curve.Field.Characteristic, output);
            }
            else
            {
                if (!ECAlgorithms.IsF2mCurve(curve))
                {
                    throw new ArgumentException("'ecParameters' not a known curve type");
                }
                IPolynomialExtensionField polynomialExtensionField = (IPolynomialExtensionField)curve.Field;
                int[] exponentsPresent = polynomialExtensionField.MinimalPolynomial.GetExponentsPresent();
                TlsUtilities.WriteUint8(2, output);
                int i = exponentsPresent[exponentsPresent.Length - 1];
                TlsUtilities.CheckUint16(i);
                TlsUtilities.WriteUint16(i, output);
                if (exponentsPresent.Length == 3)
                {
                    TlsUtilities.WriteUint8(1, output);
                    WriteECExponent(exponentsPresent[1], output);
                }
                else
                {
                    if (exponentsPresent.Length != 5)
                    {
                        throw new ArgumentException("Only trinomial and pentomial curves are supported");
                    }
                    TlsUtilities.WriteUint8(2, output);
                    WriteECExponent(exponentsPresent[1], output);
                    WriteECExponent(exponentsPresent[2], output);
                    WriteECExponent(exponentsPresent[3], output);
                }
            }
            WriteECFieldElement(curve.A, output);
            WriteECFieldElement(curve.B, output);
            TlsUtilities.WriteOpaque8(SerializeECPoint(ecPointFormats, ecParameters.G), output);
            WriteECParameter(ecParameters.N, output);
            WriteECParameter(ecParameters.H, output);
        }
示例#28
0
        /**
         * Encode this {@link CertificateRequest} to a {@link Stream}.
         *
         * @param output the {@link Stream} to encode to.
         * @throws IOException
         */
        public virtual void Encode(Stream output)
        {
            if (mCertificateTypes == null || mCertificateTypes.Length == 0)
            {
                TlsUtilities.WriteUint8(0, output);
            }
            else
            {
                TlsUtilities.WriteUint8ArrayWithUint8Length(mCertificateTypes, output);
            }

            if (mSupportedSignatureAlgorithms != null)
            {
                // TODO Check whether SignatureAlgorithm.anonymous is allowed here
                TlsUtilities.EncodeSupportedSignatureAlgorithms(mSupportedSignatureAlgorithms, false, output);
            }

            if (mCertificateAuthorities == null || mCertificateAuthorities.Count < 1)
            {
                TlsUtilities.WriteUint16(0, output);
            }
            else
            {
                IList derEncodings = Platform.CreateArrayList(mCertificateAuthorities.Count);

                int totalLength = 0;
                foreach (Asn1Encodable certificateAuthority in mCertificateAuthorities)
                {
                    byte[] derEncoding = certificateAuthority.GetEncoded(Asn1Encodable.Der);
                    derEncodings.Add(derEncoding);
                    totalLength += derEncoding.Length + 2;
                }

                TlsUtilities.CheckUint16(totalLength);
                TlsUtilities.WriteUint16(totalLength, output);

                foreach (byte[] derEncoding in derEncodings)
                {
                    TlsUtilities.WriteOpaque16(derEncoding, output);
                }
            }
        }
        /**
         * Encode this {@link ServerNameList} to a {@link Stream}.
         *
         * @param output
         *            the {@link Stream} to encode to.
         * @throws IOException
         */
        public virtual void Encode(Stream output)
        {
            MemoryStream buf = new MemoryStream();

            byte[] nameTypesSeen = TlsUtilities.EmptyBytes;
            foreach (ServerName entry in ServerNames)
            {
                nameTypesSeen = CheckNameType(nameTypesSeen, entry.NameType);
                if (nameTypesSeen == null)
                {
                    throw new TlsFatalAlert(AlertDescription.internal_error);
                }

                entry.Encode(buf);
            }

            TlsUtilities.CheckUint16(buf.Length);
            TlsUtilities.WriteUint16((int)buf.Length, output);
            buf.WriteTo(output);
        }
示例#30
0
        public static HeartbeatMessage Parse(Stream input)
        {
            byte b = TlsUtilities.ReadUint8(input);

            if (!HeartbeatMessageType.IsValid(b))
            {
                throw new TlsFatalAlert(47);
            }
            int           payloadLength = TlsUtilities.ReadUint16(input);
            PayloadBuffer payloadBuffer = new PayloadBuffer();

            Streams.PipeAll(input, (Stream)(object)payloadBuffer);
            byte[] array = payloadBuffer.ToTruncatedByteArray(payloadLength);
            if (array == null)
            {
                return(null);
            }
            TlsUtilities.CheckUint16(((Stream)payloadBuffer).get_Length());
            int paddingLength = (int)((Stream)payloadBuffer).get_Length() - array.Length;

            return(new HeartbeatMessage(b, array, paddingLength));
        }