@@ -42,16 +42,38 @@ mod tests {
4242 }
4343
4444 #[ test]
45- fn test_verify ( ) {
46- let empty_hash = "blake3:af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262" ;
47- let hello_hash = "blake3:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24" ;
45+ fn test_verify_happy_path ( ) {
46+ let data = b"hello world" ;
47+ let expected = "blake3:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24" ;
48+ assert ! ( verify( data, expected) ) ;
49+ }
50+
51+ #[ test]
52+ fn test_verify_modified_data ( ) {
53+ let data = b"hello world!" ; // extra char
54+ let expected = "blake3:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24" ; // hash of "hello world"
55+ assert ! ( !verify( data, expected) ) ;
56+ }
57+
58+ #[ test]
59+ fn test_verify_invalid_prefix ( ) {
60+ let data = b"hello world" ;
61+ // same hash value, different prefix
62+ let expected = "sha256:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24" ;
63+ assert ! ( !verify( data, expected) ) ;
64+ }
4865
49- assert ! ( verify( b"" , empty_hash) ) ;
50- assert ! ( verify( b"hello world" , hello_hash) ) ;
66+ #[ test]
67+ fn test_verify_wrong_length_hash ( ) {
68+ let data = b"hello world" ;
69+ let expected = "blake3:d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e" ; // truncated
70+ assert ! ( !verify( data, expected) ) ;
71+ }
5172
52- // Negative test cases
53- assert ! ( !verify( b"hello world" , empty_hash) ) ;
54- assert ! ( !verify( b"" , hello_hash) ) ;
55- assert ! ( !verify( b"hello world" , "blake3:invalid" ) ) ;
73+ #[ test]
74+ fn test_verify_empty_string ( ) {
75+ let data = b"" ;
76+ let expected = "blake3:af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262" ;
77+ assert ! ( verify( data, expected) ) ;
5678 }
5779}
0 commit comments