/// <param name="bytes">2 bytes are required to be passed in.</param>
        public UsernamePasswordResponse(byte[] bytes)
        {
            Guard.Same($"{nameof(bytes)}.{nameof(bytes.Length)}", 2, bytes.Length);

            Ver    = new AuthVerField(bytes[0]);
            Status = new AuthStatusField(bytes[1]);
        }
예제 #2
0
    public UsernamePasswordRequest(byte[] bytes)
    {
        Guard.NotNullOrEmpty(nameof(bytes), bytes);
        Guard.InRangeAndNotNull($"{nameof(bytes)}.{nameof(bytes.Length)}", bytes.Length, 6, 513);

        Ver   = new AuthVerField(bytes[0]);
        ULen  = new ULenField(bytes[1]);
        UName = new UNameField(bytes[2..(2 + ULen.Value)]);
        public override void FromBytes(byte[] bytes)
        {
            Guard.NotNullOrEmpty(nameof(bytes), bytes);
            Guard.Same($"{nameof(bytes)}.{nameof(bytes.Length)}", 2, bytes.Length);

            Ver = new AuthVerField(bytes[0]);

            Status = new AuthStatusField(bytes[1]);
        }
예제 #4
0
        public override void FromBytes(byte[] bytes)
        {
            Guard.NotNullOrEmpty(nameof(bytes), bytes);
            Guard.InRangeAndNotNull($"{nameof(bytes)}.{nameof(bytes.Length)}", bytes.Length, 6, 513);

            Ver = new AuthVerField(bytes[0]);

            ULen = new ULenField();
            ULen.FromByte(bytes[1]);

            UName = new UNameField();
            UName.FromBytes(bytes[2..(2 + ULen.Value)]);
        public override void FromBytes(byte[] bytes)
        {
            Guard.NotNullOrEmpty(nameof(bytes), bytes);
            Guard.InRangeAndNotNull($"{nameof(bytes)}.{nameof(bytes.Length)}", bytes.Length, 6, 513);

            Ver = new AuthVerField();
            Ver.FromByte(bytes[0]);

            ULen = new ULenField();
            ULen.FromByte(bytes[1]);

            UName = new UNameField();
            UName.FromBytes(bytes.Skip(2).Take(ULen.Value).ToArray());

            PLen = new PLenField();
            PLen.FromByte(bytes[1 + ULen.Value]);
            int expectedPlenValue = bytes.Length - 3 + ULen.Value;

            if (PLen.Value != expectedPlenValue)
            {
                throw new FormatException($"{nameof(PLen)}.{nameof(PLen.Value)} must be {nameof(bytes)}.{nameof(bytes.Length)} - 3 + {nameof(ULen)}.{nameof(ULen.Value)} = {expectedPlenValue}. Actual: {PLen.Value}.");
            }
            Passwd.FromBytes(bytes.Skip(3 + ULen.Value).ToArray());
        }