/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  org.jose4j.jwt.JwtClaims
 *  org.jose4j.jwt.MalformedClaimException
 *  org.jose4j.jwt.consumer.ErrorCodeValidator$Error
 *  org.jose4j.jwt.consumer.InvalidJwtException
 *  org.jose4j.jwt.consumer.JwtConsumer
 *  org.jose4j.jwt.consumer.JwtConsumerBuilder
 *  org.jose4j.jwt.consumer.JwtContext
 *  org.jose4j.jwx.JsonWebStructure
 *  org.jose4j.keys.resolvers.JwksVerificationKeyResolver
 *  org.jose4j.keys.resolvers.VerificationKeyResolver
 */
package com.l7tech.server.oauth2;

import com.l7tech.server.oauth2.OAuth2Verifier;
import com.l7tech.server.oauth2.OAuth2VerifierResult;
import com.l7tech.server.oauth2.SSGOAuth2Issuer;
import com.l7tech.server.oauth2.SSGOAuth2VerifierResult;
import java.util.HashMap;
import org.jose4j.jwt.JwtClaims;
import org.jose4j.jwt.MalformedClaimException;
import org.jose4j.jwt.consumer.ErrorCodeValidator;
import org.jose4j.jwt.consumer.InvalidJwtException;
import org.jose4j.jwt.consumer.JwtConsumer;
import org.jose4j.jwt.consumer.JwtConsumerBuilder;
import org.jose4j.jwt.consumer.JwtContext;
import org.jose4j.jwx.JsonWebStructure;
import org.jose4j.keys.resolvers.JwksVerificationKeyResolver;
import org.jose4j.keys.resolvers.VerificationKeyResolver;

