ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& rawFormat, const ArrayPiece& wrappedKey, Key* unwrappingKey, const Dictionary& rawUnwrapAlgorithm, const Dictionary& rawUnwrappedKeyAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
{
    RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
    ScriptPromise promise = result->promise();

    if (!canAccessWebCrypto(scriptState, result.get()))
        return promise;

    if (!ensureNotNull(wrappedKey, "wrappedKey", result.get()))
        return promise;
    if (!ensureNotNull(unwrappingKey, "unwrappingKey", result.get()))
        return promise;

    blink::WebCryptoKeyFormat format;
    if (!Key::parseFormat(rawFormat, format, result.get()))
        return promise;

    blink::WebCryptoKeyUsageMask keyUsages;
    if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get()))
        return promise;

    blink::WebCryptoAlgorithm unwrapAlgorithm;
    if (!parseAlgorithm(rawUnwrapAlgorithm, blink::WebCryptoOperationUnwrapKey, unwrapAlgorithm, result.get()))
        return promise;

    blink::WebCryptoAlgorithm unwrappedKeyAlgorithm;
    if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, blink::WebCryptoOperationImportKey, unwrappedKeyAlgorithm, result.get()))
        return promise;

    if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, blink::WebCryptoOperationUnwrapKey, result.get()))
        return promise;

    blink::Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(), wrappedKey.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result());
    return promise;
}
ScriptPromise SubtleCrypto::wrapKey(ScriptState* scriptState, const String& rawFormat, Key* key, Key* wrappingKey, const Dictionary& rawWrapAlgorithm)
{
    RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
    ScriptPromise promise = result->promise();

    if (!canAccessWebCrypto(scriptState, result.get()))
        return promise;

    if (!ensureNotNull(key, "key", result.get()))
        return promise;

    if (!ensureNotNull(wrappingKey, "wrappingKey", result.get()))
        return promise;

    blink::WebCryptoKeyFormat format;
    if (!Key::parseFormat(rawFormat, format, result.get()))
        return promise;

    blink::WebCryptoAlgorithm wrapAlgorithm;
    if (!parseAlgorithm(rawWrapAlgorithm, blink::WebCryptoOperationWrapKey, wrapAlgorithm, result.get()))
        return promise;

    if (!key->extractable()) {
        result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key is not extractable");
        return promise;
    }

    if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, blink::WebCryptoOperationWrapKey, result.get()))
        return promise;

    blink::Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key(), wrapAlgorithm, result->result());
    return promise;
}
static ScriptPromise startCryptoOperation(ScriptState* scriptState, const Dictionary& rawAlgorithm, Key* key, blink::WebCryptoOperation operationType, const ArrayPiece& signature, const ArrayPiece& dataBuffer)
{
    RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
    ScriptPromise promise = result->promise();

    if (!canAccessWebCrypto(scriptState, result.get()))
        return promise;

    bool requiresKey = operationType != blink::WebCryptoOperationDigest;

    if (requiresKey && !ensureNotNull(key, "key", result.get()))
        return promise;
    if (operationType == blink::WebCryptoOperationVerify && !ensureNotNull(signature, "signature", result.get()))
        return promise;
    if (!ensureNotNull(dataBuffer, "dataBuffer", result.get()))
        return promise;

    blink::WebCryptoAlgorithm algorithm;
    if (!parseAlgorithm(rawAlgorithm, operationType, algorithm, result.get()))
        return promise;

    if (requiresKey && !key->canBeUsedForAlgorithm(algorithm, operationType, result.get()))
        return promise;

    const unsigned char* data = dataBuffer.bytes();
    unsigned dataSize = dataBuffer.byteLength();

    switch (operationType) {
    case blink::WebCryptoOperationEncrypt:
        blink::Platform::current()->crypto()->encrypt(algorithm, key->key(), data, dataSize, result->result());
        break;
    case blink::WebCryptoOperationDecrypt:
        blink::Platform::current()->crypto()->decrypt(algorithm, key->key(), data, dataSize, result->result());
        break;
    case blink::WebCryptoOperationSign:
        blink::Platform::current()->crypto()->sign(algorithm, key->key(), data, dataSize, result->result());
        break;
    case blink::WebCryptoOperationVerify:
        blink::Platform::current()->crypto()->verifySignature(algorithm, key->key(), signature.bytes(), signature.byteLength(), data, dataSize, result->result());
        break;
    case blink::WebCryptoOperationDigest:
        blink::Platform::current()->crypto()->digest(algorithm, data, dataSize, result->result());
        break;
    default:
        ASSERT_NOT_REACHED();
        return ScriptPromise();
    }

    return promise;
}
ScriptPromise SubtleCrypto::importKey(ScriptState* scriptState, const String& rawFormat, const ArrayPiece& keyData, const Dictionary& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
{
    RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
    ScriptPromise promise = result->promise();

    if (!canAccessWebCrypto(scriptState, result.get()))
        return promise;

    if (!ensureNotNull(keyData, "keyData", result.get()))
        return promise;

    blink::WebCryptoKeyFormat format;
    if (!Key::parseFormat(rawFormat, format, result.get()))
        return promise;

    if (format == blink::WebCryptoKeyFormatJwk) {
        result->completeWithError(blink::WebCryptoErrorTypeData, "Key data must be an object for JWK import");
        return promise;
    }

    blink::WebCryptoKeyUsageMask keyUsages;
    if (!Key::parseUsageMask(rawKeyUsages, keyUsages, result.get()))
        return promise;

    blink::WebCryptoAlgorithm algorithm;
    if (!parseAlgorithm(rawAlgorithm, blink::WebCryptoOperationImportKey, algorithm, result.get()))
        return promise;

    blink::Platform::current()->crypto()->importKey(format, keyData.bytes(), keyData.byteLength(), algorithm, extractable, keyUsages, result->result());
    return promise;
}
Exemple #5
0
  /** \brief Wrap an existing Dune grid object.

   \param[in]  dune_grid  Pointer to the Dune grid to wrap.
   \param[in]  topology   The topology of the grid.
   \param[in]  domainIndices Vector of domain indices.
   \param[in]  own  If true, *dune_grid is deleted in this object's destructor.
   */
  explicit ConcreteGrid(DuneGrid *dune_grid, GridParameters::Topology topology,
                        bool own = false)
      : m_dune_grid(ensureNotNull(dune_grid)), m_owns_dune_grid(own),
        m_topology(topology), m_global_id_set(&dune_grid->globalIdSet()),
        m_domain_index(
            *dune_grid,
            std::vector<int>(dune_grid->size(0 /*level*/, 0 /*codim*/),
                             0 /*default index*/)) {}
ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& rawFormat, Key* key)
{
    RefPtr<CryptoResultImpl> result = CryptoResultImpl::create(scriptState);
    ScriptPromise promise = result->promise();

    if (!canAccessWebCrypto(scriptState, result.get()))
        return promise;

    if (!ensureNotNull(key, "key", result.get()))
        return promise;

    blink::WebCryptoKeyFormat format;
    if (!Key::parseFormat(rawFormat, format, result.get()))
        return promise;

    if (!key->extractable()) {
        result->completeWithError(blink::WebCryptoErrorTypeInvalidAccess, "key is not extractable");
        return promise;
    }

    blink::Platform::current()->crypto()->exportKey(format, key->key(), result->result());
    return promise;
}
Exemple #7
0
 /** \brief Wrap an existing Dune grid object.
     \param[in] dune_grid Pointer to the Dune grid to wrap.
     \param[in] topology The topology of the grid
     \param[in] own If true, *dune_grid is deleted in this object's destructor.
 */
 explicit ConcreteGrid(DuneGrid *dune_grid, GridParameters::Topology topology,
                       const std::vector<int> &domainIndices, bool own = false)
     : m_dune_grid(ensureNotNull(dune_grid)), m_owns_dune_grid(own),
       m_topology(topology), m_global_id_set(&dune_grid->globalIdSet()),
       m_domain_index(*dune_grid, domainIndices) {}