/// <summary> /// Create a ConfigRelationNameFilter for the given values. /// </summary> /// /// <param name="name">The relation name, which is copied.</param> /// <param name="relation">The relation type as a ConfigNameRelation.Relation enum.</param> public ConfigRelationNameFilter(Name name, ConfigNameRelation.Relation relation) { // Copy the Name. name_ = new Name(name); relation_ = relation; }
public ConfigHyperRelationChecker(String packetNameRegexString, String packetNameExpansion, String keyNameRegexString, String keyNameExpansion, ConfigNameRelation.Relation hyperRelation) { packetNameRegex_ = new NdnRegexTopMatcher(packetNameRegexString); packetNameExpansion_ = packetNameExpansion; keyNameRegex_ = new NdnRegexTopMatcher(keyNameRegexString); keyNameExpansion_ = keyNameExpansion; hyperRelation_ = hyperRelation; }
/// <summary> /// Get a string representation of the Relation enum. /// </summary> /// /// <param name="relation">The value for the ConfigNameRelation.Relation enum.</param> /// <returns>The string representation.</returns> public static String toString(ConfigNameRelation.Relation relation) { if (relation == net.named_data.jndn.security.v2.validator_config.ConfigNameRelation.Relation.EQUAL) { return("equal"); } else if (relation == net.named_data.jndn.security.v2.validator_config.ConfigNameRelation.Relation.IS_PREFIX_OF) { return("is-prefix-of"); } else if (relation == net.named_data.jndn.security.v2.validator_config.ConfigNameRelation.Relation.IS_STRICT_PREFIX_OF) { return("is-strict-prefix-of"); } else { // We don't expect this to happen. return(""); } }
/// <summary> /// Check whether name1 and name2 satisfy the relation. /// </summary> /// /// <param name="relation">The value for the ConfigNameRelation.Relation enum.</param> /// <param name="name1">The first name to check.</param> /// <param name="name2">The second name to check.</param> /// <returns>True if the names satisfy the relation.</returns> public static bool checkNameRelation(ConfigNameRelation.Relation relation, Name name1, Name name2) { if (relation == net.named_data.jndn.security.v2.validator_config.ConfigNameRelation.Relation.EQUAL) { return(name1.equals(name2)); } else if (relation == net.named_data.jndn.security.v2.validator_config.ConfigNameRelation.Relation.IS_PREFIX_OF) { return(name1.isPrefixOf(name2)); } else if (relation == net.named_data.jndn.security.v2.validator_config.ConfigNameRelation.Relation.IS_STRICT_PREFIX_OF) { return(name1.isPrefixOf(name2) && name1.size() < name2.size()); } else { // We don't expect this to happen. return(false); } }
/// <summary> /// This is a helper for create() to create a filter from the configuration /// section which is type "name". /// </summary> /// /// <param name="configSection">The section containing the definition of the filter.</param> /// <returns>A new filter created from the configuration section.</returns> private static ConfigFilter createNameFilter(BoostInfoTree configSection) { String nameUri = configSection.getFirstValue("name"); if (nameUri != null) { // Get the filter.name. Name name = new Name(nameUri); // Get the filter.relation. String relationValue = configSection.getFirstValue("relation"); if (relationValue == null) { throw new ValidatorConfigError("Expected <filter.relation>"); } ConfigNameRelation.Relation relation = net.named_data.jndn.security.v2.validator_config.ConfigNameRelation .getNameRelationFromString(relationValue); return(new ConfigRelationNameFilter(name, relation)); } String regexString = configSection.getFirstValue("regex"); if (regexString != null) { try { return(new ConfigRegexNameFilter(regexString)); } catch (Exception e) { throw new ValidatorConfigError("Wrong filter.regex: " + regexString); } } throw new ValidatorConfigError("Wrong filter(name) properties"); }
private static ConfigChecker createKeyLocatorNameChecker( BoostInfoTree configSection) { String nameUri = configSection.getFirstValue("name"); if (nameUri != null) { Name name = new Name(nameUri); String relationValue = configSection.getFirstValue("relation"); if (relationValue == null) { throw new ValidatorConfigError( "Expected <checker.key-locator.relation>"); } ConfigNameRelation.Relation relation = net.named_data.jndn.security.v2.validator_config.ConfigNameRelation .getNameRelationFromString(relationValue); return(new ConfigNameRelationChecker(name, relation)); } String regexString = configSection.getFirstValue("regex"); if (regexString != null) { try { return(new ConfigRegexChecker(regexString)); } catch (Exception e) { throw new ValidatorConfigError( "Invalid checker.key-locator.regex: " + regexString); } } ArrayList <BoostInfoTree> hyperRelationList = configSection .get("hyper-relation"); if (hyperRelationList.Count == 1) { BoostInfoTree hyperRelation = hyperRelationList[0]; // Get k-regex. String keyRegex = hyperRelation.getFirstValue("k-regex"); if (keyRegex == null) { throw new ValidatorConfigError( "Expected <checker.key-locator.hyper-relation.k-regex>"); } // Get k-expand. String keyExpansion = hyperRelation.getFirstValue("k-expand"); if (keyExpansion == null) { throw new ValidatorConfigError( "Expected <checker.key-locator.hyper-relation.k-expand"); } // Get h-relation. String hyperRelationString = hyperRelation .getFirstValue("h-relation"); if (hyperRelationString == null) { throw new ValidatorConfigError( "Expected <checker.key-locator.hyper-relation.h-relation>"); } // Get p-regex. String packetNameRegex = hyperRelation.getFirstValue("p-regex"); if (packetNameRegex == null) { throw new ValidatorConfigError( "Expected <checker.key-locator.hyper-relation.p-regex>"); } // Get p-expand. String packetNameExpansion = hyperRelation .getFirstValue("p-expand"); if (packetNameExpansion == null) { throw new ValidatorConfigError( "Expected <checker.key-locator.hyper-relation.p-expand>"); } ConfigNameRelation.Relation relation_0 = net.named_data.jndn.security.v2.validator_config.ConfigNameRelation .getNameRelationFromString(hyperRelationString); try { return(new ConfigHyperRelationChecker(packetNameRegex, packetNameExpansion, keyRegex, keyExpansion, relation_0)); } catch (Exception e_1) { throw new ValidatorConfigError( "Invalid regex for key-locator.hyper-relation"); } } throw new ValidatorConfigError("Unsupported checker.key-locator"); }
public ConfigNameRelationChecker(Name name, ConfigNameRelation.Relation relation) { name_ = name; relation_ = relation; }