Last active
December 15, 2016 02:26
-
-
Save zhehaowang/f72219d3c17f2752061964e992fca475 to your computer and use it in GitHub Desktop.
NDN regex matching in ndn-dot-net
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copy ndn-dot-net.dll to this folder and do "mcs /r:ndn-dot-net.dll test-ndn-regex.cs" | |
namespace net.named_data.jndn.security.policy { | |
using ILOG.J2CsMapping.Text; | |
using System; | |
using System.Collections; | |
using System.ComponentModel; | |
using System.IO; | |
using System.Runtime.CompilerServices; | |
using System.Text; | |
using net.named_data.jndn; | |
using net.named_data.jndn.encoding; | |
using net.named_data.jndn.encoding.der; | |
using net.named_data.jndn.security; | |
using net.named_data.jndn.security.certificate; | |
using net.named_data.jndn.util; | |
class MyTest { | |
static void Main() { | |
String identityRegex = "^([^<KEY>]*)<KEY>(<>*)<ksk-.+><ID-CERT>"; | |
Name signatureName = new Name("/home/gateway/KEY/ksk-1473888812/ID-CERT"); | |
Matcher identityMatch = net.named_data.jndn.util.NdnRegexMatcher.match(identityRegex, | |
signatureName); | |
if (identityMatch != null) { | |
Console.Out.WriteLine("match!"); | |
} else { | |
Console.Out.WriteLine("The hierarchical identityRegex \"" | |
+ identityRegex + "\" does not match signatureName \"" | |
+ signatureName.toUri() + "\""); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python comparison test | |
import os | |
import re | |
import logging | |
from base64 import b64decode | |
from pyndn.name import Name | |
from pyndn.data import Data | |
from pyndn.interest import Interest | |
from pyndn.key_locator import KeyLocator | |
from pyndn.security.policy.policy_manager import PolicyManager | |
from pyndn.security.policy.certificate_cache import CertificateCache | |
from pyndn.security.policy.validation_request import ValidationRequest | |
from pyndn.security.certificate.identity_certificate import IdentityCertificate | |
from pyndn.util.blob import Blob | |
from pyndn.util.common import Common | |
from pyndn.encoding.wire_format import WireFormat | |
from pyndn.key_locator import KeyLocatorType | |
from pyndn.security.security_exception import SecurityException | |
from pyndn.util.boost_info_parser import BoostInfoParser | |
from pyndn.util.ndn_regex import NdnRegexMatcher | |
signatureName = Name("/home/gateway/KEY/ksk-1473888812/ID-CERT") | |
identityRegex = '^([^<KEY>]*)<KEY>(<>*)<ksk-.+><ID-CERT>' | |
identityMatch = NdnRegexMatcher.match(identityRegex, signatureName) | |
if identityMatch is not None: | |
print "match" | |
else: | |
print "The hierarchical identityRegex \"" + identityRegex + "\" does not match signatureName \"" + signatureName.toUri() + "\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment