def validate_digest_nonce(params, request, nonce_manager):
    """Validate that the digest parameters contain a fresh nonce.

    This is a helper function to check that the provided digest-auth
    credentials contain a valid, up-to-date nonce.  It calls various
    methods on the provided NonceManager object in order to query and
    update the state of the nonce database.

    Returns True if the nonce is valid, False otherwise.
    """
    nonce = params['nonce']
    if not nonce_manager.is_valid_nonce(nonce, request):
        return False
    nc_new = params.get('nc', None)
    if nc_new is not None:
        try:
            nc_new = int(nc_new[:8], 16)
        except ValueError:
            return False
    nc_old = nonce_manager.get_nonce_count(nonce)
    if nc_old is not None:
        if nc_new is None or nc_new <= nc_old:
            return False
    if nc_new is not None:
        nonce_manager.set_nonce_count(nonce, nc_new)
    return True
