libfuzzy_sys/
lib.rs

1// ssdeep-rs: A Rust wrapper for ssdeep.
2//
3// Copyright (c) 2016 Petr Zemek <s3rvac@petrzemek.net>
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18//! Native bindings to the `libfuzzy` library, which is internally used by the
19//! [ssdeep-rs](https://github.com/s3rvac/ssdeep-rs) crate. See its description
20//! for more information.
21
22extern crate libc;
23
24use libc::c_char;
25use libc::c_int;
26use libc::c_uchar;
27
28// From fuzzy.h:
29
30/// Length of an individual fuzzy hash signature component.
31const SPAMSUM_LENGTH: usize = 64;
32
33/// The longest possible length for a fuzzy hash signature.
34pub const FUZZY_MAX_RESULT: usize = 2 * SPAMSUM_LENGTH + 20;
35
36extern "C" {
37    /// Computes the match score between two fuzzy hashes.
38    // int fuzzy_compare(const char *sig1, const char *sig2);
39    pub fn fuzzy_compare(sig1: *const c_char, sig2: *const c_char) -> c_int;
40
41    /// Computes the fuzzy hash of a buffer.
42    // int fuzzy_hash_buf(const unsigned char *buf, uint32_t buf_len, char *result);
43    pub fn fuzzy_hash_buf(buf: *const c_uchar, buf_len: u32, result: *mut c_char) -> c_int;
44
45    /// Computes the fuzzy hash of a file.
46    // int fuzzy_hash_filename(const char *filename, char *result);
47    pub fn fuzzy_hash_filename(filename: *const c_char, result: *mut c_char) -> c_int;
48}