Пример #1
0
def trust_id_for_repo(trust_map, fms_id, repo_hash):
    """ Accept index updates from an fms id for a repo."""
    assert is_fms_id(fms_id)
    assert is_hex_string(repo_hash)

    hashes = trust_map.get(fms_id, ())
    if repo_hash in hashes:
        return False
    hashes = list(hashes)
    hashes.append(repo_hash)
    trust_map[fms_id] = tuple(hashes)

    return True
Пример #2
0
    def validate_trust_map_entry(cls, cfg, fields):
        """ INTERNAL: Raise a ValueError for invalid trust map entries. """
        if not is_fms_id(fields[0]):
            raise ValueError("%s doesn't look like an fms id." % fields[0])
        if len(fields) < 2:
            raise ValueError("No USK hashes for fms id: %s?" % fields[0])
        for value in fields[1:]:
            if not is_hex_string(value):
                raise ValueError("%s doesn't look like a repo hash." % value)

        if fields[0] in cfg.fmsread_trust_map:
            raise ValueError(("%s appears more than once in the " +
                              "[fmsread_trust_map] section.") % fields[0])
Пример #3
0
def trust_id_for_repo(trust_map, fms_id, repo_hash):
    """ Accept index updates from an fms id for a repo."""
    assert is_fms_id(fms_id)
    assert is_hex_string(repo_hash)

    hashes = trust_map.get(fms_id, ())
    if repo_hash in hashes:
        return False
    hashes = list(hashes)
    hashes.append(repo_hash)
    trust_map[fms_id] = tuple(hashes)

    return True
Пример #4
0
    def validate_trust_map_entry(cls, cfg, fields):
        """ INTERNAL: Raise a ValueError for invalid trust map entries. """
        if not is_fms_id(fields[0]):
            raise ValueError("%s doesn't look like an fms id." %
                                     fields[0])
        if len(fields) < 2:
            raise ValueError("No USK hashes for fms id: %s?" %
                                     fields[0])
        for value in fields[1:]:
            if not is_hex_string(value):
                raise ValueError("%s doesn't look like a repo hash." %
                                         value)

        if fields[0] in cfg.fmsread_trust_map:
            raise ValueError(("%s appears more than once in the "
                              + "[fmsread_trust_map] section.") %
                             fields[0])
Пример #5
0
def parse_trust_args(params, opts):
    """ INTERNAL: Helper function to parse  --hash and --fmsid. """
    if not opts.get('hash', []):
        raise util.Abort("Use --hash to set the USK hash.")
    if len(opts['hash']) != 1:
        raise util.Abort("Only one --hash value is allowed.")
    if not is_hex_string(opts['hash'][0]):
        raise util.Abort("[%s] doesn't look like a USK hash." %
                         opts['hash'][0])

    if not opts.get('fmsid', []):
        raise util.Abort("Use --fmsid to set the FMS id.")
    if len(opts['fmsid']) != 1:
        raise util.Abort("Only one --fmsid value is allowed.")
    if not is_fms_id(opts['fmsid'][0]):
        raise util.Abort("[%s] doesn't look like an FMS id."
                         % opts['fmsid'][0])

    params['FMSREAD_HASH'] = opts['hash'][0]
    params['FMSREAD_FMSID'] = opts['fmsid'][0]
Пример #6
0
def parse_trust_args(params, opts):
    """ INTERNAL: Helper function to parse  --hash and --fmsid. """
    if opts.get('hash', []) == []:
        raise util.Abort("Use --hash to set the USK hash.")
    if len(opts['hash']) != 1:
        raise util.Abort("Only one --hash value is allowed.")
    if not is_hex_string(opts['hash'][0]):
        raise util.Abort("[%s] doesn't look like a USK hash." %
                         opts['hash'][0])

    if opts.get('fmsid', []) == []:
        raise util.Abort("Use --fmsid to set the FMS id.")
    if len(opts['fmsid']) != 1:
        raise util.Abort("Only one --fmsid value is allowed.")
    if not is_fms_id(opts['fmsid'][0]):
        raise util.Abort("[%s] doesn't look like an FMS id." %
                         opts['fmsid'][0])

    params['FMSREAD_HASH'] = opts['hash'][0]
    params['FMSREAD_FMSID'] = opts['fmsid'][0]
Пример #7
0
def untrust_id_for_repo(trust_map, fms_id, repo_hash):
    """ Stop accepting index updates from an fms id for a repo."""
    assert is_fms_id(fms_id)
    assert is_hex_string(repo_hash)

    if not fms_id in trust_map:
        return False

    hashes = list(trust_map[fms_id])
    # Paranoia. There shouldn't be duplicates.
    count = 0
    while repo_hash in hashes:
        hashes.remove(repo_hash)
        count += 1

    if len(hashes) == 0:
        del trust_map[fms_id]
        return True

    trust_map[fms_id] = tuple(hashes)
    return count > 0
Пример #8
0
def untrust_id_for_repo(trust_map, fms_id, repo_hash):
    """ Stop accepting index updates from an fms id for a repo."""
    assert is_fms_id(fms_id)
    assert is_hex_string(repo_hash)

    if not fms_id in trust_map:
        return False

    hashes = list(trust_map[fms_id])
    # Paranoia. There shouldn't be duplicates.
    count = 0
    while repo_hash in hashes:
        hashes.remove(repo_hash)
        count += 1

    if len(hashes) == 0:
        del trust_map[fms_id]
        return True

    trust_map[fms_id] = tuple(hashes)
    return count > 0