Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Scope"/> class.
 /// </summary>
 /// <param name="data">The data.</param>
 public Scope(Sequence data)
 {
     _container      = data ?? throw new ArgumentNullException(nameof(data));
     ContextEngineId = (OctetString)data[0];
     ContextName     = (OctetString)data[1];
     Pdu             = (ISnmpPdu)data[2];
 }
Exemplo n.º 2
0
        public Packet Move()
        {
            Sequence?sequence = _sequence;

            _sequence = null;
            return(new Packet(sequence, checkHeader: false));
        }
Exemplo n.º 3
0
        public Packet(Sequence?sequence, bool checkHeader = true)
        {
            if (sequence != null)
            {
                if (sequence.IsEmpty)
                {
                    // Reserve some room for the header.
                    Span <byte> header = sequence.AllocGetSpan(HeaderLength);
                    header.Slice(0, HeaderLength).Clear();
                    sequence.AppendAlloced(HeaderLength);
                }
                else if (checkHeader)
                {
                    if (sequence.FirstSpan.Length < MinMsgLength)
                    {
                        ThrowHelper.ThrowProtocolInvalidPacketLength();
                    }

                    Span <byte> firstSpan = sequence.FirstSpan;
                    BinaryPrimitives.TryReadUInt32BigEndian(firstSpan, out uint packet_length);
                    byte padding_length = firstSpan[PaddingOffset];
                    if (sequence.Length != packet_length + 4 ||
                        padding_length > (packet_length - 1))
                    {
                        ThrowHelper.ThrowProtocolInvalidPacketLength();
                    }
                    // TODO: remove padding.
                }
            }
            _sequence = sequence;
        }
Exemplo n.º 4
0
        public void Can_be_compared_against_null()
        {
            Sequence nonNullable = Sequence.First;
            Sequence?nullable    = null;

            (nonNullable != null).Should().BeTrue();
            (nullable == null).Should().BeTrue();
        }
Exemplo n.º 5
0
        private void EnlargeUnused(int sizeHint)
        {
            if (_sequence == null)
            {
                _sequence = _sequencePool !.RentSequence();
            }

            _unused = _sequence.AllocGetSpan(sizeHint);
        }
Exemplo n.º 6
0
 private Sequence(Sequence parent, WordTree wordTree, int row, int col)
 {
     _puzzle   = parent._puzzle;
     _wordTree = wordTree;
     _parent   = parent;
     _row      = row;
     _col      = col;
     Length    = parent.Length + 1;
 }
