JSCryptoKeyCustom.cpp [plain text]
#include "config.h"
#include "JSCryptoKey.h"
#if ENABLE(SUBTLE_CRYPTO)
#include "CryptoKeyAES.h"
#include "CryptoKeyEC.h"
#include "CryptoKeyHMAC.h"
#include "CryptoKeyRSA.h"
#include "CryptoKeyRaw.h"
#include "JSCryptoAlgorithmBuilder.h"
#include <heap/HeapInlines.h>
#include <runtime/JSCJSValueInlines.h>
using namespace JSC;
namespace WebCore {
JSValue JSCryptoKey::algorithm(JSC::ExecState& state) const
{
if (m_algorithm)
return m_algorithm.get();
JSCryptoAlgorithmBuilder builder(&state);
std::unique_ptr<KeyAlgorithm> algorithm = wrapped().buildAlgorithm();
switch (algorithm->keyAlgorithmClass()) {
case KeyAlgorithmClass::AES: {
auto& aesAlgorithm = downcast<AesKeyAlgorithm>(*algorithm);
builder.add("name", aesAlgorithm.name());
builder.add("length", aesAlgorithm.length());
break;
}
case KeyAlgorithmClass::EC: {
auto& ecAlgorithm = downcast<EcKeyAlgorithm>(*algorithm);
builder.add("name", ecAlgorithm.name());
builder.add("namedCurve", ecAlgorithm.namedCurve());
break;
}
case KeyAlgorithmClass::HMAC: {
auto& hmacAlgorithm = downcast<HmacKeyAlgorithm>(*algorithm);
builder.add("name", hmacAlgorithm.name());
JSCryptoAlgorithmBuilder hmacHash(&state);
hmacHash.add("name", hmacAlgorithm.hash());
builder.add("hash", hmacHash);
builder.add("length", hmacAlgorithm.length());
break;
}
case KeyAlgorithmClass::HRSA: {
auto& rsaAlgorithm = downcast<RsaHashedKeyAlgorithm>(*algorithm);
builder.add("name", rsaAlgorithm.name());
builder.add("modulusLength", rsaAlgorithm.modulusLength());
builder.add("publicExponent", rsaAlgorithm.publicExponent());
JSCryptoAlgorithmBuilder rsaHash(&state);
rsaHash.add("name", rsaAlgorithm.hash());
builder.add("hash", rsaHash);
break;
}
case KeyAlgorithmClass::RSA: {
auto& rsaAlgorithm = downcast<RsaKeyAlgorithm>(*algorithm);
builder.add("name", rsaAlgorithm.name());
builder.add("modulusLength", rsaAlgorithm.modulusLength());
builder.add("publicExponent", rsaAlgorithm.publicExponent());
break;
}
case KeyAlgorithmClass::Raw: {
auto& rawAlgorithm = downcast<RawKeyAlgorithm>(*algorithm);
builder.add("name", rawAlgorithm.name());
break;
}
}
m_algorithm.set(state.vm(), this, builder.result());
return m_algorithm.get();
}
}
#endif // ENABLE(SUBTLE_CRYPTO)