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


Python Name.toUri方法代码示例

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


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

示例1: _initialTimeOut

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
    def _initialTimeOut(self, interest):
        """
        Initial sync interest timeout, which means there are no other publishers
        yet.
        """
        if not self._enabled:
            # Ignore callbacks after the application calls shutdown().
            return

        logging.getLogger(__name__).info("initial sync timeout")
        logging.getLogger(__name__).info("no other people")
        self._sequenceNo += 1
        if self._sequenceNo != 0:
            # Since there were no other users, we expect sequence no 0.
            raise RuntimeError(
              "ChronoSync: sequenceNo_ is not the expected value of 0 for first use.")

        tempContent = sync_state_pb2.SyncStateMsg()
        content = getattr(tempContent, "ss").add()
        content.name = self._applicationDataPrefixUri
        content.type = SyncState_UPDATE
        content.seqno.seq = self._sequenceNo
        content.seqno.session = self._sessionNo
        self._update(getattr(tempContent, "ss"))

        self._onInitialized()

        name = Name(self._applicationBroadcastPrefix)
        name.append(self._digestTree.getRoot())
        retryInterest = Interest(name)
        retryInterest.setInterestLifetimeMilliseconds(self._syncLifetime)
        self._face.expressInterest(retryInterest, self._onData, self._syncTimeout)
        logging.getLogger(__name__).info("Syncinterest expressed:")
        logging.getLogger(__name__).info("%s", name.toUri())
开发者ID:WeiqiJust,项目名称:NDN-total,代码行数:36,代码来源:chrono_sync2013.py

示例2: _onData

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
    def _onData(self, interest, data):
        """
        Process Sync Data.
        """
        if not self._enabled:
            # Ignore callbacks after the application calls shutdown().
            return

        logging.getLogger(__name__).info(
          "Sync ContentObject received in callback")
        logging.getLogger(__name__).info(
            "name: %s", data.getName().toUri())
        # TODO: Check if this works in Python 3.
        tempContent = SyncStateMsg()
#pylint: disable=E1103
        tempContent.ParseFromString(data.getContent().toBytes())
#pylint: enable=E1103
        content = getattr(tempContent, "ss")
        if self._digestTree.getRoot() == "00":
            isRecovery = True
            #processing initial sync data
            self._initialOndata(content)
        else:
            self._update(content)
            if (interest.getName().size() ==
                self._applicationBroadcastPrefix.size() + 2):
                # Assume this is a recovery interest.
                isRecovery = True
            else:
                isRecovery = False

        # Send the interests to fetch the application data.
        syncStates = []
        for i in range(len(content)):
            syncState = content[i]

            # Only report UPDATE sync states.
            if syncState.type == SyncState_UPDATE:
                if len(syncState.application_info) > 0:
                    applicationInfo = Blob(syncState.application_info, True)
                else:
                    applicationInfo = Blob()

                syncStates.append(self.SyncState(
                  syncState.name, syncState.seqno.session,
                  syncState.seqno.seq, applicationInfo))

        try:
            self._onReceivedSyncState(syncStates, isRecovery)
        except:
            logging.exception("Error in onReceivedSyncState")

        name = Name(self._applicationBroadcastPrefix)
        name.append(self._digestTree.getRoot())
        syncInterest = Interest(name)
        syncInterest.setInterestLifetimeMilliseconds(self._syncLifetime)
        self._face.expressInterest(syncInterest, self._onData, self._syncTimeout)
        logging.getLogger(__name__).info("Syncinterest expressed:")
        logging.getLogger(__name__).info("%s", name.toUri())
开发者ID:named-data,项目名称:PyNDN2,代码行数:61,代码来源:chrono_sync2013.py

示例3: _sendRecovery

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
 def _sendRecovery(self, syncDigest):
     """
     Send Recovery Interest.
     """
     logging.getLogger(__name__).info("unknown digest: ")
     name = Name(self._applicationBroadcastPrefix)
     name.append("recovery").append(syncDigest)
     interest = Interest(name)
     interest.setInterestLifetimeMilliseconds(self._syncLifetime)
     self._face.expressInterest(interest, self._onData, self._syncTimeout)
     logging.getLogger(__name__).info("Recovery Syncinterest expressed:")
     logging.getLogger(__name__).info("%s", name.toUri())
