Function ssdeep::compare
[−]
[src]
pub fn compare(hash1: &[u8], hash2: &[u8]) -> Option<i8>
Computes the match score between two fuzzy hashes.
Returns a value from 0 to 100 indicating the match score of the two hashes.
A match score of zero indicates that the hashes did not match. When an
error occurs, it returns None
.
Examples
When the hashes are identical, it returns 100:
let h1 = b"3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C"; let h2 = b"3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C"; assert_eq!(ssdeep::compare(h1, h2), Some(100));
When the hashes are similar, it returns a positive integer:
let h1 = b"3:AXGBicFlgVNhBGcL6wCrFQEv:AXGHsNhxLsr2C"; let h2 = b"3:AXGBicFlIHBGcL6wCrFQEv:AXGH6xLsr2Cx"; assert_eq!(ssdeep::compare(h1, h2), Some(22));
When the hashes have no similarity at all, it returns zero:
let h1 = b"3:u+N:u+N"; let h2 = b"3:OWIXTn:OWQ"; assert_eq!(ssdeep::compare(h1, h2), Some(0));
When either of the hashes is invalid, it returns None
:
let h1 = b"XYZ"; let h2 = b"3:tc:u"; assert_eq!(ssdeep::compare(h1, h2), None);
Panics
If either of the hashes contain a null byte. Note that
hash()
never returns a hash with a null byte, so this may
happen only if you handcrafted the hashes or obtained them from other
sources.
Implementation details
Internally, it calls the fuzzy_compare()
function from the underlying C
library. The return value -1
is translated into None
.