Bug 1289330 - Check for success when calling ToKeyAlgorithm() r=bz

This commit is contained in:
Tim Taubert 2016-07-28 10:21:23 +02:00
Родитель b18a29d071
Коммит 77edbd02e0
2 изменённых файлов: 32 добавлений и 9 удалений

Просмотреть файл

@ -204,8 +204,10 @@ CryptoKey::GetAlgorithm(JSContext* cx, JS::MutableHandle<JSObject*> aRetVal,
break; break;
case KeyAlgorithmProxy::RSA: { case KeyAlgorithmProxy::RSA: {
RootedDictionary<RsaHashedKeyAlgorithm> rsa(cx); RootedDictionary<RsaHashedKeyAlgorithm> rsa(cx);
mAlgorithm.mRsa.ToKeyAlgorithm(cx, rsa); converted = mAlgorithm.mRsa.ToKeyAlgorithm(cx, rsa);
converted = ToJSValue(cx, rsa, &val); if (converted) {
converted = ToJSValue(cx, rsa, &val);
}
break; break;
} }
case KeyAlgorithmProxy::EC: case KeyAlgorithmProxy::EC:
@ -213,8 +215,10 @@ CryptoKey::GetAlgorithm(JSContext* cx, JS::MutableHandle<JSObject*> aRetVal,
break; break;
case KeyAlgorithmProxy::DH: { case KeyAlgorithmProxy::DH: {
RootedDictionary<DhKeyAlgorithm> dh(cx); RootedDictionary<DhKeyAlgorithm> dh(cx);
mAlgorithm.mDh.ToKeyAlgorithm(cx, dh); converted = mAlgorithm.mDh.ToKeyAlgorithm(cx, dh);
converted = ToJSValue(cx, dh, &val); if (converted) {
converted = ToJSValue(cx, dh, &val);
}
break; break;
} }
} }

Просмотреть файл

@ -25,14 +25,21 @@ struct RsaHashedKeyAlgorithmStorage {
uint16_t mModulusLength; uint16_t mModulusLength;
CryptoBuffer mPublicExponent; CryptoBuffer mPublicExponent;
void bool
ToKeyAlgorithm(JSContext* aCx, RsaHashedKeyAlgorithm& aRsa) const ToKeyAlgorithm(JSContext* aCx, RsaHashedKeyAlgorithm& aRsa) const
{ {
JS::Rooted<JSObject*> exponent(aCx, mPublicExponent.ToUint8Array(aCx));
if (!exponent) {
return false;
}
aRsa.mName = mName; aRsa.mName = mName;
aRsa.mModulusLength = mModulusLength; aRsa.mModulusLength = mModulusLength;
aRsa.mHash.mName = mHash.mName; aRsa.mHash.mName = mHash.mName;
aRsa.mPublicExponent.Init(mPublicExponent.ToUint8Array(aCx)); aRsa.mPublicExponent.Init(exponent);
aRsa.mPublicExponent.ComputeLengthAndData(); aRsa.mPublicExponent.ComputeLengthAndData();
return true;
} }
}; };
@ -43,14 +50,26 @@ struct DhKeyAlgorithmStorage {
CryptoBuffer mPrime; CryptoBuffer mPrime;
CryptoBuffer mGenerator; CryptoBuffer mGenerator;
void bool
ToKeyAlgorithm(JSContext* aCx, DhKeyAlgorithm& aDh) const ToKeyAlgorithm(JSContext* aCx, DhKeyAlgorithm& aDh) const
{ {
JS::Rooted<JSObject*> prime(aCx, mPrime.ToUint8Array(aCx));
if (!prime) {
return false;
}
JS::Rooted<JSObject*> generator(aCx, mGenerator.ToUint8Array(aCx));
if (!generator) {
return false;
}
aDh.mName = mName; aDh.mName = mName;
aDh.mPrime.Init(mPrime.ToUint8Array(aCx)); aDh.mPrime.Init(prime);
aDh.mPrime.ComputeLengthAndData(); aDh.mPrime.ComputeLengthAndData();
aDh.mGenerator.Init(mGenerator.ToUint8Array(aCx)); aDh.mGenerator.Init(generator);
aDh.mGenerator.ComputeLengthAndData(); aDh.mGenerator.ComputeLengthAndData();
return true;
} }
}; };