开发者ID:named-data,项目名称:PyNDN2,代码行数:14,代码来源:chrono_sync2013.py

示例4: _syncTimeout

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
    def _syncTimeout(self, interest):
        """
        Sync interest time out.  If the interest is the static one send again.
        """
        if not self._enabled:
            # Ignore callbacks after the application calls shutdown().
            return

        logging.getLogger(__name__).info("Sync Interest time out.")
        logging.getLogger(__name__).info(
          "Sync Interest name: %s", interest.getName().toUri())
        component = interest.getName().get(4).toEscapedString()
        if component == self._digestTree.getRoot():
            name = Name(interest.getName())
            retryInterest = Interest(interest.getName())
            retryInterest.setInterestLifetimeMilliseconds(self._syncLifetime)
            self._face.expressInterest(
              retryInterest, self._onData, self._syncTimeout)

            logging.getLogger(__name__).info("Syncinterest expressed:")
            logging.getLogger(__name__).info("%s", name.toUri())
开发者ID:WeiqiJust,项目名称:NDN-total,代码行数:23,代码来源:chrono_sync2013.py

示例5: PibKeyContainer

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
class PibKeyContainer(object):
    """
    Create a PibKeyContainer for an identity with identityName. This constructor
    should only be called by PibIdentityImpl.

    :param Name identityName: The name of the identity, which is copied.
    :param PibImpl pibImpl: The PIB backend implementation.
    """
    def __init__(self, identityName, pibImpl):
        # Cache of loaded PibKeyImpl objects. Name => PibKeyImpl.
        self._keys = {}

        # Copy the Name.
        self._identityName = Name(identityName)
        self._pibImpl = pibImpl

        if pibImpl == None:
            raise ValueError("The pibImpl is None")

        self._keyNames = self._pibImpl.getKeysOfIdentity(identityName)

    def size(self):
        """
        Get the number of keys in the container.

        :return: The number of keys.
        :rtype: int
        """
        return len(self._keyNames)

    def add(self, key, keyName):
        """
        Add a key with name keyName into the container. If a key with the same
        name already exists, this replaces it.

        :param key: The buffer of encoded key bytes.
        :type key: an array which implements the buffer protocol
        :param Name keyName: The name of the key, which is copied.
        :return: The PibKey object.
        :rtype: PibKey
        :raises ValueError: If the name of the key does not match the identity
          name.
        """
        if not self._identityName.equals(PibKey.extractIdentityFromKeyName(keyName)):
            raise ValueError("The key name `" + keyName.toUri() +
              "` does not match the identity name `" +
              self._identityName.toUri() + "`")

        # Copy the Name.
        self._keyNames.add(Name(keyName))
        self._keys[Name(keyName)] = PibKeyImpl(keyName, key, self._pibImpl)

        return self.get(keyName)

    def remove(self, keyName):
        """
        Remove the key with name keyName from the container, and its related
        certificates. If the key does not exist, do nothing.

        :param Name keyName: The name of the key.
        :raises ValueError: If keyName does not match the identity name.
        """
        if not self._identityName.equals(PibKey.extractIdentityFromKeyName(keyName)):
          raise ValueError("Key name `" + keyName.toUri() +
            "` does not match identity `" + self._identityName.toUri() + "`")

        try:
            self._keyNames.remove(keyName)
        except KeyError:
            # Do nothing if it doesn't exist.
            pass

        try:
            del self._keys[keyName]
        except KeyError:
            # Do nothing if it doesn't exist.
            pass

        self._pibImpl.removeKey(keyName)

    def get(self, keyName):
        """
        Get the key with name keyName from the container.

        :param Name keyName: The name of the key.
        :return: The PibKey object.
        :rtype: PibKey
        :raises ValueError: If keyName does not match the identity name.
        :raises Pib.Error: If the key does not exist.
        """
        if not self._identityName.equals(PibKey.extractIdentityFromKeyName(keyName)):
            raise ValueError("Key name `" + keyName.toUri() +
              "` does not match identity `" + self._identityName.toUri() + "`")

        try:
            pibKeyImpl = self._keys[keyName]
        except KeyError:
            pibKeyImpl = None

        if pibKeyImpl == None:
