void JSCryptoKeySerializationJWK::buildJSONForRSAComponents(JSC::ExecState* exec, const CryptoKeyDataRSAComponents& data, JSC::JSObject* result) { addToJSON(exec, result, "kty", "RSA"); addToJSON(exec, result, "n", base64URLEncode(data.modulus())); addToJSON(exec, result, "e", base64URLEncode(data.exponent())); if (data.type() == CryptoKeyDataRSAComponents::Type::Public) return; addToJSON(exec, result, "d", base64URLEncode(data.privateExponent())); if (!data.hasAdditionalPrivateKeyParameters()) return; addToJSON(exec, result, "p", base64URLEncode(data.firstPrimeInfo().primeFactor)); addToJSON(exec, result, "q", base64URLEncode(data.secondPrimeInfo().primeFactor)); addToJSON(exec, result, "dp", base64URLEncode(data.firstPrimeInfo().factorCRTExponent)); addToJSON(exec, result, "dq", base64URLEncode(data.secondPrimeInfo().factorCRTExponent)); addToJSON(exec, result, "qi", base64URLEncode(data.secondPrimeInfo().factorCRTCoefficient)); if (data.otherPrimeInfos().isEmpty()) return; JSArray* oth = constructEmptyArray(exec, 0, exec->lexicalGlobalObject(), data.otherPrimeInfos().size()); for (size_t i = 0, size = data.otherPrimeInfos().size(); i < size; ++i) { JSObject* jsPrimeInfo = constructEmptyObject(exec); addToJSON(exec, jsPrimeInfo, "r", base64URLEncode(data.otherPrimeInfos()[i].primeFactor)); addToJSON(exec, jsPrimeInfo, "d", base64URLEncode(data.otherPrimeInfos()[i].factorCRTExponent)); addToJSON(exec, jsPrimeInfo, "t", base64URLEncode(data.otherPrimeInfos()[i].factorCRTCoefficient)); oth->putDirectIndex(exec, i, jsPrimeInfo); } result->putDirect(exec->vm(), Identifier(exec, "oth"), oth); }