Example #1
0
        private static Encoding GetEncodingFromByteCode(ConditionalAceTokenByteCode tokenType, bool allowAttributeType)
        {
            switch (tokenType)
            {
            case ConditionalAceTokenByteCode.UnicodeString:
                return(Encoding.Unicode);

            case ConditionalAceTokenByteCode.ResourceAttribute:
            case ConditionalAceTokenByteCode.UserAttribute:
            case ConditionalAceTokenByteCode.LocalAttribute:
            case ConditionalAceTokenByteCode.DeviceAttribute:
                if (allowAttributeType)
                {
                    return(Encoding.Unicode);
                }
                else
                {
                    goto default;
                }

            case ConditionalAceTokenByteCode.OctetString:
                return(Encoding.UTF8);

            default:
                throw new Exception(string.Format("Unable to determine encoding from byte code '{0}", tokenType));
            }
        }
Example #2
0
        public ConditionalAceAttributeToken(ConditionalAceTokenByteCode attributeType, string attributeName) : base(attributeType)
        {
            switch (attributeType)
            {
            case ConditionalAceTokenByteCode.UserAttribute:
            case ConditionalAceTokenByteCode.DeviceAttribute:
            case ConditionalAceTokenByteCode.LocalAttribute:
            case ConditionalAceTokenByteCode.ResourceAttribute:
                // Do nothing
                break;

            default:
                throw new Exception(string.Format("TokenByteCode '{0}' is not an attribute type", attributeType));
            }

            // Create a unicode string token:
            this.UnicodeStringToken = new ConditionalAceStringToken(attributeName, attributeType, true);
        }
Example #3
0
        public ConditionalAceOperatorToken(ConditionalAceTokenByteCode byteCode) : base(byteCode)
        {
            switch ((ConditionalAceTokenByteCode)byteCode)
            {
            case ConditionalAceTokenByteCode.Exists:
            case ConditionalAceTokenByteCode.Member_of:
            case ConditionalAceTokenByteCode.Device_Member_of:
            case ConditionalAceTokenByteCode.Member_of_Any:
            case ConditionalAceTokenByteCode.Device_Member_of_Any:
            case ConditionalAceTokenByteCode.Not_Exists:
            case ConditionalAceTokenByteCode.Not_Member_of:
            case ConditionalAceTokenByteCode.Not_Device_Member_of:
            case ConditionalAceTokenByteCode.Not_Member_of_Any:
            case ConditionalAceTokenByteCode.Not_Device_Member_of_Any:
            case ConditionalAceTokenByteCode.Not:
                this.OperatorType = ConditionalAceOperatorTokenType.Unary;
                break;

            case ConditionalAceTokenByteCode.Equals:
            case ConditionalAceTokenByteCode.NotEquals:
            case ConditionalAceTokenByteCode.LessThan:
            case ConditionalAceTokenByteCode.LessThanOrEqualTo:
            case ConditionalAceTokenByteCode.GreaterThan:
            case ConditionalAceTokenByteCode.GreaterThanOrEqualTo:
            case ConditionalAceTokenByteCode.Contains:
            case ConditionalAceTokenByteCode.AnyOf:
            case ConditionalAceTokenByteCode.NotContains:
            case ConditionalAceTokenByteCode.NotAnyOf:
            case ConditionalAceTokenByteCode.And:
            case ConditionalAceTokenByteCode.Or:
                this.OperatorType = ConditionalAceOperatorTokenType.Binary;
                break;

            default:
                //throw new Exception(string.Format("Unknown operator byte code: 0x{0:x2}", byteCode));
                throw new Exception(string.Format("Invalid operator byte code: {0}", byteCode));
            }
        }
Example #4
0
        public static ConditionalAceStringToken FromBytes(byte[] binaryForm, int offset, ConditionalAceTokenByteCode tokenType)
        {
            int length = BitConverter.ToInt32(binaryForm, offset);

            if (length >= (binaryForm.Length - offset))
            {
                throw new Exception("Unable to create ConditionalAceStringToken from byte array; length is too long");
            }

            var stringToken = new ConditionalAceStringToken(string.Empty, tokenType);

            stringToken.StringValue = stringToken.Encoding.GetString(binaryForm, offset + 4, length);

            return(stringToken);
        }
Example #5
0
 internal ConditionalAceStringToken(string stringValue, ConditionalAceTokenByteCode tokenType, bool allowAttributeType) : base(tokenType)
 {
     // Hidden constructor that allows token types other than Unicode and Octet strings
     this.Encoding    = GetEncodingFromByteCode(tokenType, allowAttributeType);
     this.StringValue = stringValue;
 }
Example #6
0
 public ConditionalAceStringToken(string stringValue, ConditionalAceTokenByteCode tokenType) : this(stringValue, tokenType, false)
 {
 }
Example #7
0
        public static ConditionalAceAttributeToken FromBytes(byte[] binaryForm, int offset, ConditionalAceTokenByteCode tokenType)
        {
            int length = BitConverter.ToInt32(binaryForm, offset);

            if (length >= (binaryForm.Length - offset))
            {
                throw new Exception("Unable to create ConditionalAceStringToken from byte array; length is too long");
            }

            string attributeName = Encoding.Unicode.GetString(binaryForm, offset + 4, length);

            return(new ConditionalAceAttributeToken(tokenType, attributeName));
        }
Example #8
0
 internal ConditionalAceLiteralToken(ConditionalAceTokenByteCode byteCode) : base(byteCode)
 {
 }
Example #9
0
 public ConditionalAceToken(ConditionalAceTokenByteCode byteCode)
 {
     this.TokenByteCode = byteCode;
 }