Commit 30744386 authored by Tom Schuster's avatar Tom Schuster Committed by Pier Angelo Vendrame
Browse files

Bug 2024443 - Make CryptoKey::GetAlgorithm more idiomatic. r=nkulatova

parent 238f9a77
Loading
Loading
Loading
Loading
+13 −12
Original line number Diff line number Diff line
@@ -186,38 +186,39 @@ void CryptoKey::GetType(nsString& aRetVal) const {

bool CryptoKey::Extractable() const { return (mAttributes & EXTRACTABLE); }

void CryptoKey::GetAlgorithm(JSContext* cx,
void CryptoKey::GetAlgorithm(JSContext* aCx,
                             JS::MutableHandle<JSObject*> aRetVal,
                             ErrorResult& aRv) const {
  bool converted = false;
  JS::Rooted<JS::Value> val(cx);
  JS::Rooted<JS::Value> val(aCx);
  switch (mAlgorithm.mType) {
    case KeyAlgorithmProxy::AES:
      converted = ToJSValue(cx, mAlgorithm.mAes, &val);
      converted = ToJSValue(aCx, mAlgorithm.mAes, &val);
      break;
    case KeyAlgorithmProxy::KDF:
      converted = ToJSValue(cx, mAlgorithm.mKDF, &val);
      converted = ToJSValue(aCx, mAlgorithm.mKDF, &val);
      break;
    case KeyAlgorithmProxy::HMAC:
      converted = ToJSValue(cx, mAlgorithm.mHmac, &val);
      converted = ToJSValue(aCx, mAlgorithm.mHmac, &val);
      break;
    case KeyAlgorithmProxy::RSA: {
      RootedDictionary<RsaHashedKeyAlgorithm> rsa(cx);
      converted = mAlgorithm.mRsa.ToKeyAlgorithm(cx, rsa, aRv);
      if (converted) {
        converted = ToJSValue(cx, rsa, &val);
      RootedDictionary<RsaHashedKeyAlgorithm> rsa(aCx);
      mAlgorithm.mRsa.ToKeyAlgorithm(aCx, rsa, aRv);
      if (aRv.Failed()) {
        return;
      }
      converted = ToJSValue(aCx, rsa, &val);
      break;
    }
    case KeyAlgorithmProxy::EC:
      converted = ToJSValue(cx, mAlgorithm.mEc, &val);
      converted = ToJSValue(aCx, mAlgorithm.mEc, &val);
      break;
    case KeyAlgorithmProxy::OKP:
      converted = ToJSValue(cx, mAlgorithm.mEd, &val);
      converted = ToJSValue(aCx, mAlgorithm.mEd, &val);
      break;
  }
  if (!converted) {
    aRv.Throw(NS_ERROR_DOM_OPERATION_ERR);
    aRv.NoteJSContextException(aCx);
    return;
  }

+2 −4
Original line number Diff line number Diff line
@@ -35,20 +35,18 @@ struct RsaHashedKeyAlgorithmStorage {
  uint16_t mModulusLength;
  CryptoBuffer mPublicExponent;

  bool ToKeyAlgorithm(JSContext* aCx, RsaHashedKeyAlgorithm& aRsa,
  void ToKeyAlgorithm(JSContext* aCx, RsaHashedKeyAlgorithm& aRsa,
                      ErrorResult& aError) const {
    JS::Rooted<JSObject*> exponent(aCx,
                                   mPublicExponent.ToUint8Array(aCx, aError));
    if (aError.Failed()) {
      return false;
      return;
    }

    aRsa.mName = mName;
    aRsa.mModulusLength = mModulusLength;
    aRsa.mHash.mName = mHash.mName;
    aRsa.mPublicExponent.Init(exponent);

    return true;
  }
};