001package com.nimbusds.jose.jwk; 002 003 004import java.text.ParseException; 005 006 007/** 008 * Enumeration of key uses. Represents the {@code use} parameter in a JSON Web 009 * Key (JWK). 010 * 011 * <p>Represents the following JWK use values: 012 * 013 * <ul> 014 * <li>{@link #SIGNATURE sig} 015 * <li>{@link #ENCRYPTION enc} 016 * </ul> 017 * 018 * @author Vladimir Dzhuvinov 019 * @version $version$ (2013-05-29) 020 */ 021public enum Use { 022 023 024 /** 025 * Signature. 026 */ 027 SIGNATURE, 028 029 030 /** 031 * Encryption. 032 */ 033 ENCRYPTION; 034 035 036 /** 037 * Parses a JSON Web Key (JWK) use from the specified {@code use} 038 * parameter value. 039 * 040 * @param s The string to parse. Must be either "sig" or "enc". Must 041 * not be {@code null}. 042 * 043 * @throws ParseException If the string couldn't be parsed to a valid 044 * key use. 045 */ 046 public static Use parse(final String s) 047 throws ParseException { 048 049 if (s.equals("sig")) { 050 051 return SIGNATURE; 052 053 } else if (s.equals("enc")) { 054 055 return ENCRYPTION; 056 } else { 057 058 throw new ParseException("Invalid JWK use: " + s, 0); 059 } 060 } 061}