#.........这里部分代码省略.........
开发者ID:named-data,项目名称:PyNDN2,代码行数:103,代码来源:pib_key_container.py

示例6: _processSyncInterest

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
    def _processSyncInterest(self, index, syncDigest, face):
        """
        Common interest processing, using digest log to find the difference
        after syncDigest.

        :return: True if sent a data packet to satisfy the interest, otherwise
          False.
        :rtype: bool
        """
        nameList = []       # of str
        sequenceNoList = [] # of int
        sessionNoList = []  # of int
        for j in range(index + 1, len(self._digestLog)):
            temp = self._digestLog[j].getData() # array of sync_state_pb2.SyncState.
            for i in range(len(temp)):
                syncState = temp[i]
                if syncState.type != SyncState_UPDATE:
                    continue

                if self._digestTree.find(
                      syncState.name, syncState.seqno.session) != -1:
                    n = -1
                    for k in range(len(nameList)):
                        if nameList[k] == syncState.name:
                            n = k
                            break

                    if n == -1:
                        nameList.append(syncState.name)
                        sequenceNoList.append(syncState.seqno.seq)
                        sessionNoList.append(syncState.seqno.session)
                    else:
                        sequenceNoList[n] = syncState.seqno.seq
                        sessionNoList[n] = syncState.seqno.session

        tempContent = SyncStateMsg()
        for i in range(len(nameList)):
            content = getattr(tempContent, "ss").add()
            content.name = nameList[i]
            content.type = SyncState_UPDATE
            content.seqno.seq = sequenceNoList[i]
            content.seqno.session = sessionNoList[i]

        sent = False
        if len(getattr(tempContent, "ss")) != 0:
            name = Name(self._applicationBroadcastPrefix)
            name.append(syncDigest)
            # TODO: Check if this works in Python 3.
#pylint: disable=E1103
            array = tempContent.SerializeToString()
#pylint: enable=E1103
            data = Data(name)
            data.setContent(Blob(array))
            self._keyChain.sign(data, self._certificateName)

            try:
                face.putData(data)
            except Exception as ex:
                logging.getLogger(__name__).error(
                  "Error in face.putData: %s", str(ex))
                return

            sent = True
            logging.getLogger(__name__).info("Sync Data send")
            logging.getLogger(__name__).info("%s", name.toUri())

        return sent
开发者ID:named-data,项目名称:PyNDN2,代码行数:69,代码来源:chrono_sync2013.py

