 {do_message} = require '../../lib/openpgp/processor'
 {keys,data}  = require '../data/detached'
 {WordArray}  = require 'triplesec'
+{MRF}        = require '../../lib/rand'
 
 #=================================================
 
 ring = new PgpKeyRing()
+
+#==========================================
+
+random = (hi) -> MRF().random_word() % hi
+
+#==========================================
+
+corrupt = (inbuf, cb) ->
+  outbuf = new Buffer inbuf
+  i = random inbuf.length
+  c = (random 0xff) + 1
+  outbuf.writeUInt8((inbuf.readUInt8(i) ^ c), i)
+  cb outbuf
 
 #==========================================
 

  # Base-64-decode the file data
  for key,val of data
    val.data = new Buffer val.data, 'base64'

  cb()



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

good_check_sig_all_at_once = (T, name, {data,sig,bad_data}, cb) -> 
  await do_message { keyfetch : ring, armored : sig, data }, defer err
  T.no_error err, "sig worked for #{name}"
  T.waypoint "Sig #{name} / good checked out"
  cb()

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

bad_check_sig_all_at_once = (T, name, {sig,bad_data}, cb) -> 
  await do_message { keyfetch : ring, armored : sig, data : bad_data }, defer err
  T.assert err?, "errored out on bad signature"
  T.waypoint "Sig #{name} / bad checked out"
  cb()

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