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


Python Data.setSignature方法代码示例

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


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

示例1: main

# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import setSignature [as 别名]
def main():
    data = Data()
    data.wireDecode(TlvData)

    # 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.verifyDataWithHmacWithSha256(data, key):
      dump("Hard-coded data signature verification: VERIFIED")
    else:
      dump("Hard-coded data signature verification: FAILED")

    freshData = Data(Name("/ndn/abc"))
    signature = HmacWithSha256Signature()
    signature.getKeyLocator().setType(KeyLocatorType.KEYNAME)
    signature.getKeyLocator().setKeyName(Name("key1"))
    freshData.setSignature(signature)
    freshData.setContent("SUCCESS!")
    dump("Signing fresh data packet", freshData.getName().toUri())
    KeyChain.signWithHmacWithSha256(freshData, key)

    if KeyChain.verifyDataWithHmacWithSha256(freshData, key):
      dump("Freshly-signed data signature verification: VERIFIED")
    else:
      dump("Freshly-signed data signature verification: FAILED")
开发者ID:MAHIS,项目名称:PyNDN2,代码行数:31,代码来源:test_sign_verify_data_hmac.py

示例2: generateData

# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import setSignature [as 别名]
    def generateData(self, baseName):
        '''
           This appends the segment number to the data name, since repo-ng tends to expect it
        '''
        # just make up some data and return it
        ts = (time.time())
        segmentId = 0 # compatible with repo-ng test: may change to test segmented data

        versionStr = baseName.get(-1).toEscapedString()
        dataName = Name(baseName)
        dataName.appendSegment(segmentId)

        d = Data(dataName)
        content = "(" + str(ts) +  ") Data named " + dataName.toUri()
        d.setContent(content)
        d.getMetaInfo().setFinalBlockID(segmentId)
        d.getMetaInfo().setFreshnessPeriod(-1)
        if shouldSign:
            self.keychain.sign(d, self.certificateName)
        else:
            d.setSignature(self.fakeSignature)

        stats.insertDataForVersion(versionStr, {'publish_time':time.time()})
        logger.debug('Publishing: '+d.getName().toUri())
        return d
开发者ID:thecodemaiden,项目名称:nfd-timing,代码行数:27,代码来源:mcc-event-publisher.py

示例3: generateData

# 需要导入模块: from pyndn import Data [as 别名]
# 或者: from pyndn.Data import setSignature [as 别名]
def generateData(baseName):
    '''
       This appends the segment number to the data name
    '''
    # just make up some data and return it
    ts = (time.time())
    segmentId = 0 # compatible with repo-ng test: may change to test segmented data

    versionComponent = baseName.get(-1) # should have a ts
    dataName = Name(baseName)
    dataName.appendSegment(segmentId)

    d = Data(dataName)
    content = "(" + str(ts) +  ") Data named " + dataName.toUri()
    d.setContent(content)
    d.getMetaInfo().setFinalBlockID(segmentId)
    d.getMetaInfo().setFreshnessPeriod(-1)
    if shouldSign:
        keychain.sign(d, certName)
    else:
        d.setSignature(fakeSignature)

    if shouldCollectStats:
        info = getInfoForVersion(versionComponent.toEscapedString())
        if info is not None:
            info['publish_time'] = ts

    return d
开发者ID:thecodemaiden,项目名称:nfd-timing,代码行数:30,代码来源:mcc-publisher.py


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