#
# Commands covered: nacl::auth
#

#
# (c) 2016 Alexander Schoepe
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

if {[lsearch [namespace children] ::tcltest] == -1} {
  package require tcltest 2
  namespace import -force ::tcltest::*
  loadTestedCommands
}

package require nacl

if {[lsearch -exact [nacl::randombytes names] urandom] > -1} {
  nacl::randombytes source urandom
}

set m1 [binary decode hex cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd]
set k1 [binary decode hex 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20]
set a1 [binary decode hex 372efcf9b40b35c2115b1346903d2ef42fced46f0846e7257bb156d3d7b30d3f]

test auth-1.1 {auth takes args} -body {
  nacl::auth
} -returnCodes error -result "wrong # args: should be \"nacl::auth ?command? ?-option? ...\""

test auth-1.2 {auth info} {
  list [catch {nacl::auth info} l] $l
} {0 {auth 32 nonce 32}}

test auth-1.3 {auth hmac512256} {
  set m2 {what do ya want for nothing?}
  set k2 Jefe[string repeat \x00 28]
  list [nacl::auth -hmac512256 auth $m2 $k2] [binary encode hex $auth]
} {0 164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea250554}

test auth-1.4 {auth hmac256} {
  list [nacl::auth -hmac256 auth $m1 $k1] $auth
} [list 0 $a1]

test auth-1.5 {auth verify hmac256} {
  nacl::auth verify -hmac256 $a1 $m1 $k1
} 0

# cleanup
::tcltest::cleanupTests
return
