/// <summary> /// This method help to convert the property value, which is of variable bytes, to ExtendedRuleCondition structure. /// </summary> /// <param name="byteArray">The byte array to be converted.</param> /// <returns>Return the ExtendedRuleCondition structure.</returns> public static ExtendedRuleCondition PropertyValueConvertToExtendedRuleCondition(byte[] byteArray) { // The first 2 bytes of byteArray only indicates the total number of subsequent bytes, // byteArrayTobeConvert is the actual bytes used to convert to the ExtendedRuleCondition structure, // which should not include the first 2 bytes of byteArray. byte[] byteArrayTobeConvert = new byte[byteArray.Length - 2]; Array.Copy(byteArray, 2, byteArrayTobeConvert, 0, byteArray.Length - 2); // Deserialize the byte array value into the ExtendedRuleCondition structure. ExtendedRuleCondition extendedRuleCondition = new ExtendedRuleCondition(); extendedRuleCondition.Deserialize(byteArrayTobeConvert); return extendedRuleCondition; }
/// <summary> /// Generate test data for creating extended rule. /// </summary> /// <param name="rulename">The rule name.</param> /// <param name="ruleSequence">The rule sequence.</param> /// <param name="ruleState">The rule state.</param> /// <param name="provider">The rule provider.</param> /// <param name="actionType">The rule action Type.</param> /// <param name="actionData">The rule action data.</param> /// <param name="contentRestrictSubjectName">The subject name of the rule content restriction.</param> /// <param name="namedPropertyInfo">The namedPropertyInfo that needed for construct the rule data.</param> /// <returns>An array of TaggedPropertyValue of an extended rule.</returns> public static TaggedPropertyValue[] GenerateExtendedRuleTestData(string rulename, int ruleSequence, uint ruleState, string provider, ActionType actionType, IActionData actionData, string contentRestrictSubjectName, NamedPropertyInfo namedPropertyInfo) { List<TaggedPropertyValue> propList = new List<TaggedPropertyValue>(); TaggedPropertyValue pidTagRuleMessageName = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageNameTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageName, PropertyType = (ushort)PropertyType.PtypString }; pidTagRuleMessageName.PropertyTag = pidTagRuleMessageNameTag; pidTagRuleMessageName.Value = Encoding.Unicode.GetBytes(rulename + "\0"); propList.Add(pidTagRuleMessageName); TaggedPropertyValue pidTagMessageClass = new TaggedPropertyValue(); PropertyTag pidTagMessageClassTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagMessageClass, PropertyType = (ushort)PropertyType.PtypString }; pidTagMessageClass.PropertyTag = pidTagMessageClassTag; pidTagMessageClass.Value = Encoding.Unicode.GetBytes(Constants.ExtendedRuleMessageClass + "\0"); propList.Add(pidTagMessageClass); TaggedPropertyValue pidTagRuleMessageSequence = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageSequencePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageSequence, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleMessageSequence.PropertyTag = pidTagRuleMessageSequencePropertyTag; pidTagRuleMessageSequence.Value = BitConverter.GetBytes(ruleSequence); propList.Add(pidTagRuleMessageSequence); TaggedPropertyValue pidTagRuleMessageState = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageStatePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageState, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleMessageState.PropertyTag = pidTagRuleMessageStatePropertyTag; pidTagRuleMessageState.Value = BitConverter.GetBytes(ruleState); propList.Add(pidTagRuleMessageState); TaggedPropertyValue pidTagRuleMessageLevel = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageLevelPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageLevel, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleMessageLevel.PropertyTag = pidTagRuleMessageLevelPropertyTag; pidTagRuleMessageLevel.Value = BitConverter.GetBytes(Constants.ExtendedRuleMessageLevel); propList.Add(pidTagRuleMessageLevel); TaggedPropertyValue pidTagRuleMessageProvider = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageProviderPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageProvider, PropertyType = (ushort)PropertyType.PtypString }; pidTagRuleMessageProvider.PropertyTag = pidTagRuleMessageProviderPropertyTag; pidTagRuleMessageProvider.Value = Encoding.Unicode.GetBytes(provider + "\0"); propList.Add(pidTagRuleMessageProvider); ExtendedRuleActions extendedRuleActions = new ExtendedRuleActions { NamedPropertyInformation = namedPropertyInfo }; extendedRuleActions.RuleVersion = Constants.ExtendedRuleVersion; extendedRuleActions.RuleActionBuffer = GetRuleAction(actionType, CountByte.FourBytesCount, actionData, Constants.CommonActionFlavor, Constants.RuleActionFlags); TaggedPropertyValue pidTagExtendedRuleMessageActions = new TaggedPropertyValue(); PropertyTag pidTagExtendedRuleMessageActionsPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagExtendedRuleMessageActions, PropertyType = (ushort)PropertyType.PtypBinary }; pidTagExtendedRuleMessageActions.PropertyTag = pidTagExtendedRuleMessageActionsPropertyTag; pidTagExtendedRuleMessageActions.Value = Common.AddInt16LengthBeforeBinaryArray(extendedRuleActions.Serialize()); propList.Add(pidTagExtendedRuleMessageActions); TaggedPropertyValue pidTagExtendedRuleMessageCondition = new TaggedPropertyValue(); PropertyTag pidTagExtendedRuleMessageConditionPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagExtendedRuleMessageCondition, PropertyType = (ushort)PropertyType.PtypBinary }; pidTagExtendedRuleMessageCondition.PropertyTag = pidTagExtendedRuleMessageConditionPropertyTag; TaggedPropertyValue taggedProperty = new TaggedPropertyValue(); PropertyTag taggedPropertyPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagSubject, PropertyType = (ushort)PropertyType.PtypString }; taggedProperty.PropertyTag = taggedPropertyPropertyTag; taggedProperty.Value = Encoding.Unicode.GetBytes(contentRestrictSubjectName + "\0"); ContentRestriction contentRestriction = new ContentRestriction { FuzzyLevelLow = ContentRestriction.FuzzyLevelLowValue.FL_SUBSTRING, FuzzyLevelHigh = ContentRestriction.FuzzyLevelHighValue.FL_IGNORECASE, PropertyTag = taggedProperty.PropertyTag, TaggedValue = taggedProperty }; ExtendedRuleCondition extendedRuleCondition = new ExtendedRuleCondition { NamedPropertyInformation = namedPropertyInfo, RuleRestriction = contentRestriction }; pidTagExtendedRuleMessageCondition.Value = Common.AddInt16LengthBeforeBinaryArray(extendedRuleCondition.Serialize()); propList.Add(pidTagExtendedRuleMessageCondition); return propList.ToArray(); }
/// <summary> /// Verify ExtendedRuleCondition buffer. /// </summary> /// <param name="extendedRuleCondition">ExtendedRuleCondition structure to be verified.</param> private void VerifyExtendedRuleMessageCondition(ExtendedRuleCondition extendedRuleCondition) { // Get all of the Named Properties contained in this condition property value. PropertyName[] propertyNames = extendedRuleCondition.NamedPropertyInformation.NamedProperty; if (extendedRuleCondition.RuleRestriction != null) { // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R215"); // Verify MS-OXORULE requirement: MS-OXORULE_R215. // If the value of the restrictionType is less than 0x0c means the RuleRestriction is one of the restriction structure. bool isVerifyR215 = (uint)extendedRuleCondition.RuleRestriction.RestrictType < 0x0c; Site.CaptureRequirementIfIsTrue( isVerifyR215, 215, @"[In PidTagExtendedRuleMessageCondition Property] RuleRestriction (variable): The condition is expressed as a restriction, as specified in [MS-OXCDATA] section 2.12."); // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R214"); // Verify MS-OXORULE requirement: MS-OXORULE_R214. // The condition is a ContentRestriction type, so if RuleRestriction in the extendRuleCondition is a ContentRestriction type R214 can be verified. Site.CaptureRequirementIfAreEqual<Type>( typeof(ContentRestriction), extendedRuleCondition.RuleRestriction.GetType(), 214, @"[In PidTagExtendedRuleMessageCondition Property] RuleRestriction (variable): A structure containing the condition to be evaluated."); } // If the propertyNames exists, check whether the names' value contained in this structure are all in Unicode format. if (propertyNames != null) { // isContainNameValue is used to indicate whether exist nameValue in the PropertyName array. bool isContainNameValue = false; bool isVerifyR198 = true; // Check whether every name value contained in the PropertyName structure is in Unicode format. for (int i = 0; i < propertyNames.Length; i++) { // Get the name value contained in the action buffer. // Name is a string value. byte[] nameValue = propertyNames[i].Name; if (nameValue != null) { isContainNameValue = true; // If the nameValue cannot be converted to a Unicode string, it means the name value is not in Unicode format. if (Encoding.Unicode.GetString(nameValue) == null) { isVerifyR198 = false; break; } } } if (isContainNameValue) { // Add the debug information. Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R198"); // Verify MS-OXORULE requirement: MS-OXORULE_R198. Site.CaptureRequirementIfIsTrue( isVerifyR198, 198, @"[In PidTagExtendedRuleMessageCondition Property] All string values contained in any part of this condition property value MUST be in Unicode format."); } } this.VerifyNamedPropertyInformation(extendedRuleCondition.NamedPropertyInformation); // Add the debug information. // The format of the PidTagExtendedRuleMessageCondition property: NamedPropertyInformation, RuleRestriction has been verified by above capture code, so R200 can be verified directly. Site.Log.Add(LogEntryKind.Debug, "Verify MS-OXORULE_R200"); // Verify MS-OXORULE requirement: MS-OXORULE_R200. Site.CaptureRequirement( 200, @"[In PidTagExtendedRuleMessageCondition Property] The format of the PidTagExtendedRuleMessageCondition property is as follows: NamedPropertyInformation, RuleRestriction."); }