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

package com.nimbusds.jose.jwk;

import java.util.Iterator;
import java.text.ParseException;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.List;

public enum KeyOperation
{
    SIGN("sign"), 
    VERIFY("verify"), 
    ENCRYPT("encrypt"), 
    DECRYPT("decrypt"), 
    WRAP_KEY("wrapKey"), 
    UNWRAP_KEY("unwrapKey"), 
    DERIVE_KEY("deriveKey"), 
    DERIVE_BITS("deriveBits");
    
    private final String identifier;
    
    private KeyOperation(final String identifier) {
        if (identifier == null) {
            throw new IllegalArgumentException("The key operation identifier must not be null");
        }
        this.identifier = identifier;
    }
    
    public String identifier() {
        return this.identifier;
    }
    
    @Override
    public String toString() {
        return this.identifier();
    }
    
    public static Set<KeyOperation> parse(final List<String> sl) throws ParseException {
        if (sl == null) {
            return null;
        }
        final Set<KeyOperation> keyOps = new LinkedHashSet<KeyOperation>();
        for (final String s : sl) {
            if (s == null) {
                continue;
            }
            KeyOperation parsedOp = null;
            for (final KeyOperation op : values()) {
                if (s.equals(op.identifier())) {
                    parsedOp = op;
                    break;
                }
            }
            if (parsedOp == null) {
                throw new ParseException("Invalid JWK operation: " + s, 0);
            }
            keyOps.add(parsedOp);
        }
        return keyOps;
    }
}
