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)); } }
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); }
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)); } }
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); }
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; }
public ConditionalAceStringToken(string stringValue, ConditionalAceTokenByteCode tokenType) : this(stringValue, tokenType, false) { }
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)); }
internal ConditionalAceLiteralToken(ConditionalAceTokenByteCode byteCode) : base(byteCode) { }
public ConditionalAceToken(ConditionalAceTokenByteCode byteCode) { this.TokenByteCode = byteCode; }