/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.l7tech.util.Background
 *  com.l7tech.util.HexUtils
 */
package com.l7tech.server.policy.assertion.credential;

import com.l7tech.server.policy.assertion.credential.d;
import com.l7tech.server.policy.assertion.credential.f;
import com.l7tech.util.Background;
import com.l7tech.util.HexUtils;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.TimerTask;

public class DigestSessions {
    private static final Random a = new SecureRandom();
    private static DigestSessions b;
    private Map c = new HashMap();

    public static DigestSessions getInstance() {
        if (b == null) {
            b = new DigestSessions();
        }
        return b;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public boolean use(String string) {
        d d10;
        Map map = this.c;
        synchronized (map) {
            d10 = (d)this.c.get(string);
        }
        if (d10 == null) {
            return false;
        }
        long l2 = System.currentTimeMillis();
        d d11 = d10;
        synchronized (d11) {
            if (d10.b <= l2) {
                return false;
            }
            if (d10.c++ > d10.d) {
                return false;
            }
        }
        return true;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public void invalidate(String string) {
        Map map = this.c;
        synchronized (map) {
            this.c.remove(string);
        }
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public String generate(int n2, int n3) {
        long l2 = System.currentTimeMillis();
        byte[] byArray = new byte[64];
        a.nextBytes(byArray);
        String string = HexUtils.encodeBase64((byte[])byArray, (boolean)true);
        Map map = this.c;
        synchronized (map) {
            this.c.put(string, new d(string, l2 + (long)n2, n3));
        }
        return string;
    }

    private DigestSessions() {
        Background.scheduleRepeated((TimerTask)new f(this), (long)300000L, (long)300000L);
    }
}

