Method: RbNaCl::SelfTest.box_common_test

Defined in:
lib/rbnacl/self_test.rb

.box_common_test(box) ⇒ Object

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rbnacl/self_test.rb', line 31

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