async function configureFallback()

in modules/web-crypto-backend/src/backend-factory.ts [81:110]


  async function configureFallback(fallback: SubtleCrypto) {
    const fallbackRequired = await fallbackRequiredPromise
    /* Precondition: If a fallback is not required, do not configure one. */
    if (!fallbackRequired) {
      return
    }

    /* Precondition: Can not reconfigure fallback. */
    if (webCryptoFallbackPromise)
      throw new Error('Fallback reconfiguration denied')

    /* Precondition: Fallback must look like it supports the required operations. */
    if (!supportsSubtleCrypto(fallback))
      throw new Error('Fallback does not support WebCrypto')

    // This if to lock the fallback.
    // when using the fallback, it is simpler
    // for the customer to not await the success
    // of configuration so we handle it for them
    // I still return in case they want to await
    webCryptoFallbackPromise = supportsZeroByteGCM(fallback).then(
      (zeroByteGCMSupport) => {
        /* Postcondition: The fallback must specifically support ZeroByteGCM. */
        if (!zeroByteGCMSupport)
          throw new Error('Fallback does not support zero byte AES-GCM')
        return fallback
      }
    )
    return webCryptoFallbackPromise
  }