本文整理汇总了Python中pyndn.Interest.wireDecode方法的典型用法代码示例。如果您正苦于以下问题:Python Interest.wireDecode方法的具体用法?Python Interest.wireDecode怎么用?Python Interest.wireDecode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyndn.Interest
的用法示例。
在下文中一共展示了Interest.wireDecode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_redecode
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
def test_redecode(self):
# check that we encode and decode correctly
encoding = self.referenceInterest.wireEncode()
reDecodedInterest = Interest()
reDecodedInterest.wireDecode(encoding)
redecodedDump = dumpInterest(reDecodedInterest)
self.assertEqual(initialDump, redecodedDump, 'Re-decoded interest does not match original')
示例2: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
def main():
# Silence the warning from Interest wire encode.
Interest.setDefaultCanBePrefix(True)
interest = Interest()
interest.wireDecode(TlvInterest)
# Use a hard-wired secret for testing. In a real application the signer
# ensures that the verifier knows the shared key and its keyName.
key = Blob(bytearray([
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
]))
if KeyChain.verifyInterestWithHmacWithSha256(interest, key):
dump("Hard-coded interest signature verification: VERIFIED")
else:
dump("Hard-coded interest signature verification: FAILED")
freshInterest = Interest(Name("/ndn/abc"))
freshInterest.setMustBeFresh(False)
keyName = Name("key1")
dump("Signing fresh interest", freshInterest.getName().toUri())
KeyChain.signWithHmacWithSha256(freshInterest, key, keyName)
if KeyChain.verifyInterestWithHmacWithSha256(freshInterest, key):
dump("Freshly-signed interest signature verification: VERIFIED")
else:
dump("Freshly-signed interest signature verification: FAILED")
示例3: TestInterestDump
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
class TestInterestDump(ut.TestCase):
def setUp(self):
self.referenceInterest = Interest()
self.referenceInterest.wireDecode(codedInterest)
def test_dump(self):
# see if the dump format is the same as we expect
decodedDump = dumpInterest(self.referenceInterest)
self.assertEqual(initialDump, decodedDump, 'Initial dump does not have expected format')
def test_redecode(self):
# check that we encode and decode correctly
encoding = self.referenceInterest.wireEncode()
reDecodedInterest = Interest()
reDecodedInterest.wireDecode(encoding)
redecodedDump = dumpInterest(reDecodedInterest)
self.assertEqual(initialDump, redecodedDump, 'Re-decoded interest does not match original')
def test_create_fresh(self):
freshInterest = createFreshInterest()
freshDump = dumpInterest(freshInterest)
self.assertTrue(interestDumpsEqual(initialDump, freshDump), 'Fresh interest does not match original')
reDecodedFreshInterest = Interest()
reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
reDecodedFreshDump = dumpInterest(reDecodedFreshInterest)
self.assertTrue(interestDumpsEqual(freshDump, reDecodedFreshDump), 'Redecoded fresh interest does not match original')
示例4: test_create_fresh
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
def test_create_fresh(self):
freshInterest = createFreshInterest()
freshDump = dumpInterest(freshInterest)
self.assertTrue(interestDumpsEqual(initialDump, freshDump), 'Fresh interest does not match original')
reDecodedFreshInterest = Interest()
reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
reDecodedFreshDump = dumpInterest(reDecodedFreshInterest)
self.assertTrue(interestDumpsEqual(freshDump, reDecodedFreshDump), 'Redecoded fresh interest does not match original')
示例5: test_redecode_implicit_digest_exclude
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
def test_redecode_implicit_digest_exclude(self):
# Check that we encode and decode correctly with an implicit digest exclude.
interest = Interest(Name("/A"))
interest.getExclude().appendComponent(Name("/sha256digest=" +
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").get(0))
dump = dumpInterest(interest)
encoding = interest.wireEncode()
reDecodedInterest = Interest()
reDecodedInterest.wireDecode(encoding)
redecodedDump = dumpInterest(reDecodedInterest)
self.assertTrue(interestDumpsEqual(dump, redecodedDump),
"Re-decoded interest does not match original")
示例6: TestInterestDump
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
class TestInterestDump(ut.TestCase):
def setUp(self):
self.referenceInterest = Interest()
self.referenceInterest.wireDecode(codedInterest)
def test_dump(self):
# see if the dump format is the same as we expect
decodedDump = dumpInterest(self.referenceInterest)
self.assertEqual(initialDump, decodedDump, 'Initial dump does not have expected format')
def test_redecode(self):
# check that we encode and decode correctly
encoding = self.referenceInterest.wireEncode()
reDecodedInterest = Interest()
reDecodedInterest.wireDecode(encoding)
redecodedDump = dumpInterest(reDecodedInterest)
self.assertEqual(initialDump, redecodedDump, 'Re-decoded interest does not match original')
def test_redecode_implicit_digest_exclude(self):
# Check that we encode and decode correctly with an implicit digest exclude.
interest = Interest(Name("/A"))
interest.getExclude().appendComponent(Name("/sha256digest=" +
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").get(0))
dump = dumpInterest(interest)
encoding = interest.wireEncode()
reDecodedInterest = Interest()
reDecodedInterest.wireDecode(encoding)
redecodedDump = dumpInterest(reDecodedInterest)
self.assertTrue(interestDumpsEqual(dump, redecodedDump),
"Re-decoded interest does not match original")
def test_create_fresh(self):
freshInterest = createFreshInterest()
freshDump = dumpInterest(freshInterest)
self.assertTrue(interestDumpsEqual(initialDump, freshDump), 'Fresh interest does not match original')
reDecodedFreshInterest = Interest()
reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
reDecodedFreshDump = dumpInterest(reDecodedFreshInterest)
self.assertTrue(interestDumpsEqual(freshDump, reDecodedFreshDump), 'Redecoded fresh interest does not match original')
示例7: TestInterestMethods
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
class TestInterestMethods(ut.TestCase):
def setUp(self):
self.referenceInterest = Interest()
self.referenceInterest.wireDecode(codedInterest)
def test_copy_constructor(self):
interest = Interest(self.referenceInterest)
self.assertTrue(interestDumpsEqual(dumpInterest(interest), dumpInterest(self.referenceInterest)), 'Interest constructed as deep copy does not match original')
def test_empty_nonce(self):
# make sure a freshly created interest has no nonce
freshInterest = createFreshInterest()
self.assertTrue(freshInterest.getNonce().isNull(), 'Freshly created interest should not have a nonce')
def test_set_removes_nonce(self):
# ensure that setting a value on an interest clears the nonce
self.assertFalse(self.referenceInterest.getNonce().isNull())
interest = Interest(self.referenceInterest)
interest.setChildSelector(0)
self.assertTrue(interest.getNonce().isNull(), 'Interest should not have a nonce after changing fields')
示例8: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
def main():
interest = Interest()
interest.wireDecode(TlvInterest)
dump("Interest:")
dumpInterest(interest)
encoding = interest.wireEncode()
dump("")
dump("Re-encoded interest", encoding.toHex())
reDecodedInterest = Interest()
reDecodedInterest.wireDecode(encoding)
dump("Re-decoded Interest:")
dumpInterest(reDecodedInterest)
freshInterest = Interest(Name("/ndn/abc"))
freshInterest.setMustBeFresh(False)
dump(freshInterest.toUri())
freshInterest.setMinSuffixComponents(4)
freshInterest.setMaxSuffixComponents(6)
freshInterest.getKeyLocator().setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
freshInterest.getKeyLocator().setKeyData(bytearray(
[0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]))
freshInterest.getExclude().appendComponent(Name("abc")[0]).appendAny()
freshInterest.setInterestLifetimeMilliseconds(30000)
freshInterest.setChildSelector(1)
freshInterest.setMustBeFresh(True);
freshInterest.setScope(2)
reDecodedFreshInterest = Interest()
reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
dump("")
dump("Re-decoded fresh Interest:")
dumpInterest(reDecodedFreshInterest)
示例9: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
def main():
interest = Interest()
interest.wireDecode(TlvInterest)
dump("Interest:")
dumpInterest(interest)
# Set the name again to clear the cached encoding so we encode again.
interest.setName(interest.getName())
encoding = interest.wireEncode()
dump("")
dump("Re-encoded interest", encoding.toHex())
reDecodedInterest = Interest()
reDecodedInterest.wireDecode(encoding)
dump("Re-decoded Interest:")
dumpInterest(reDecodedInterest)
freshInterest = Interest(Name("/ndn/abc"))
freshInterest.setMustBeFresh(False)
dump(freshInterest.toUri())
freshInterest.setMinSuffixComponents(4)
freshInterest.setMaxSuffixComponents(6)
freshInterest.getKeyLocator().setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
freshInterest.getKeyLocator().setKeyData(bytearray(
[0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]))
freshInterest.getExclude().appendComponent(Name("abc")[0]).appendAny()
freshInterest.setInterestLifetimeMilliseconds(30000)
freshInterest.setChildSelector(1)
freshInterest.setMustBeFresh(True);
freshInterest.setScope(2)
identityStorage = MemoryIdentityStorage()
privateKeyStorage = MemoryPrivateKeyStorage()
keyChain = KeyChain(IdentityManager(identityStorage, privateKeyStorage),
SelfVerifyPolicyManager(identityStorage))
# Initialize the storage.
keyName = Name("/testname/DSK-123")
certificateName = keyName.getSubName(0, keyName.size() - 1).append(
"KEY").append(keyName[-1]).append("ID-CERT").append("0")
identityStorage.addKey(keyName, KeyType.RSA, Blob(DEFAULT_RSA_PUBLIC_KEY_DER))
privateKeyStorage.setKeyPairForKeyName(
keyName, KeyType.RSA, DEFAULT_RSA_PUBLIC_KEY_DER, DEFAULT_RSA_PRIVATE_KEY_DER)
# Make a Face just so that we can sign the interest.
face = Face("localhost")
face.setCommandSigningInfo(keyChain, certificateName)
face.makeCommandInterest(freshInterest)
reDecodedFreshInterest = Interest()
reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
dump("")
dump("Re-decoded fresh Interest:")
dumpInterest(reDecodedFreshInterest)
keyChain.verifyInterest(
reDecodedFreshInterest, makeOnVerified("Freshly-signed Interest"),
makeOnVerifyFailed("Freshly-signed Interest"))
示例10: main
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
def main():
# Silence the warning from Interest wire encode.
Interest.setDefaultCanBePrefix(True)
interest = Interest()
interest.wireDecode(TlvInterest)
dump("Interest:")
dumpInterest(interest)
# Set the name again to clear the cached encoding so we encode again.
interest.setName(interest.getName())
encoding = interest.wireEncode()
dump("")
dump("Re-encoded interest", encoding.toHex())
reDecodedInterest = Interest()
reDecodedInterest.wireDecode(encoding)
dump("Re-decoded Interest:")
dumpInterest(reDecodedInterest)
freshInterest = (Interest(Name("/ndn/abc"))
.setMustBeFresh(False)
.setMinSuffixComponents(4)
.setMaxSuffixComponents(6)
.setInterestLifetimeMilliseconds(30000)
.setChildSelector(1)
.setMustBeFresh(True))
freshInterest.getKeyLocator().setType(KeyLocatorType.KEY_LOCATOR_DIGEST)
freshInterest.getKeyLocator().setKeyData(bytearray(
[0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]))
freshInterest.getExclude().appendComponent(Name("abc")[0]).appendAny()
freshInterest.getForwardingHint().add(1, Name("/A"))
dump(freshInterest.toUri())
# Set up the KeyChain.
keyChain = KeyChain("pib-memory:", "tpm-memory:")
keyChain.importSafeBag(SafeBag
(Name("/testname/KEY/123"),
Blob(DEFAULT_RSA_PRIVATE_KEY_DER, False),
Blob(DEFAULT_RSA_PUBLIC_KEY_DER, False)))
validator = Validator(ValidationPolicyFromPib(keyChain.getPib()))
# Make a Face just so that we can sign the interest.
face = Face("localhost")
face.setCommandSigningInfo(keyChain, keyChain.getDefaultCertificateName())
face.makeCommandInterest(freshInterest)
reDecodedFreshInterest = Interest()
reDecodedFreshInterest.wireDecode(freshInterest.wireEncode())
dump("")
dump("Re-decoded fresh Interest:")
dumpInterest(reDecodedFreshInterest)
validator.validate(
reDecodedFreshInterest, makeSuccessCallback("Freshly-signed Interest"),
makeFailureCallback("Freshly-signed Interest"))
示例11: TestInterestMethods
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
class TestInterestMethods(ut.TestCase):
def setUp(self):
self.referenceInterest = Interest()
self.referenceInterest.wireDecode(codedInterest)
def test_copy_constructor(self):
interest = Interest(self.referenceInterest)
self.assertTrue(interestDumpsEqual(dumpInterest(interest), dumpInterest(self.referenceInterest)), 'Interest constructed as deep copy does not match original')
def test_empty_nonce(self):
# make sure a freshly created interest has no nonce
freshInterest = createFreshInterest()
self.assertTrue(freshInterest.getNonce().isNull(), 'Freshly created interest should not have a nonce')
def test_set_removes_nonce(self):
# Ensure that changing a value on an interest clears the nonce.
self.assertFalse(self.referenceInterest.getNonce().isNull())
interest = Interest(self.referenceInterest)
# Change a child object.
interest.getExclude().clear()
self.assertTrue(interest.getNonce().isNull(), 'Interest should not have a nonce after changing fields')
def test_refresh_nonce(self):
interest = Interest(self.referenceInterest)
oldNonce = interest.getNonce()
self.assertEqual(4, oldNonce.size())
interest.refreshNonce()
self.assertEqual(oldNonce.size(), interest.getNonce().size(),
"The refreshed nonce should be the same size")
self.assertFalse(interest.getNonce().equals(oldNonce),
"The refreshed nonce should be different")
def test_exclude_matches(self):
exclude = Exclude()
exclude.appendComponent(Name("%00%02").get(0))
exclude.appendAny()
exclude.appendComponent(Name("%00%20").get(0))
component = Name("%00%01").get(0)
self.assertFalse(exclude.matches(component),
component.toEscapedString() + " should not match " + exclude.toUri())
component = Name("%00%0F").get(0)
self.assertTrue(exclude.matches(component),
component.toEscapedString() + " should match " + exclude.toUri())
component = Name("%00%21").get(0)
self.assertFalse(exclude.matches(component),
component.toEscapedString() + " should not match " + exclude.toUri())
def test_verify_digest_sha256(self):
# Create a KeyChain but we don't need to add keys.
identityStorage = MemoryIdentityStorage()
keyChain = KeyChain(
IdentityManager(identityStorage, MemoryPrivateKeyStorage()),
SelfVerifyPolicyManager(identityStorage))
interest = Interest(Name("/test/signed-interest"))
keyChain.signWithSha256(interest)
# We create 'mock' objects to replace callbacks since we're not
# interested in the effect of the callbacks themselves.
failedCallback = Mock()
verifiedCallback = Mock()
keyChain.verifyInterest(interest, verifiedCallback, failedCallback)
self.assertEqual(failedCallback.call_count, 0, 'Signature verification failed')
self.assertEqual(verifiedCallback.call_count, 1, 'Verification callback was not used.')
def test_interest_filter_matching(self):
self.assertEqual(True, InterestFilter("/a").doesMatch(Name("/a/b")))
self.assertEqual(True, InterestFilter("/a/b").doesMatch(Name("/a/b")))
self.assertEqual(False, InterestFilter("/a/b/c").doesMatch(Name("/a/b")))
self.assertEqual(True, InterestFilter("/a", "<b>").doesMatch(Name("/a/b")))
self.assertEqual(False, InterestFilter("/a/b", "<b>").doesMatch(Name("/a/b")))
self.assertEqual(False, InterestFilter("/a/b", "<c>").doesMatch(Name("/a/b/c/d")))
self.assertEqual(False, InterestFilter("/a/b", "<b>").doesMatch(Name("/a/b/c/b")))
self.assertEqual(True, InterestFilter("/a/b", "<>*<b>").doesMatch(Name("/a/b/c/b")))
self.assertEqual(False, InterestFilter("/a", "<b>").doesMatch(Name("/a/b/c/d")))
self.assertEqual(True, InterestFilter("/a", "<b><>*").doesMatch(Name("/a/b/c/d")))
self.assertEqual(True, InterestFilter("/a", "<b><>*").doesMatch(Name("/a/b")))
self.assertEqual(False, InterestFilter("/a", "<b><>+").doesMatch(Name("/a/b")))
self.assertEqual(True, InterestFilter("/a", "<b><>+").doesMatch(Name("/a/b/c")))
示例12: TestInterestMethods
# 需要导入模块: from pyndn import Interest [as 别名]
# 或者: from pyndn.Interest import wireDecode [as 别名]
class TestInterestMethods(ut.TestCase):
def setUp(self):
self.referenceInterest = Interest()
self.referenceInterest.wireDecode(codedInterest)
def test_copy_constructor(self):
interest = Interest(self.referenceInterest)
self.assertTrue(interestDumpsEqual(dumpInterest(interest), dumpInterest(self.referenceInterest)), 'Interest constructed as deep copy does not match original')
def test_empty_nonce(self):
# make sure a freshly created interest has no nonce
freshInterest = createFreshInterest()
self.assertTrue(freshInterest.getNonce().isNull(), 'Freshly created interest should not have a nonce')
def test_set_removes_nonce(self):
# Ensure that changing a value on an interest clears the nonce.
self.assertFalse(self.referenceInterest.getNonce().isNull())
interest = Interest(self.referenceInterest)
# Change a child object.
interest.getExclude().clear()
self.assertTrue(interest.getNonce().isNull(), 'Interest should not have a nonce after changing fields')
def test_refresh_nonce(self):
interest = Interest(self.referenceInterest)
oldNonce = interest.getNonce()
self.assertEqual(4, oldNonce.size())
interest.refreshNonce()
self.assertEqual(oldNonce.size(), interest.getNonce().size(),
"The refreshed nonce should be the same size")
self.assertFalse(interest.getNonce().equals(oldNonce),
"The refreshed nonce should be different")
def test_exclude_matches(self):
exclude = Exclude()
exclude.appendComponent(Name("%00%02").get(0))
exclude.appendAny()
exclude.appendComponent(Name("%00%20").get(0))
component = Name("%00%01").get(0)
self.assertFalse(exclude.matches(component),
component.toEscapedString() + " should not match " + exclude.toUri())
component = Name("%00%0F").get(0)
self.assertTrue(exclude.matches(component),
component.toEscapedString() + " should match " + exclude.toUri())
component = Name("%00%21").get(0)
self.assertFalse(exclude.matches(component),
component.toEscapedString() + " should not match " + exclude.toUri())
def test_verify_digest_sha256(self):
# Create a KeyChain but we don't need to add keys.
identityStorage = MemoryIdentityStorage()
keyChain = KeyChain(
IdentityManager(identityStorage, MemoryPrivateKeyStorage()),
SelfVerifyPolicyManager(identityStorage))
interest = Interest(Name("/test/signed-interest"))
keyChain.signWithSha256(interest)
# We create 'mock' objects to replace callbacks since we're not
# interested in the effect of the callbacks themselves.
failedCallback = Mock()
verifiedCallback = Mock()
keyChain.verifyInterest(interest, verifiedCallback, failedCallback)
self.assertEqual(failedCallback.call_count, 0, 'Signature verification failed')
self.assertEqual(verifiedCallback.call_count, 1, 'Verification callback was not used.')
def test_matches_data(self):
interest = Interest(Name("/A"))
interest.setMinSuffixComponents(2)
interest.setMaxSuffixComponents(2)
interest.getKeyLocator().setType(KeyLocatorType.KEYNAME)
interest.getKeyLocator().setKeyName(Name("/B"))
interest.getExclude().appendComponent(Name.Component("J"))
interest.getExclude().appendAny()
data = Data(Name("/A/D"))
signature = Sha256WithRsaSignature()
signature.getKeyLocator().setType(KeyLocatorType.KEYNAME)
signature.getKeyLocator().setKeyName(Name("/B"))
data.setSignature(signature)
self.assertEqual(interest.matchesData(data), True)
# Check violating MinSuffixComponents.
data1 = Data(data)
data1.setName(Name("/A"))
self.assertEqual(interest.matchesData(data1), False)
interest1 = Interest(interest)
interest1.setMinSuffixComponents(1)
self.assertEqual(interest1.matchesData(data1), True)
# Check violating MaxSuffixComponents.
data2 = Data(data)
data2.setName(Name("/A/E/F"))
self.assertEqual(interest.matchesData(data2), False)
interest2 = Interest(interest)
interest2.setMaxSuffixComponents(3)
#.........这里部分代码省略.........