[WebCrypto] Crypto operations should copy their parameters before hoping to another...
[WebKit-https.git] / Source / WebCore / crypto / parameters / CryptoAlgorithmRsaOaepParams.h
index c56e653..300d8e4 100644 (file)
@@ -36,27 +36,35 @@ namespace WebCore {
 class CryptoAlgorithmRsaOaepParams final : public CryptoAlgorithmParameters {
 public:
     // Use labelVector() instead of label. The label will be gone once labelVector() is called.
-    std::optional<BufferSource::VariantType> label;
+    mutable std::optional<BufferSource::VariantType> label;
 
     Class parametersClass() const final { return Class::RsaOaepParams; }
 
-    const Vector<uint8_t>& labelVector()
+    const Vector<uint8_t>& labelVector() const
     {
         if (!m_labelVector.isEmpty() || !label)
             return m_labelVector;
 
-        m_labelBuffer = WTFMove(*label);
+        BufferSource labelBuffer = WTFMove(*label);
         label = std::nullopt;
-        if (!m_labelBuffer.length())
+        if (!labelBuffer.length())
             return m_labelVector;
 
-        m_labelVector.append(m_labelBuffer.data(), m_labelBuffer.length());
+        m_labelVector.append(labelBuffer.data(), labelBuffer.length());
         return m_labelVector;
     }
 
+    CryptoAlgorithmRsaOaepParams isolatedCopy() const
+    {
+        CryptoAlgorithmRsaOaepParams result;
+        result.identifier = identifier;
+        result.m_labelVector = labelVector();
+
+        return result;
+    }
+
 private:
-    Vector<uint8_t> m_labelVector;
-    BufferSource m_labelBuffer;
+    mutable Vector<uint8_t> m_labelVector;
 };
 
 } // namespace WebCore