class DirectDigestAuthClient extends DirectClient {

    private String realm = "pac4jRealm";

    /**
     * <p>Constructor for DirectDigestAuthClient.</p>
     */
    public DirectDigestAuthClient() {
    }

    /**
     * <p>Constructor for DirectDigestAuthClient.</p>
     *
     * @param digestAuthenticator a {@link Authenticator} object
     */
    public DirectDigestAuthClient(final Authenticator digestAuthenticator) {
        setAuthenticatorIfUndefined(digestAuthenticator);
    }

    /**
     * <p>Constructor for DirectDigestAuthClient.</p>
     *
     * @param digestAuthenticator a {@link Authenticator} object
     * @param profileCreator a {@link ProfileCreator} object
     */
    public DirectDigestAuthClient(final Authenticator digestAuthenticator,
                                 final ProfileCreator profileCreator) {
        setAuthenticatorIfUndefined(digestAuthenticator);
        setProfileCreatorIfUndefined(profileCreator);
    }

    /** {@inheritDoc} */
    @Override
    protected void internalInit(final boolean forceReinit) {
        setCredentialsExtractorIfUndefined(new DigestAuthExtractor());
    }

    /**
     * {@inheritDoc}
     *
     * Per RFC 2617
     * If a server receives a request for an access-protected object, and an
     * acceptable Authorization header is not sent, the server responds with
     * a "401 Unauthorized" status code, and a WWW-Authenticate header
     */
    @Override
    public Optional<Credentials> getCredentials(final CallContext ctx) {
        // set the www-authenticate in case of error
        val nonce = calculateNonce();
        ctx.webContext().setResponseHeader(HttpConstants.AUTHENTICATE_HEADER, "Digest realm=\"" + realm + "\", qop=\"auth\", nonce=\""
            + nonce + "\"");

        return super.getCredentials(ctx);
    }

    /**
     * A server-specified data string which should be uniquely generated each time a 401 response is made (RFC 2617)
     * Based on current time including nanoseconds
     */
    private String calculateNonce() {<FILL_FUNCTION_BODY>}
}

        val time = LocalDateTime.now();
        val formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd:HH:mm:ss.SSS");
        val fmtTime = formatter.format(time);
        return CredentialUtil.encryptMD5(fmtTime + CommonHelper.randomString(10));
    
<methods>public non-sealed void <init>() ,public final Optional<org.pac4j.core.exception.http.RedirectionAction> getLogoutAction(CallContext, org.pac4j.core.profile.UserProfile, java.lang.String) ,public final Optional<org.pac4j.core.exception.http.RedirectionAction> getRedirectionAction(CallContext) ,public final org.pac4j.core.exception.http.HttpAction processLogout(CallContext, org.pac4j.core.credentials.Credentials) <variables>