How to use the ow.buffer function in ow

To help you get started, we’ve selected a few ow 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 KishanBagaria / padding-oracle-attacker / src / encrypt.ts View on Github external
async function encrypt({
  url, blockSize, logMode = 'full', plaintext: _plaintext, makeFinalRequest = true, lastCiphertextBlock, ...args
}: EncryptOptions) {
  ow(_plaintext, 'plaintext', ow.buffer)
  ow(lastCiphertextBlock, ow.optional.buffer)
  if (lastCiphertextBlock && lastCiphertextBlock.length !== blockSize) throw TypeError('Invalid `lastCiphertextBlock`, should have length equal to `blockSize`')

  const plaintext = addPadding(_plaintext, blockSize)

  const blockCount = (plaintext.length / blockSize) + 1
  const totalSize = blockCount * blockSize

  const foundBytes = Buffer.alloc(totalSize) // ciphertext bytes
  const interBytes = Buffer.alloc(totalSize - blockSize)
  const foundOffsets: Set = new Set()

  if (lastCiphertextBlock) {
    lastCiphertextBlock.copy(foundBytes, foundBytes.length - blockSize)
  }
github KishanBagaria / padding-oracle-attacker / src / decrypt.ts View on Github external
async function decrypt({
  url, blockSize, logMode = 'full', ciphertext, isDecryptionSuccess, makeInitialRequest = true, alreadyFound, startFromFirstBlock, initFirstPayloadBlockWithOrigBytes, ...args
}: DecryptOptions) {
  ow(ciphertext, ow.buffer)
  ow(alreadyFound, ow.optional.buffer)
  if (ciphertext.length % blockSize !== 0) throw TypeError('Invalid `ciphertext`, should be evenly divisble by `blockSize`')

  const totalSize = ciphertext.length
  const blockCount = totalSize / blockSize

  const foundBytes = Buffer.alloc(totalSize - blockSize) // plaintext bytes
  const interBytes = Buffer.alloc(totalSize - blockSize)
  const foundOffsets: Set = new Set()

  if (alreadyFound && alreadyFound.length) {
    const startIndex = foundBytes.length - alreadyFound.length
    const lastBytes = ciphertext.slice(startIndex)
    const interFound = xor(alreadyFound, lastBytes)
    alreadyFound.copy(foundBytes, startIndex)
    interFound.copy(interBytes, startIndex)

ow

Function argument validation for humans

MIT
Latest version published 21 days ago

Package Health Score

80 / 100
Full package analysis