当前位置: 首页>>代码示例>>Python>>正文


Python Data.setName方法代码示例

本文整理汇总了Python中pyndn.Data.setName方法的典型用法代码示例。如果您正苦于以下问题:Python Data.setName方法的具体用法?Python Data.setName怎么用?Python Data.setName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyndn.Data的用法示例。


在下文中一共展示了Data.setName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_hyper_relation

# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import setName [as 别名]
    def test_hyper_relation(self):
        # Set up the validator.
        fetcher = CertificateFetcherOffline()
        validator = ValidatorConfig(fetcher)
        validator.load(
          os.path.join(self._policyConfigDirectory, "hyperrelation_ruleset.conf"))

        # Set up a Data packet and result object.
        data = Data()
        KeyLocator.getFromSignature(data.getSignature()).setType(KeyLocatorType.KEYNAME)
        result = TestValidationResult(data)

        data.setName(Name("/SecurityTestSecRule/Basic/Longer/Data2"))

        KeyLocator.getFromSignature(data.getSignature()).setKeyName(
          Name("/SecurityTestSecRule/Basic/Longer/KEY/123"))
        result.checkPolicy(validator)
        self.assertTrue(result._calledFailure and not result.calledContinue_)
        KeyLocator.getFromSignature(data.getSignature()).setKeyName(
          Name("/SecurityTestSecRule/Basic/KEY/123"))
        result.checkPolicy(validator)
        self.assertTrue(result._calledFailure and not result.calledContinue_)

        data.setName(Name("/SecurityTestSecRule/Basic/Other/Data1"))

        KeyLocator.getFromSignature(data.getSignature()).setKeyName(
          Name("/SecurityTestSecRule/Basic/Longer/KEY/123"))
        result.checkPolicy(validator)
        self.assertTrue(result._calledFailure and not result.calledContinue_)
        KeyLocator.getFromSignature(data.getSignature()).setKeyName(
          Name("/SecurityTestSecRule/Basic/KEY/123"))
        result.checkPolicy(validator)
        self.assertTrue(result._calledFailure and not result.calledContinue_)
开发者ID:named-data,项目名称:PyNDN2,代码行数:35,代码来源:test_validation_policy_config.py

示例2: setName

# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import setName [as 别名]
    def setName(self, name):
        """
        Overrides Data.setName() to ensure that the new name is a valid identity
        certificate name.
        :param name: The new name for this IdentityCertificate
        :type name: Name
        """
        if (not self._isCorrectName(name)):
            raise SecurityException("Bad format for identity certificate name!")

        Data.setName(self, name)
        self._setPublicKeyName()
开发者ID:WeiqiJust,项目名称:NDN-total,代码行数:14,代码来源:identity_certificate.py

示例3: test_get_group_key_without_regeneration

# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import setName [as 别名]
    def test_get_group_key_without_regeneration(self):
        # Create the group manager.
        manager = GroupManager(
          Name("Alice"), Name("data_type"),
          Sqlite3GroupManagerDb(self.groupKeyDatabaseFilePath), 1024, 1,
          self.keyChain)
        self.setManager(manager)

        # Get the data list from the group manager.
        timePoint1 = Schedule.fromIsoString("20150825T093000")
        result = manager.getGroupKey(timePoint1)

        self.assertEqual(4, len(result))

        # The first data packet contains the group's encryption key (public key).
        data1 = result[0]
        self.assertEqual(
          "/Alice/READ/data_type/E-KEY/20150825T090000/20150825T100000",
          data1.getName().toUri())
        groupEKey1 = EncryptKey(data1.getContent())

        # Get the second data packet and decrypt.
        data = result[1]
        self.assertEqual(
          "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/ksk-123",
          data.getName().toUri())

        # Add new members to the database.
        dataBlob = self.certificate.wireEncode()
        memberD = Data()
        memberD.wireDecode(dataBlob)
        memberD.setName(Name("/ndn/memberD/KEY/ksk-123/ID-CERT/123"))
        manager.addMember("schedule1", memberD)

        result2 = manager.getGroupKey(timePoint1, False)
        self.assertEqual(5, len(result2))

        # Check that the new EKey is the same as the previous one.
        data2 = result2[0]
        self.assertEqual(
          "/Alice/READ/data_type/E-KEY/20150825T090000/20150825T100000",
           data2.getName().toUri())
        groupEKey2 = EncryptKey(data2.getContent())
        self.assertTrue(groupEKey1.getKeyBits().equals(groupEKey2.getKeyBits()));

        # Check the second data packet.
        data2 = result2[1]
        self.assertEqual(
          "/Alice/READ/data_type/D-KEY/20150825T090000/20150825T100000/FOR/ndn/memberA/ksk-123",
          data2.getName().toUri())
开发者ID:named-data,项目名称:PyNDN2,代码行数:52,代码来源:test_group_manager.py

示例4: setManager

# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import setName [as 别名]
    def setManager(self, manager):
        # Set up the first schedule.
        schedule1 = Schedule()
        interval11 = RepetitiveInterval(
          Schedule.fromIsoString("20150825T000000"),
          Schedule.fromIsoString("20150827T000000"), 5, 10, 2,
          RepetitiveInterval.RepeatUnit.DAY)
        interval12 = RepetitiveInterval(
          Schedule.fromIsoString("20150825T000000"),
          Schedule.fromIsoString("20150827T000000"), 6, 8, 1,
          RepetitiveInterval.RepeatUnit.DAY)
        interval13 = RepetitiveInterval(
          Schedule.fromIsoString("20150827T000000"),
          Schedule.fromIsoString("20150827T000000"), 7, 8)
        schedule1.addWhiteInterval(interval11)
        schedule1.addWhiteInterval(interval12)
        schedule1.addBlackInterval(interval13)

        # Set up the second schedule.
        schedule2 = Schedule()
        interval21 = RepetitiveInterval(
          Schedule.fromIsoString("20150825T000000"),
          Schedule.fromIsoString("20150827T000000"), 9, 12, 1,
          RepetitiveInterval.RepeatUnit.DAY)
        interval22 = RepetitiveInterval(
          Schedule.fromIsoString("20150827T000000"),
          Schedule.fromIsoString("20150827T000000"), 6, 8)
        interval23 = RepetitiveInterval(
          Schedule.fromIsoString("20150827T000000"),
          Schedule.fromIsoString("20150827T000000"), 2, 4)
        schedule2.addWhiteInterval(interval21)
        schedule2.addWhiteInterval(interval22)
        schedule2.addBlackInterval(interval23)

        # Add them to the group manager database.
        manager.addSchedule("schedule1", schedule1)
        manager.addSchedule("schedule2", schedule2)

        # Make some adaptions to certificate.
        dataBlob = self.certificate.wireEncode()

        memberA = Data()
        memberA.wireDecode(dataBlob, TlvWireFormat.get())
        memberA.setName(Name("/ndn/memberA/KEY/ksk-123/ID-CERT/123"))
        memberB = Data()
        memberB.wireDecode(dataBlob, TlvWireFormat.get())
        memberB.setName(Name("/ndn/memberB/KEY/ksk-123/ID-CERT/123"))
        memberC = Data()
        memberC.wireDecode(dataBlob, TlvWireFormat.get())
        memberC.setName(Name("/ndn/memberC/KEY/ksk-123/ID-CERT/123"))

        # Add the members to the database.
        manager.addMember("schedule1", memberA)
        manager.addMember("schedule1", memberB)
        manager.addMember("schedule2", memberC)
开发者ID:named-data,项目名称:PyNDN2,代码行数:57,代码来源:test_group_manager.py

示例5: test_name_relation

# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import setName [as 别名]
    def test_name_relation(self):
        # Set up the validators.
        fetcher = CertificateFetcherOffline()
        validatorPrefix = ValidatorConfig(fetcher)
        validatorEqual = ValidatorConfig(fetcher)
        validatorStrict = ValidatorConfig(fetcher)

        validatorPrefix.load(
          os.path.join(self._policyConfigDirectory, "relation_ruleset_prefix.conf"))
        validatorEqual.load(
          os.path.join(self._policyConfigDirectory, "relation_ruleset_equal.conf"))
        validatorStrict.load(
          os.path.join(self._policyConfigDirectory, "relation_ruleset_strict.conf"))

        # Set up a Data packet and result object.
        data = Data()
        KeyLocator.getFromSignature(data.getSignature()).setType(
          KeyLocatorType.KEYNAME)
        KeyLocator.getFromSignature(data.getSignature()).setKeyName(
          Name("/SecurityTestSecRule/KEY/123"))
        result = TestValidationResult(data)

        data.setName(Name("/TestRule1"))
        result.checkPolicy(validatorPrefix)
        self.assertTrue(result.calledContinue_ and not result._calledFailure,
          "Prefix relation should match prefix name")
        result.checkPolicy(validatorEqual)
        self.assertTrue(result.calledContinue_ and not result._calledFailure,
          "Equal relation should match prefix name")
        result.checkPolicy(validatorStrict)
        self.assertTrue(result._calledFailure and not result.calledContinue_,
          "Strict-prefix relation should not match prefix name")

        data.setName(Name("/TestRule1/hi"))
        result.checkPolicy(validatorPrefix)
        self.assertTrue(result.calledContinue_ and not result._calledFailure,
          "Prefix relation should match longer name")
        result.checkPolicy(validatorEqual)
        self.assertTrue(result._calledFailure and not result.calledContinue_,
          "Equal relation should not match longer name")
        result.checkPolicy(validatorStrict)
        self.assertTrue(result.calledContinue_ and not result._calledFailure,
          "Strict-prefix relation should match longer name")

        data.setName(Name("/Bad/TestRule1/"))
        result.checkPolicy(validatorPrefix)
        self.assertTrue(result._calledFailure and not result.calledContinue_,
          "Prefix relation should not match inner components")
        result.checkPolicy(validatorEqual)
        self.assertTrue(result._calledFailure and not result.calledContinue_,
          "Equal relation should not match inner components")
        result.checkPolicy(validatorStrict)
        self.assertTrue(result._calledFailure and not result.calledContinue_,
          "Strict-prefix relation should  not match inner components")
开发者ID:named-data,项目名称:PyNDN2,代码行数:56,代码来源:test_validation_policy_config.py

示例6: RepoSocketPublisher

# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import setName [as 别名]
from pyndn import Data
from pyndn.security import KeyChain

import sys

from RepoSocketPublisher import RepoSocketPublisher

publisher = RepoSocketPublisher(12345)

keyChain = KeyChain()

max_packets = 50000

total_size = 0

n = Name("/test").append(str(0))
d = Data(n)
d.setContent("this is a test.")
d.getMetaInfo().setFreshnessPeriod(4000)
keyChain.sign(d, keyChain.getDefaultCertificateName())

for i in range(0, max_packets + 1):
    n = Name("/test").append(str(i))
    d.setName(n)
    if i % 100000 == 0:
        print str(i)
    if i == max_packets:
        print str(total_size)
    total_size = total_size + d.wireEncode().size()
    publisher.put(d)
开发者ID:WeiqiJust,项目名称:NDN-total,代码行数:32,代码来源:test_publisher.py


注:本文中的pyndn.Data.setName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。