示例#1
0
        public static Certificate Deserialise(Stream stream, TCertificateType certificateType)
        {
            Certificate result = new Certificate();
            int         certificateChainLength = NetworkByteOrderConverter.ToInt24(stream);

            if (certificateChainLength > 0)
            {
                result._CertificateType = certificateType;
                if (certificateType == TCertificateType.X509)
                {
                    result._CertChain = new List <byte[]>();
                    while (certificateChainLength > 0)
                    {
                        int    certificateLength = NetworkByteOrderConverter.ToInt24(stream);
                        byte[] certificate       = new byte[certificateLength];
                        stream.Read(certificate, 0, certificateLength);
                        result._CertChain.Add(certificate);
                        certificateChainLength = certificateChainLength - certificateLength - 3;
                    }
                }
                else
                {
                }
            }
            return(result);
        }
示例#2
0
        public static Certificate Deserialise(Stream stream, TCertificateType certificateType)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            var result = new Certificate();
            var certificateChainLength = NetworkByteOrderConverter.ToInt24(stream);

            if (certificateChainLength > 0)
            {
                result.CertificateType = certificateType;
                if (certificateType == TCertificateType.X509)
                {
                    result.CertChain = new List <byte[]>();
                    while (certificateChainLength > 0)
                    {
                        var certificateLength = NetworkByteOrderConverter.ToInt24(stream);
                        var certificate       = new byte[certificateLength];
                        stream.Read(certificate, 0, certificateLength);
                        result.CertChain.Add(certificate);
                        certificateChainLength = certificateChainLength - certificateLength - 3;
                    }

                    if (result.CertChain.Any())
                    {
                        result.Cert = result.CertChain[0];
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            return(result);
        }