// 
// Decompiled by Procyon v0.6.0
// 

package com.nimbusds.jose.proc;

import java.util.Collection;
import java.util.HashSet;
import java.util.Arrays;
import java.util.Collections;
import com.nimbusds.jose.JOSEObjectType;
import java.util.Set;
import com.nimbusds.jose.shaded.jcip.Immutable;

@Immutable
public class DefaultJOSEObjectTypeVerifier<C extends SecurityContext> implements JOSEObjectTypeVerifier<C>
{
    private final Set<JOSEObjectType> allowedTypes;
    public static final DefaultJOSEObjectTypeVerifier JOSE;
    public static final DefaultJOSEObjectTypeVerifier JWT;
    
    public DefaultJOSEObjectTypeVerifier() {
        this.allowedTypes = Collections.singleton((JOSEObjectType)null);
    }
    
    public DefaultJOSEObjectTypeVerifier(final Set<JOSEObjectType> allowedTypes) {
        if (allowedTypes.isEmpty()) {
            throw new IllegalArgumentException("The allowed types must not be empty");
        }
        this.allowedTypes = allowedTypes;
    }
    
    public DefaultJOSEObjectTypeVerifier(final JOSEObjectType... allowedTypes) {
        if (allowedTypes.length == 0) {
            throw new IllegalArgumentException("The allowed types must not be empty");
        }
        this.allowedTypes = new HashSet<JOSEObjectType>(Arrays.asList(allowedTypes));
    }
    
    public Set<JOSEObjectType> getAllowedTypes() {
        return this.allowedTypes;
    }
    
    @Override
    public void verify(final JOSEObjectType type, final C context) throws BadJOSEException {
        if (type == null && !this.allowedTypes.contains(null)) {
            throw new BadJOSEException("Required JOSE header typ (type) parameter is missing");
        }
        if (!this.allowedTypes.contains(type)) {
            throw new BadJOSEException("JOSE header typ (type) " + type + " not allowed");
        }
    }
    
    static {
        JOSE = new DefaultJOSEObjectTypeVerifier(new JOSEObjectType[] { JOSEObjectType.JOSE, null });
        JWT = new DefaultJOSEObjectTypeVerifier(new JOSEObjectType[] { JOSEObjectType.JWT, null });
    }
}