示例7: EncryptorV2

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
class EncryptorV2(object):
    """
    Create an EncryptorV2 with the given parameters. This uses the face to
    register to receive Interests for the prefix {ckPrefix}/CK.

    :param Name accessPrefix: The NAC prefix to fetch the Key Encryption Key
      (KEK) (e.g., /access/prefix/NAC/data/subset). This copies the Name.
    :param Name ckPrefix: The prefix under which Content Keys (CK) will be
      generated. (Each will have a unique version appended.) This copies the Name.
    :param SigningInfo ckDataSigningInfo: The SigningInfo parameters to sign the
      Content Key (CK) Data packet. This copies the SigningInfo.
    :param onError: On failure to create the CK data (failed to fetch the KEK,
      failed to encrypt with the KEK, etc.), this calls
      onError(errorCode, message) where errorCode is from EncryptError.ErrorCode
      and message is a str. The encrypt method will continue trying to retrieve
      the KEK until success (with each attempt separated by
      RETRY_DELAY_KEK_RETRIEVAL_MS) and onError may be called multiple times.
      NOTE: The library will log any exceptions thrown by this callback, but for
      better error handling the callback should catch and properly handle any
      exceptions.
    :type onError: function object
    :param Validator validator: The validation policy to ensure correctness of
      the KEK.
    :param KeyChain keyChain: The KeyChain used to sign Data packets.
    :param Face face: The Face that will be used to fetch the KEK and publish CK
      data.
    """
    def __init__(self, accessPrefix, ckPrefix, ckDataSigningInfo,
      onError, validator, keyChain, face):
        # Copy the Name.
        self._accessPrefix = Name(accessPrefix)
        self._ckPrefix = Name(ckPrefix)
        self._ckBits = bytearray(EncryptorV2.AES_KEY_SIZE)
        self._ckDataSigningInfo = SigningInfo(ckDataSigningInfo)
        self._isKekRetrievalInProgress = False
        self._onError = onError
        self._keyChain = keyChain
        self._face = face

        self._kekData = None
        # Storage for encrypted CKs.
        self._storage = InMemoryStorageRetaining()
        self._kekPendingInterestId = 0

        self.regenerateCk()

        def onInterest(prefix, interest, face, interestFilterId, filter):
            data = self._storage.find(interest)
            if data != None:
                logging.getLogger(__name__).info("Serving " +
                  data.getName().toUri() + " from InMemoryStorage")
                try:
                    face.putData(data)
                except:
                    logging.exception("Error in Face.putData")
            else:
                logging.getLogger(__name__).info(
                  "Didn't find CK data for " + interest.getName().toUri())
                # TODO: Send NACK?

        def onRegisterFailed(prefix):
            logging.getLogger(__name__).error(
              "Failed to register prefix " + prefix.toUri())

        self._ckRegisteredPrefixId = self._face.registerPrefix(
          Name(ckPrefix).append(EncryptorV2.NAME_COMPONENT_CK),
          onInterest, onRegisterFailed)

    def shutdown(self):
        self._face.unsetInterestFilter(self._ckRegisteredPrefixId)
        if self._kekPendingInterestId > 0:
            self._face.removePendingInterest(self._kekPendingInterestId)

    def encrypt(self, plainData):
        """
        Encrypt the plainData using the existing Content Key (CK) and return a
        new EncryptedContent.

        :param plainData: The data to encrypt.
        :type plainData: Blob or an array which implements the buffer protocol
        :return: The new EncryptedContent.
        :rtype: EncryptedContent
        """
        # Generate the initial vector.
        initialVector = bytearray(EncryptorV2.AES_IV_SIZE)
        for i in range(len(initialVector)):
            initialVector[i] = _systemRandom.randint(0, 0xff)

        params = EncryptParams(EncryptAlgorithmType.AesCbc)
        params.setInitialVector(Blob(initialVector, False))
        encryptedData = AesAlgorithm.encrypt(
          Blob(self._ckBits, False), Blob(plainData, False), params)

        content = EncryptedContent()
        content.setInitialVector(params.getInitialVector())
        content.setPayload(encryptedData)
        content.setKeyLocatorName(self._ckName)

        return content

#.........这里部分代码省略.........
开发者ID:named-data,项目名称:PyNDN2,代码行数:103,代码来源:encryptor_v2.py

示例8: _fetchKdk

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
    def _fetchKdk(self, contentKey, kdkPrefix, ckData, onError, nTriesLeft):
        """
        :param DecryptorV2.ContentKey contentKey:
        :param Name kdkPrefix:
        :param Data ckData:
        :param onError: On error, this calls onError(errorCode, message)
        :type onError: function object
        :param int nTriesLeft:
        """
        # <kdk-prefix>/KDK/<kdk-id>    /ENCRYPTED-BY  /<credential-identity>/KEY/<key-id>
        # \                          /                \                                /
        #  -----------  -------------                  ---------------  ---------------
        #             \/                                              \/
        #     from the CK data                                from configuration

        kdkName = Name(kdkPrefix)
        kdkName.append(EncryptorV2.NAME_COMPONENT_ENCRYPTED_BY).append(
          self._credentialsKey.getName())

        logging.getLogger(__name__).info("Fetching KDK " + kdkName.toUri())

        def onData(kdkInterest, kdkData):
            try:
                contentKey.pendingInterest = 0
                # TODO: Verify that the key is legitimate.

                isOk = self._decryptAndImportKdk(kdkData, onError)
                if not isOk:
                    return
                # This way of getting the kdkKeyName is a bit hacky.
                kdkKeyName = kdkPrefix.getPrefix(-2).append("KEY").append(
                  kdkPrefix.get(-1))
                self._decryptCkAndProcessPendingDecrypts(
                  contentKey, ckData, kdkKeyName, onError)
            except Exception as ex:
                onError(EncryptError.ErrorCode.General,
                  "Error in fetchCk onData: " + repr(ex))

        def onTimeout(interest):
            contentKey.pendingInterest = 0
            if nTriesLeft > 1:
                self._fetchKdk(
                  contentKey, kdkPrefix, ckData, onError, nTriesLeft - 1)
            else:
                onError(EncryptError.ErrorCode.KdkRetrievalTimeout,
                  "Retrieval of KDK [" + interest.getName().toUri() +
                  "] timed out")

        def onNetworkNack(interest, networkNack):
            contentKey.pendingInterest = 0
            onError(EncryptError.ErrorCode.KdkRetrievalFailure,
              "Retrieval of KDK [" + interest.getName().toUri() +
              "] failed. Got NACK (" + str(networkNack.getReason()) + ")")

        try:
            contentKey.pendingInterest = self._face.expressInterest(
              Interest(kdkName).setMustBeFresh(True).setCanBePrefix(False),
              onData, onTimeout, onNetworkNack)
        except Exception as ex:
            onError(EncryptError.ErrorCode.General,
              "expressInterest error: " + repr(ex))
