{"ast":null,"code":"'use strict';\n\nvar assert = require('minimalistic-assert');\n\nvar inherits = require('inherits');\n\nvar proto = {};\n\nfunction CBCState(iv) {\n  assert.equal(iv.length, 8, 'Invalid IV length');\n  this.iv = new Array(8);\n\n  for (var i = 0; i < this.iv.length; i++) {\n    this.iv[i] = iv[i];\n  }\n}\n\nfunction instantiate(Base) {\n  function CBC(options) {\n    Base.call(this, options);\n\n    this._cbcInit();\n  }\n\n  inherits(CBC, Base);\n  var keys = Object.keys(proto);\n\n  for (var i = 0; i < keys.length; i++) {\n    var key = keys[i];\n    CBC.prototype[key] = proto[key];\n  }\n\n  CBC.create = function create(options) {\n    return new CBC(options);\n  };\n\n  return CBC;\n}\n\nexports.instantiate = instantiate;\n\nproto._cbcInit = function _cbcInit() {\n  var state = new CBCState(this.options.iv);\n  this._cbcState = state;\n};\n\nproto._update = function _update(inp, inOff, out, outOff) {\n  var state = this._cbcState;\n  var superProto = this.constructor.super_.prototype;\n  var iv = state.iv;\n\n  if (this.type === 'encrypt') {\n    for (var i = 0; i < this.blockSize; i++) {\n      iv[i] ^= inp[inOff + i];\n    }\n\n    superProto._update.call(this, iv, 0, out, outOff);\n\n    for (var i = 0; i < this.blockSize; i++) {\n      iv[i] = out[outOff + i];\n    }\n  } else {\n    superProto._update.call(this, inp, inOff, out, outOff);\n\n    for (var i = 0; i < this.blockSize; i++) {\n      out[outOff + i] ^= iv[i];\n    }\n\n    for (var i = 0; i < this.blockSize; i++) {\n      iv[i] = inp[inOff + i];\n    }\n  }\n};","map":null,"metadata":{},"sourceType":"script"}