Пример #1
0
def remove_key(keyid):
    """ 
  <Purpose>
    Remove the key belonging to 'keyid'.

  <Arguments>
    keyid:
      An object conformant to 'tuf.formats.KEYID_SCHEMA'.  It is used as an
      identifier for keys.

  <Exceptions>
    tuf.FormatError, if 'keyid' does not have the correct format.

    tuf.UnknownKeyError, if 'keyid' is not found in key database.

  <Side Effects>
    The key, identified by 'keyid', is deleted from the key database.

  <Returns>
    None.

  """

    # Does 'keyid' have the correct format?
    # This check will ensure 'keyid' has the appropriate number of objects
    # and object types, and that all dict keys are properly named.
    # Raise 'tuf.FormatError' is the match fails.
    tuf.formats.KEYID_SCHEMA.check_match(keyid)

    # Remove the key belonging to 'keyid' if found in the key database.
    if keyid in _keydb_dict:
        del _keydb_dict[keyid]
    else:
        raise tuf.UnknownKeyError('Key: ' + keyid)
Пример #2
0
def get_key(keyid):
    """ 
  <Purpose>
    Return the key belonging to 'keyid'.

  <Arguments>
    keyid:
      An object conformant to 'tuf.formats.KEYID_SCHEMA'.  It is used as an
      identifier for keys.

  <Exceptions>
    tuf.FormatError, if 'keyid' does not have the correct format.

    tuf.UnknownKeyError, if 'keyid' is not found in the keydb database.

  <Side Effects>
    None.

  <Returns>
    The key matching 'keyid'.  In the case of RSA keys, a dictionary conformant
    to 'tuf.formats.RSAKEY_SCHEMA' is returned.

  """

    # Does 'keyid' have the correct format?
    # This check will ensure 'keyid' has the appropriate number of objects
    # and object types, and that all dict keys are properly named.
    # Raise 'tuf.FormatError' is the match fails.
    tuf.formats.KEYID_SCHEMA.check_match(keyid)

    # Return the key belonging to 'keyid', if found in the key database.
    try:
        return _keydb_dict[keyid]
    except KeyError:
        raise tuf.UnknownKeyError('Key: ' + keyid)
Пример #3
0
def remove_key(keyid, repository_name='default'):
    """
  <Purpose>
    Remove the key belonging to 'keyid'.

  <Arguments>
    keyid:
      An object conformant to 'tuf.formats.KEYID_SCHEMA'.  It is used as an
      identifier for keys.

    repository_name:
      The name of the repository to remove the key.  If not supplied, the key
      is removed from the 'default' repository.

  <Exceptions>
    tuf.FormatError, if the arguments do not have the correct format.

    tuf.UnknownKeyError, if 'keyid' is not found in key database.

    tuf.InvalidNameError, if 'repository_name' does not exist in the key
    database.

  <Side Effects>
    The key, identified by 'keyid', is deleted from the key database.

  <Returns>
    None.
  """

    I_TO_PRINT = TO_PRINT + uptane.YELLOW + '[remove_key(keyid, repository_name)]: ' + uptane.ENDCOLORS

    #TODO: Print to be deleted
    print(
        str('%s %s %s %s %s' % (I_TO_PRINT, 'Removing key from keyDB: ', keyid,
                                'repository_name:', repository_name)))
    #TODO: Until here

    # Does 'keyid' have the correct format?
    # This check will ensure 'keyid' has the appropriate number of objects
    # and object types, and that all dict keys are properly named.
    # Raise 'tuf.FormatError' is the match fails.
    tuf.formats.KEYID_SCHEMA.check_match(keyid)

    # Does 'repository_name' have the correct format?
    tuf.formats.NAME_SCHEMA.check_match(repository_name)

    if repository_name not in _keydb_dict:
        raise tuf.InvalidNameError('Repository name does not exist:'
                                   ' ' + repr(repository_name))

    # Remove the key belonging to 'keyid' if found in the key database.
    if keyid in _keydb_dict[repository_name]:
        del _keydb_dict[repository_name][keyid]

    else:
        raise tuf.UnknownKeyError('Key: ' + keyid)

    #TODO: Print to be deleted
    print(str('%s %s ' % (I_TO_PRINT, 'Returning ...')))
Пример #4
0
def get_key(keyid, repository_name='default'):
    """ 
  <Purpose>
    Return the key belonging to 'keyid'.

  <Arguments>
    keyid:
      An object conformant to 'tuf.formats.KEYID_SCHEMA'.  It is used as an
      identifier for keys.

    repository_name:
      The name of the repository to get the key.  If not supplied, the key is
      retrieved from the 'default' repository.

  <Exceptions>
    tuf.FormatError, if the arguments do not have the correct format.

    tuf.UnknownKeyError, if 'keyid' is not found in the keydb database.

    tuf.InvalidNameError, if 'repository_name' does not exist in the key
    database.

  <Side Effects>
    None.

  <Returns>
    The key matching 'keyid'.  In the case of RSA keys, a dictionary conformant
    to 'tuf.formats.RSAKEY_SCHEMA' is returned.
  """

    # Does 'keyid' have the correct format?
    # This check will ensure 'keyid' has the appropriate number of objects
    # and object types, and that all dict keys are properly named.
    # Raise 'tuf.FormatError' is the match fails.
    tuf.formats.KEYID_SCHEMA.check_match(keyid)

    # Does 'repository_name' have the correct format?
    tuf.formats.NAME_SCHEMA.check_match(repository_name)

    if repository_name not in _keydb_dict:
        raise tuf.InvalidNameError('Repository name does not exist:'
                                   ' ' + repr(repository_name))

    # Return the key belonging to 'keyid', if found in the key database.
    try:
        return copy.deepcopy(_keydb_dict[repository_name][keyid])

    except KeyError:
        raise tuf.UnknownKeyError('Key: ' + keyid)