开发者ID:named-data,项目名称:PyNDN2,代码行数:63,代码来源:decryptor_v2.py

示例9: _checkSignatureMatch

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
    def _checkSignatureMatch(self, signatureName, objectName, rule, failureReason):
        """
        Once a rule is found to match data or a signed interest, the name in the
        KeyLocator must satisfy the condition in the 'checker' section of the rule,
        else the data or interest is rejected.

        :param Name signatureName: The certificate name from the KeyLocator .
        :param Name objectName: The name of the data packet or interest. In the
          case of signed interests, this excludes the timestamp, nonce and signature
          components.
        :param BoostInfoTree rule: The rule from the configuration file that matches
          the data or interest.
        :param Array<str> failureReason: If verification fails, set
          failureReason[0] to the failure reason string.
        :return: True if matches.
        :rtype: bool

        """
        checker = rule['checker'][0]
        checkerType = checker['type'][0].getValue()
        if checkerType == 'fixed-signer':
            signerInfo = checker['signer'][0]
            signerType = signerInfo['type'][0].getValue()
            if signerType == 'file':
                if self._isSecurityV1:
                    cert = self._lookupCertificate(
                      signerInfo['file-name'][0].getValue(), True)
                    if cert is None:
                        failureReason[0] = (
                          "Can't find fixed-signer certificate file: " +
                          signerInfo['file-name'][0].getValue())
                        return False
                else:
                    cert = self._lookupCertificateV2(
                      signerInfo['file-name'][0].getValue(), True)
                    if cert is None:
                        failureReason[0] = (
                          "Can't find fixed-signer certificate file: " +
                          signerInfo['file-name'][0].getValue())
                        return False
            elif signerType == 'base64':
                if self._isSecurityV1:
                    cert = self._lookupCertificate(
                      signerInfo['base64-string'][0].getValue(), False)
                    if cert is None:
                        failureReason[0] = (
                          "Can't find fixed-signer certificate base64: " +
                          signerInfo['base64-string'][0].getValue())
                        return False
                else:
                    cert = self._lookupCertificateV2(
                      signerInfo['base64-string'][0].getValue(), False)
                    if cert is None:
                        failureReason[0] = (
                          "Can't find fixed-signer certificate base64: " +
                          signerInfo['base64-string'][0].getValue())
                        return False
            else:
                failureReason[0] = ("Unrecognized fixed-signer signerType: " +
                  signerType)
                return False

            if cert.getName().equals(signatureName):
                return True
            else:
                failureReason[0] = ("fixed-signer cert name \"" +
                  cert.getName().toUri() + "\" does not equal signatureName \"" +
                  signatureName.toUri() + "\"")
                return False
        elif checkerType == 'hierarchical':
            # this just means the data/interest name has the signing identity as a prefix
            # that means everything before 'ksk-?' in the key name
            identityRegex = '^([^<KEY>]*)<KEY>(<>*)<ksk-.+><ID-CERT>'
            identityMatch = NdnRegexTopMatcher(identityRegex)
            if identityMatch.match(signatureName):
                identityPrefix = identityMatch.expand("\\1").append(
                  identityMatch.expand("\\2"))
                if self._matchesRelation(objectName, identityPrefix, 'is-prefix-of'):
                    return True
                else:
                    failureReason[0] = ("The hierarchical objectName \"" +
                      objectName.toUri() + "\" is not a prefix of \"" +
                      identityPrefix.toUri() + "\"")
                    return False

            if not self._isSecurityV1:
                # Check for a security v2 key name.
                identityRegex2 = "^(<>*)<KEY><>$"
                identityMatch2 = NdnRegexTopMatcher(identityRegex2)
                if identityMatch2.match(signatureName):
                    identityPrefix = identityMatch2.expand("\\1")
                    if self._matchesRelation(objectName, identityPrefix, 'is-prefix-of'):
                        return True
                    else:
                        failureReason[0] = ("The hierarchical objectName \"" +
                          objectName.toUri() + "\" is not a prefix of \"" +
                          identityPrefix.toUri() + "\"")
                        return False

            failureReason[0] = ("The hierarchical identityRegex \"" +
#.........这里部分代码省略.........
开发者ID:named-data,项目名称:PyNDN2,代码行数:103,代码来源:config_policy_manager.py

示例10: PibIdentityImpl

# 需要导入模块: from pyndn.name import Name [as 别名]
# 或者: from pyndn.name.Name import toUri [as 别名]
class PibIdentityImpl(object):
    """
    Create a PibIdentityImpl with identityName.

    :param Name identityName: The name of the identity, which is copied.
    :param PibImpl pibImpl: The Pib backend implementation.
    :param bool needInit: If true and the identity does not exist in the pibImpl
      back end, then create it (and If no default identity has been set,
      identityName becomes the default). If false, then throw Pib.Error if the
      identity does not exist in the pibImpl back end.
    :raises Pib.Error: If the identity does not exist in the pibImpl back end
      and needInit is false.
    """
    def __init__(self, identityName, pibImpl, needInit):
        self._defaultKey = None

        # Copy the Name.
        self._identityName = Name(identityName)
        self._keys = PibKeyContainer(identityName, pibImpl)
        self._pibImpl = pibImpl

        if pibImpl == None:
            raise ValueError("The pibImpl is None")

        if needInit:
            self._pibImpl.addIdentity(self._identityName)
        else:
            if not self._pibImpl.hasIdentity(self._identityName):
                raise Pib.Error("Identity " + self._identityName.toUri() +
                  " does not exist")

    def getName(self):
        """
        Get the name of the identity.

        :return: The name of the identity. You must not change the Name object.
          If you need to change it then make a copy.
        :rtype: Name
        """
        return self._identityName

    def addKey(self, key, keyName):
        """
        Add the key. If a key with the same name already exists, overwrite the
        key. If no default key for the identity has been set, then set the added
        key as default for the identity.

        :param key: The public key bits. This copies the buffer.
        :type key: an array which implements the buffer protocol
        :param Name keyName: The name of the key. This copies the name.
        :return: The PibKey object.
        :rtype: PibKey
        """
        # BOOST_ASSERT(keys_.isConsistent())

        return self._keys.add(key, keyName)

    def removeKey(self, keyName):
        """
        Remove the key with keyName and its related certificates. If the key
        does not exist, do nothing.

        :param Name keyName: The name of the key.
        """
        # BOOST_ASSERT(keys_.isConsistent())

        if (self._defaultKey != None and
            self._defaultKey.getName().equals(keyName)):
            self._defaultKey = None

        self._keys.remove(keyName)

    def getKey(self, keyName):
        """
        Get the key with name keyName.

        :param Name keyName: The name of the key.
        :return: The PibKey object.
        :rtype: PibKey
        :raises ValueError: If keyName does not match the identity name.
        :raises Pib.Error: If the key does not exist.
        """
        # BOOST_ASSERT(keys_.isConsistent())

        return self._keys.get(keyName)

    def setDefaultKey(self, keyOrKeyName, arg2 = None):
        """
        setDefaultKey has two forms:
        setDefaultKey(keyName) - Set the key with name keyName as the default
        key of the identity.
        setDefaultKey(key, keyName) - Add a key with name keyName and set it as
        the default key of the identity.

        :param key: The buffer of encoded key bytes. (This is only used when
          calling setDefaultKey(key, keyName). )
        :type key: an array which implements the buffer protocol
        :param Name keyName: The name of the key. This copies the name.
        :return: The PibKey object of the default key.
        :rtype: PibKey
#.........这里部分代码省略.........
开发者ID:named-data,项目名称:PyNDN2,代码行数:103,代码来源:pib_identity_impl.py


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