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

package com.nimbusds.jose.jwk;

import com.nimbusds.jwt.util.DateUtils;
import java.util.Date;
import com.nimbusds.jose.util.X509CertChainUtils;
import com.nimbusds.jose.util.Base64;
import java.util.List;
import com.nimbusds.jose.util.Base64URL;
import java.net.URI;
import com.nimbusds.jose.Algorithm;
import java.util.Set;
import java.text.ParseException;
import com.nimbusds.jose.util.JSONObjectUtils;
import java.util.Map;

final class JWKMetadata
{
    static KeyType parseKeyType(final Map<String, Object> o) throws ParseException {
        try {
            return KeyType.parse(JSONObjectUtils.getString(o, "kty"));
        }
        catch (final IllegalArgumentException e) {
            throw new ParseException(e.getMessage(), 0);
        }
    }
    
    static KeyUse parseKeyUse(final Map<String, Object> o) throws ParseException {
        return KeyUse.parse(JSONObjectUtils.getString(o, "use"));
    }
    
    static Set<KeyOperation> parseKeyOperations(final Map<String, Object> o) throws ParseException {
        return KeyOperation.parse(JSONObjectUtils.getStringList(o, "key_ops"));
    }
    
    static Algorithm parseAlgorithm(final Map<String, Object> o) throws ParseException {
        return Algorithm.parse(JSONObjectUtils.getString(o, "alg"));
    }
    
    static String parseKeyID(final Map<String, Object> o) throws ParseException {
        return JSONObjectUtils.getString(o, "kid");
    }
    
    static URI parseX509CertURL(final Map<String, Object> o) throws ParseException {
        return JSONObjectUtils.getURI(o, "x5u");
    }
    
    static Base64URL parseX509CertThumbprint(final Map<String, Object> o) throws ParseException {
        return JSONObjectUtils.getBase64URL(o, "x5t");
    }
    
    static Base64URL parseX509CertSHA256Thumbprint(final Map<String, Object> o) throws ParseException {
        return JSONObjectUtils.getBase64URL(o, "x5t#S256");
    }
    
    static List<Base64> parseX509CertChain(final Map<String, Object> o) throws ParseException {
        final List<Base64> chain = X509CertChainUtils.toBase64List(JSONObjectUtils.getJSONArray(o, "x5c"));
        if (chain == null || !chain.isEmpty()) {
            return chain;
        }
        return null;
    }
    
    static Date parseExpirationTime(final Map<String, Object> o) throws ParseException {
        if (o.get("exp") == null) {
            return null;
        }
        return DateUtils.fromSecondsSinceEpoch(JSONObjectUtils.getLong(o, "exp"));
    }
    
    static Date parseNotBeforeTime(final Map<String, Object> o) throws ParseException {
        if (o.get("nbf") == null) {
            return null;
        }
        return DateUtils.fromSecondsSinceEpoch(JSONObjectUtils.getLong(o, "nbf"));
    }
    
    static Date parseIssueTime(final Map<String, Object> o) throws ParseException {
        if (o.get("iat") == null) {
            return null;
        }
        return DateUtils.fromSecondsSinceEpoch(JSONObjectUtils.getLong(o, "iat"));
    }
    
    static KeyRevocation parseKeyRevocation(final Map<String, Object> o) throws ParseException {
        if (o.get("revoked") == null) {
            return null;
        }
        return KeyRevocation.parse(JSONObjectUtils.getJSONObject(o, "revoked"));
    }
}
