     @_doc = @_eng.doc
     @_session = null
     @_inp = null
+    @_records = {}
+    @_decrypt_errors = []
 
   #-----------------------------------------
 

   
  #-----------------------------------------

  fetch_records : () ->
    ajax "/records", {}, "GET", defer res
    if (code = @check_res res)?
    
   
  #-----------------------------------------



##=======================================================================

# Fulfill the CryptoJS template
BinaryEncoder =
  stringify : (wa) ->
    v = wordArray.words
    n = wordArray.sigBytes
    (((v[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff) for i in [0...n]).join ''

##=======================================================================

exports.Decryptor = class Decryptor

  constructor : (@_aes_key, @_mac_key) ->
    @_errors = []
    @_mac_errors =  0
    @_decode_errors = 0
    @_aes_errors = 0
    @_successes = 0

  hit_error : (error, value, type) ->
    @_errors.push { error, value, type }

  verify_mac : (obj, receive) ->
    packed = purepack.pack obj, ENCODING
    macer = C.algo.HMAC.create C.algo.SHA256, @_mac_key
    computed = macer.update(packed).finalize().toString BinaryEncode
    return (computed == receive)

  decrypt : (v, name) ->
    ret = null
    [err, unpacked] = purepack.unpack v, ENCODING
    if err?
      @hit_error err, v, name
      @_decode_errors++
    else if not (Array.isArray unpacked)
      @hit_error "needed an array", unpacked.toString(), name
      @_decode_errors++
    else if unpacked[0] isnt 1
      @hit_error "only can decode version 1", unpacked[0], name
      @_decode_errors++
    else if unpacked.length isnt 4
      @hit_error "needed 4 fields in array", unpacked.length, name
      @_decode_errors++
    else if not @verify_mac unpacked[2..3], unpacked[1]
      @hit_error "MAC mismatch", unpacked.toString(), name
      @_mac_errors++
    else if not (pt = @decrypt_aes unpacked[2], unpacked[3])?
      @hit_error "Decrypt failure", unpacked.toString(), name
      @_aes_errors++
    else if not ([err, unpacked] = purepack.unpack pt, ENCODING)? or err?
      @hit_error, "Failed to decode plaintext", pt, name
      @_decode_errors ++
    else
      ret = unpacked
    ret

##=======================================================================

exports.Client = class Client

  #-----------------------------------------
