#
# @description Unit tests for DES block-cipher.
#
# @author Alejandro Claro (alejandro.claro@gmail.com)
#
# Copyright 2017 All rights reserved.
# Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
#
@testset "Blowfish cipher tests" begin
  @test_throws ArgumentError TripleDesCipher(UInt8[])
  @test_throws ArgumentError TripleDesCipher([ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 ])

  # DES-EDE1
  cipher = TripleDesCipher([ 0x13, 0x34, 0x57, 0x79, 0x9B, 0xBC, 0xDF, 0xF1 ])

  @test block_size(cipher) == 8
  @test key_size(cipher)   == 8

  @test_throws ArgumentError encrypt(cipher, UInt8[])
  @test_throws ArgumentError encrypt(cipher, [ 0x05, 0x06 ])

  @test_throws ArgumentError decrypt(cipher, UInt8[])
  @test_throws ArgumentError decrypt(cipher, [ 0x05, 0x06 ])

  @test encrypt(cipher, UInt8[ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF ]) == UInt8[ 0x85, 0xE8, 0x13, 0x54, 0x0F, 0x0A, 0xB4, 0x05 ]
  @test decrypt(cipher, UInt8[ 0x85, 0xE8, 0x13, 0x54, 0x0F, 0x0A, 0xB4, 0x05 ]) == UInt8[ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF ]

  # DES-EDE2
  cipher = TripleDesCipher([ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ])

  @test block_size(cipher) == 8
  @test key_size(cipher)   == 16

  @test encrypt(cipher, UInt8[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]) == UInt8[ 0xDE, 0xD0, 0x28, 0xF0, 0xC1, 0xF5, 0xA7, 0x74 ]
  @test decrypt(cipher, UInt8[ 0xDE, 0xD0, 0x28, 0xF0, 0xC1, 0xF5, 0xA7, 0x74 ]) == UInt8[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]

  # DES-EDE3
  cipher = TripleDesCipher([ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ])

  @test block_size(cipher) == 8
  @test key_size(cipher)   == 24

  @test encrypt(cipher, UInt8[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]) == UInt8[ 0x0A, 0x6F, 0x81, 0x8B, 0xD8, 0xAD, 0x5E, 0x59 ]
  @test decrypt(cipher, UInt8[ 0x0A, 0x6F, 0x81, 0x8B, 0xD8, 0xAD, 0x5E, 0x59 ]) == UInt8[ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ]
end

