module RbNaCl::SelfTest

def box_common_test(box)

def box_common_test(box)
  nonce      = vector :box_nonce
  message    = vector :box_message
  ciphertext = vector :box_ciphertext
  raise SelfTestFailure, "failed to generate correct ciphertext" unless box.encrypt(nonce, message) == ciphertext
  raise SelfTestFailure, "failed to decrypt ciphertext correctly" unless box.decrypt(nonce, ciphertext) == message
  begin
    passed         = false
    corrupt_ct     = ciphertext.dup
    corrupt_ct[23] = " "
    box.decrypt(nonce, corrupt_ct)
  rescue CryptoError
    passed = true
  ensure
    passed || raise(SelfTestFailure, "failed to detect corrupt ciphertext")
  end
end