Exemplo n.º 7
0
 public override string ToString()
 {
     if (_toString == null)
     {
         Sequence?sequence = this;
         char[]   buffer   = new char[Length];
         for (int i = Length - 1; i >= 0; i--)
         {
             char?c = _puzzle.Grid[sequence !._row, sequence._col];
Exemplo n.º 8
0
 public Sequence(Puzzle puzzle, WordTree wordTree)
 {
     _puzzle   = puzzle;
     _wordTree = wordTree;
     _parent   = null;
     _row      = -1;
     _col      = -1;
     _toString = string.Empty;
     Length    = 0;
 }
Exemplo n.º 9
0
        // Used for writing to a Sequence.
        public SequenceWriter(Sequence sequence)
        {
            if (sequence == null)
            {
                ThrowHelper.ThrowArgumentNull(nameof(sequence));
            }

            _sequencePool = null; // don't assign to not return the Sequence on Dispose.
            _sequence     = sequence;
            _unused       = default;
        }
Exemplo n.º 10
0
        public Sequence BuildSequence()
        {
            if (_sequence == null)
            {
                ThrowHelper.ThrowInvalidOperation("No data written.");
            }

            var sequence = _sequence;

            _sequence = null;
            return(sequence);
        }
Exemplo n.º 11
0
        private bool TryVisit(int row, int col, [NotNullWhen(true)] out char?letter)
        {
            Sequence?sequence = this;

            while (sequence._parent != null)
            {
                if (row == sequence._row && col == sequence._col)
                {
                    letter = null;
                    return(false);
                }
                sequence = sequence._parent;
            }
            letter = _puzzle.Grid[row, col];
            return(letter != null);
        }
Exemplo n.º 12
0
        private void Init()
        {
            _sequence = null;
            _previousAnimMilliseconds = 0d;
            _animationTimeScale       = 1f;

            _nodeAnimInfo        = NodeAnimInfo.New();
            _nodeTransformations = new Matrix4x4[_loadedResources.Nodes.Length];

            _translation = Matrix4x4.Identity;
            _orientation = Matrix4x4.Identity;
            _scaling     = Matrix4x4.Identity;
            UpdateTransformation();

            _createdInstances.Add(this);
        }
Exemplo n.º 13
0
        public void Represent(ILog log)
        {
            if (visualActionExecutor == null)
            {
                throw new ANE(nameof(visualActionExecutor));
            }
            if (!IsReady)
            {
                throw new InvalidOperationException();
            }

            currentSequence = visualActionExecutor.Execute(log);
            if (currentSequence == null)
            {
                Debug.LogWarning(Warnings.LogNotSupported(log));
            }
        }
Exemplo n.º 14
0
        protected DockDecoderBase(IEnumerable <string> strings)
        {
            Sequence?sequence = null;

            foreach (var s in strings)
            {
                if (s.StartsWith("mask"))
                {
                    sequence = new Sequence(RegexMask.Split(s)[1]);
                    _sequences.Add(sequence);
                }
                else if (s.StartsWith("mem"))
                {
                    var split = RegexMem.Split(s);
                    sequence?.Memory.Add(int.Parse(split[1]), long.Parse(split[2]));
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Creates a <see cref="TrapV1Message"/> instance with a message body.
        /// </summary>
        /// <param name="body">Message body</param>
        public TrapV1Message(Sequence body)
        {
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            if (body.Length != 3)
            {
                throw new ArgumentException("Invalid message body.", nameof(body));
            }

            Community = (OctetString)body[1];
            Version   = (VersionCode)((Integer32)body[0]).ToInt32();

            // IMPORTANT: comment this check out if you need to support
            if (Version != VersionCode.V1)
            {
                throw new ArgumentException($"TRAP v1 is not supported in this SNMP version: {Version}.", nameof(body));
            }

            _pdu = (ISnmpPdu)body[2];
            if (_pdu.TypeCode != SnmpType.TrapV1Pdu)
            {
                throw new ArgumentException("Invalid message type.", nameof(body));
            }

            var trapPdu = (TrapV1Pdu)_pdu;

            Enterprise   = trapPdu.Enterprise;
            AgentAddress = new IPAddress(trapPdu.AgentAddress.GetRaw());
            Generic      = trapPdu.Generic;
            Specific     = trapPdu.Specific;
            TimeStamp    = trapPdu.TimeStamp.ToUInt32();
            Parameters   = SecurityParameters.Create(Community);
            _container   = body;
        }
Exemplo n.º 16
0
 public void Dispose()
 {
     _sequence?.Dispose();
     _sequence = null;
 }
Exemplo n.º 17
0
        public bool TryDecodePacket(Sequence receiveBuffer, int maxLength, out Packet packet)
        {
            // Binary Packet Protocol: https://tools.ietf.org/html/rfc4253#section-6.

            /*
             *  uint32    packet_length
             *  byte      padding_length
             *  byte[n1]  payload; n1 = packet_length - padding_length - 1
             *  byte[n2]  random padding; n2 = padding_length
             *  byte[m]   mac (Message Authentication Code - MAC); m = mac_length
             */

            if (_decodedPacket == null)
            {
                _decodedPacket = _sequencePool.RentSequence();
            }

            // We can't decode past the packet, because the mac is not encrypted.
            // We need to know the packet length to know how much we can decrypt.
            while (_decodedPacket.Length < 4 && receiveBuffer.Length >= _decode.BlockSize)
            {
                _decode.Transform(receiveBuffer.AsReadOnlySequence().Slice(0, _decode.BlockSize), _decodedPacket);
                receiveBuffer.Remove(_decode.BlockSize);
            }

            var decodedReader = new SequenceReader(_decodedPacket);

            if (decodedReader.Length >= 4)
            {
                // Read the packet length.
                uint packet_length = decodedReader.ReadUInt32();
                if (packet_length > maxLength)
                {
                    ThrowHelper.ThrowProtocolPacketTooLong();
                }

                // Decode the entire packet.
                uint concatenated_length = 4 + packet_length;
                // TODO: verify contatenated_length is a multiple of the cipher block size or 8, whichever is larger.
                long remaining = concatenated_length - decodedReader.Length;
                if (remaining > 0 && receiveBuffer.Length >= remaining)
                {
                    _decode.Transform(receiveBuffer.AsReadOnlySequence().Slice(0, remaining), _decodedPacket);
                    receiveBuffer.Remove(remaining);
                    remaining = 0;
                }

                if (remaining == 0)
                {
                    if (_decodedPacket.Length != concatenated_length)
                    {
                        ThrowHelper.ThrowInvalidOperation("Complete packet expected.");
                    }

                    // TODO: verify mac
                    receiveBuffer.Remove(_mac.HashSize);

                    packet         = new Packet(_decodedPacket);
                    _decodedPacket = null;
                    return(true);
                }
            }

            packet = new Packet(null);
            return(false);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActionSequence" /> class.
 /// </summary>
 /// <param name="actions">actions.</param>
 public ActionSequence(Sequence?actions = default(Sequence?))
 {
     this.Actions = actions;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandSequence" /> class.
 /// </summary>
 /// <param name="commands">commands.</param>
 /// <param name="devices">devices.</param>
 public CommandSequence(Sequence?commands = default(Sequence?), Sequence?devices = default(Sequence?))
 {
     this.Commands = commands;
     this.Devices  = devices;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IfActionSequence" /> class.
 /// </summary>
 /// <param name="then">then.</param>
 /// <param name="_else">_else.</param>
 public IfActionSequence(Sequence?then = default(Sequence?), Sequence?_else = default(Sequence?))
 {
     this.Then = then;
     this.Else = _else;
 }