protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { lock (this.ThisLock) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.KeyExchangeAlgorithm) { this.KeyExchangeAlgorithm = EnumEx <KeyExchangeAlgorithm> .Parse(ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.KeyDerivationAlgorithm) { this.KeyDerivationAlgorithm = EnumEx <KeyDerivationAlgorithm> .Parse(ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.CryptoAlgorithm) { this.CryptoAlgorithm = EnumEx <CryptoAlgorithm> .Parse(ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.HashAlgorithm) { this.HashAlgorithm = EnumEx <HashAlgorithm> .Parse(ItemUtilities.GetString(rangeStream)); } else if (id == (byte)SerializeId.SessionId) { this.SessionId = ItemUtilities.GetByteArray(rangeStream); } } } } }
protected override void ProtectedImport(Stream stream, BufferManager bufferManager, int count) { lock (this.ThisLock) { for (; ;) { byte id; { byte[] idBuffer = new byte[1]; if (stream.Read(idBuffer, 0, idBuffer.Length) != idBuffer.Length) { return; } id = idBuffer[0]; } int length; { byte[] lengthBuffer = new byte[4]; if (stream.Read(lengthBuffer, 0, lengthBuffer.Length) != lengthBuffer.Length) { return; } length = NetworkConverter.ToInt32(lengthBuffer); } using (RangeStream rangeStream = new RangeStream(stream, stream.Position, length, true)) { if (id == (byte)SerializeId.CreationTime) { this.CreationTime = DateTime.ParseExact(ItemUtilities.GetString(rangeStream), "yyyy-MM-ddTHH:mm:ssZ", System.Globalization.DateTimeFormatInfo.InvariantInfo).ToUniversalTime(); } if (id == (byte)SerializeId.ExchangeKey) { this.ExchangeKey = ItemUtilities.GetByteArray(rangeStream); } if (id == (byte)SerializeId.ProtocolHash) { this.ProtocolHash = ItemUtilities.GetByteArray(rangeStream); } else if (id == (byte)SerializeId.Certificate) { this.Certificate = Certificate.Import(rangeStream, bufferManager); } } } } }