public class SSGOAuth2Verifier
implements OAuth2Verifier {
    private final SSGOAuth2Issuer a;
    private static final String[] b;

    public SSGOAuth2Verifier(SSGOAuth2Issuer sSGOAuth2Issuer) {
        this.a = sSGOAuth2Issuer;
    }

    @Override
    public OAuth2VerifierResult verify(String string) {
        JwtConsumer jwtConsumer = new JwtConsumerBuilder().setRequireExpirationTime().setAllowedClockSkewInSeconds(this.a.d()).setVerificationKeyResolver((VerificationKeyResolver)new JwksVerificationKeyResolver(this.a.c())).build();
        SSGOAuth2VerifierResult sSGOAuth2VerifierResult = new SSGOAuth2VerifierResult();
        try {
            JwtContext jwtContext = jwtConsumer.process(string);
            JwtClaims jwtClaims = jwtContext.getJwtClaims();
            try {
                if (this.a.isTokenRevoked(jwtClaims.getJwtId())) {
                    HashMap<String, Object> hashMap = new HashMap<String, Object>();
                    String[] stringArray = b;
                    hashMap.put(stringArray[9], -1);
                    hashMap.put(stringArray[1], stringArray[0]);
                    sSGOAuth2VerifierResult.setResult(hashMap);
                    return sSGOAuth2VerifierResult;
                }
            }
            catch (MalformedClaimException malformedClaimException) {
                // empty catch block
            }
            sSGOAuth2VerifierResult.setValid(true);
            String[] stringArray = b;
            sSGOAuth2VerifierResult.setTokenType(((JsonWebStructure)jwtContext.getJoseObjects().getFirst()).getHeader(stringArray[8]));
            sSGOAuth2VerifierResult.setResult(jwtClaims.getClaimsMap());
        }
        catch (InvalidJwtException invalidJwtException) {
            HashMap<String, Object> hashMap;
            block8: {
                block7: {
                    hashMap = new HashMap<String, Object>();
                    try {
                        if (!invalidJwtException.hasExpired()) break block7;
                        hashMap.put(b[4], 1);
                        hashMap.put(b[7], b[6]);
                        break block8;
                    }
                    catch (MalformedClaimException malformedClaimException) {
                        throw SSGOAuth2Verifier.a(malformedClaimException);
                    }
                }
                String[] stringArray = b;
                hashMap.put(stringArray[4], -1);
                hashMap.put(stringArray[7], stringArray[5]);
                hashMap.put(stringArray[2], invalidJwtException.getErrorDetails().stream().map(ErrorCodeValidator.Error::getErrorCode).toList());
                hashMap.put(stringArray[3], invalidJwtException.getErrorDetails().stream().map(ErrorCodeValidator.Error::getErrorMessage).toList());
            }
            sSGOAuth2VerifierResult.setResult(hashMap);
        }
        return sSGOAuth2VerifierResult;
    }

    private static MalformedClaimException a(MalformedClaimException malformedClaimException) {
        return malformedClaimException;
    }

    /*
     * Unable to fully structure code
     */
    static {
        block10: {
            block9: {
                var5 = new String[10];
                var3_1 = 0;
                var2_2 = "[\u001cEB\u0002:Yt%1\u0010\u0013#]z.u\u0011t9c\r\u0004\nVt8r\u0010\u001f%Fx$\u007f\u0006t9c\r\u0004&\u0012t9c\r\u0004\nVt8r\u0010\u001f%Fx$\u007f\u0011\u0005t9c\r\u0004\u0011X%g\u0003\u001a<V1\u0001F6V!]z.\u007f\u0011[\u001cEB\u0002:Yt%1\u0007\u000e%[c.u\u0011t9c\r\u0004\nVt8r\u0010\u001f%Fx$\u007f";
                var4_3 = "[\u001cEB\u0002:Yt%1\u0010\u0013#]z.u\u0011t9c\r\u0004\nVt8r\u0010\u001f%Fx$\u007f\u0006t9c\r\u0004&\u0012t9c\r\u0004\nVt8r\u0010\u001f%Fx$\u007f\u0011\u0005t9c\r\u0004\u0011X%g\u0003\u001a<V1\u0001F6V!]z.\u007f\u0011[\u001cEB\u0002:Yt%1\u0007\u000e%[c.u\u0011t9c\r\u0004\nVt8r\u0010\u001f%Fx$\u007f".length();
                var1_4 = 17;
                var0_5 = -1;
lbl7:
                // 2 sources

                while (true) {
                    v0 = 87;
                    v1 = ++var0_5;
                    v2 = var2_2.substring(v1, v1 + var1_4);
                    v3 = -1;
                    break block9;
                    break;
                }
lbl13:
                // 1 sources

                while (true) {
                    var5[var3_1++] = SSGOAuth2Verifier.a(v0, SSGOAuth2Verifier.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    var2_2 = "\u000b\\\u000f\u0005\u001aW\rcj";
                    var4_3 = "\u000b\\\u000f\u0005\u001aW\rcj".length();
                    var1_4 = 3;
                    var0_5 = -1;
lbl22:
                    // 2 sources

                    while (true) {
                        v0 = 57;
                        v4 = ++var0_5;
                        v2 = var2_2.substring(v4, v4 + var1_4);
                        v3 = 0;
                        break block9;
                        break;
                    }
                    break;
                }
lbl28:
                // 1 sources

                while (true) {
                    var5[var3_1++] = SSGOAuth2Verifier.a(v0, SSGOAuth2Verifier.a(v2));
                    if ((var0_5 += var1_4) < var4_3) {
                        var1_4 = var2_2.charAt(var0_5);
                        ** continue;
                    }
                    break block10;
                    break;
                }
            }
            switch (v3) {
                default: {
                    ** continue;
                }
                ** case 0:
lbl39:
                // 1 sources

                ** continue;
            }
        }
        SSGOAuth2Verifier.b = var5;
    }

    private static char[] a(String string) {
        char[] cArray = string.toCharArray();
        if (cArray.length < 2) {
            cArray = cArray;
            cArray[0] = (char)(cArray[0] ^ 0x65);
        }
        return cArray;
    }

    /*
     * Handled impossible loop by duplicating code
     * Enabled aggressive block sorting
     */
    private static String a(int n2, char[] cArray) {
        char[] cArray2;
        block11: {
            int n3;
            int n4;
            int n5;
            block10: {
                n5 = n2;
                cArray2 = cArray;
                n4 = cArray.length;
                n3 = 0;
                if (!true) break block10;
                n4 = n4;
                if (n4 <= n3) break block11;
            }
            do {
                n5 = n5;
                cArray2 = cArray2;
                int n6 = n3;
                cArray2[n6] = (char)(cArray2[n6] ^ (n5 ^ (switch (n3 % 7) {
                    case 0 -> 70;
                    case 1 -> 28;
                    case 2 -> 70;
                    case 3 -> 53;
                    case 4 -> 33;
                    case 5 -> 2;
                    default -> 101;
                })));
                ++n3;
                n4 = n4;
            } while (n4 > n3);
        }
        return new String(cArray2).intern();
    }
}

