export function wrapWithKeyObjectIfSupported()

in modules/material-management/src/cryptographic_material.ts [928:943]


export function wrapWithKeyObjectIfSupported(
  dataKey: Uint8Array | AwsEsdkKeyObject
): Uint8Array | AwsEsdkKeyObject {
  if (supportsKeyObject) {
    if (dataKey instanceof Uint8Array) {
      const ko = supportsKeyObject.createSecretKey(dataKey)
      /* Postcondition: Zero the secret.  It is now inside the KeyObject. */
      dataKey.fill(0)
      return ko
    }
    if (dataKey instanceof supportsKeyObject.KeyObject) return dataKey
  } else if (dataKey instanceof Uint8Array) {
    return dataKey
  }
  throw new Error('Unsupported dataKey type')
}