How to use the @aws-crypto/serialize.deserializeFactory function in @aws-crypto/serialize

To help you get started, we’ve selected a few @aws-crypto/serialize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-encryption-sdk-javascript / modules / decrypt-browser / src / decrypt.ts View on Github external
WebCryptoMaterialsManager // eslint-disable-line no-unused-vars
} from '@aws-crypto/material-management-browser'
import {
  deserializeSignature,
  MessageHeader, // eslint-disable-line no-unused-vars
  deserializeFactory,
  kdfInfo,
  decodeBodyHeader,
  aadFactory,
  concatBuffers,
  der2raw,
  HeaderInfo // eslint-disable-line no-unused-vars
} from '@aws-crypto/serialize'
import { fromUtf8, toUtf8 } from '@aws-sdk/util-utf8-browser'

const deserialize = deserializeFactory(toUtf8, WebCryptoAlgorithmSuite)
const { messageAADContentString, messageAAD } = aadFactory(fromUtf8)

export interface DecryptResult {
  messageHeader: MessageHeader
  plaintext: Uint8Array
}

export async function decrypt (
  cmm: KeyringWebCrypto|WebCryptoMaterialsManager,
  ciphertext: Uint8Array
): Promise {
  /* If the cmm is a Keyring, wrap it with WebCryptoDefaultCryptographicMaterialsManager. */
  cmm = cmm instanceof KeyringWebCrypto
    ? new WebCryptoDefaultCryptographicMaterialsManager(cmm)
    : cmm