@SuppressWarnings("WeakerAccess") //for testing protected byte[] toBytes(Object o) { String s; // https://github.com/jwtk/jjwt/issues/380 for Android compatibility (Android doesn't have org.json.JSONWriter): // This instanceof check is a sneaky (hacky?) heuristic: A JwtBuilder only ever provides Map<String,Object> // instances to its serializer instances, so by the time this method is invoked, 'o' will always be a // JSONObject. // // This is sufficient for all JJWT-supported scenarios on Android since Android users shouldn't ever use // JJWT's internal Serializer implementation for general JSON serialization. That is, its intended use // is within the context of JwtBuilder execution and not for application use outside of that. if (o instanceof JSONObject) { s = o.toString(); } else { // we still call JSONWriter for all other values 'just in case', and this works for all valid JSON values // This would fail on Android unless they include the newer org.json dependency and ignore Android's. s = Classes.invokeStatic(JSON_WRITER_CLASS_NAME, "valueToString", VALUE_TO_STRING_ARG_TYPES, o); } return s.getBytes(Strings.UTF_8); } }
case RS512: case PS512: return Classes.invokeStatic(RSA, "generateKeyPair", SIG_ARG_TYPES, alg); case ES256: case ES384: case ES512: return Classes.invokeStatic(EC, "generateKeyPair", SIG_ARG_TYPES, alg); default: String msg = "The " + alg.name() + " algorithm does not support Key Pairs.";
case HS384: case HS512: return Classes.invokeStatic(MAC, "generateKey", SIG_ARG_TYPES, alg); default: String msg = "The " + alg.name() + " algorithm does not support shared secret keys.";
@SuppressWarnings("WeakerAccess") //for testing protected byte[] toBytes(Object o) { String s; // https://github.com/jwtk/jjwt/issues/380 for Android compatibility (Android doesn't have org.json.JSONWriter): // This instanceof check is a sneaky (hacky?) heuristic: A JwtBuilder only ever provides Map<String,Object> // instances to its serializer instances, so by the time this method is invoked, 'o' will always be a // JSONObject. // // This is sufficient for all JJWT-supported scenarios on Android since Android users shouldn't ever use // JJWT's internal Serializer implementation for general JSON serialization. That is, its intended use // is within the context of JwtBuilder execution and not for application use outside of that. if (o instanceof JSONObject) { s = o.toString(); } else { // we still call JSONWriter for all other values 'just in case', and this works for all valid JSON values // This would fail on Android unless they include the newer org.json dependency and ignore Android's. s = Classes.invokeStatic(JSON_WRITER_CLASS_NAME, "valueToString", VALUE_TO_STRING_ARG_TYPES, o); } return s.getBytes(Strings.UTF_8); } }
case RS512: case PS512: return Classes.invokeStatic(RSA, "generateKeyPair", SIG_ARG_TYPES, alg); case ES256: case ES384: case ES512: return Classes.invokeStatic(EC, "generateKeyPair", SIG_ARG_TYPES, alg); default: String msg = "The " + alg.name() + " algorithm does not support Key Pairs.";
case HS384: case HS512: return Classes.invokeStatic(MAC, "generateKey", SIG_ARG_TYPES, alg); default: String msg = "The " + alg.name() + " algorithm does not support shared secret keys.";