digest-blake2b/test/blake2/key_test.rb

43 lines
1.2 KiB
Ruby
Raw Normal View History

2018-05-29 18:21:53 -04:00
require 'test_helper'
class KeyTest < MiniTest::Test
def test_none
2018-05-29 21:46:07 -04:00
key = Blake2b::Key.none
2018-05-29 18:21:53 -04:00
assert_equal [], key.bytes
end
def test_from_string
2018-05-29 21:46:07 -04:00
key = Blake2b::Key.from_string('foo bar baz')
2018-05-29 18:21:53 -04:00
assert_equal [102, 111, 111, 32, 98, 97, 114, 32, 98, 97, 122], key.bytes
end
def test_from_string_raises_on_non_ascii_string
2018-05-29 21:46:07 -04:00
assert_raises(ArgumentError) { Blake2b::Key.from_string('💩') }
2018-05-29 18:21:53 -04:00
end
def test_from_hex
2018-05-29 21:46:07 -04:00
key = Blake2b::Key.from_hex('DEADBEAF')
2018-05-29 18:21:53 -04:00
assert_equal [222, 173, 190, 175], key.bytes
end
def test_from_hex_raises_on_non_hex_string
2018-05-29 21:46:07 -04:00
assert_raises(ArgumentError) { Blake2b::Key.from_hex('DEADBEAFZZ') }
2018-05-29 18:21:53 -04:00
end
def test_from_bytes_hex
2018-05-29 21:46:07 -04:00
key = Blake2b::Key.from_bytes([0xDE, 0xAD, 0xBE, 0xAF])
2018-05-29 18:21:53 -04:00
assert_equal [222, 173, 190, 175], key.bytes
end
def test_from_bytes_int
2018-05-29 21:46:07 -04:00
key = Blake2b::Key.from_bytes([222, 173, 190, 175])
2018-05-29 18:21:53 -04:00
assert_equal [222, 173, 190, 175], key.bytes
end
def test_from_hex_raises_on_non_valid_byte_array
2018-05-29 21:46:07 -04:00
assert_raises(ArgumentError) { Blake2b::Key.from_bytes([-1]) }
assert_raises(ArgumentError) { Blake2b::Key.from_bytes([256]) }
assert_raises(ArgumentError) { Blake2b::Key.from_bytes(['foo']) }
2018-05-29 18:21:53 -04:00
end
end