photodna-sys
Low-level, unsafe FFI bindings to the Microsoft PhotoDNA Edge Hash Generator library.
Overview
This crate provides raw Rust bindings to the proprietary Microsoft PhotoDNA library, which computes perceptual hashes of images for content identification purposes. PhotoDNA is commonly used by organizations to detect known illegal content.
Note: This crate only provides the FFI bindings. You must obtain the PhotoDNA SDK separately from Microsoft.
Requirements
PhotoDNA SDK
This crate requires the proprietary Microsoft PhotoDNA Edge Hash Generator SDK (version 1.05.001). Contact Microsoft to obtain a license and the SDK files.
Set the PHOTODNA_SDK_ROOT environment variable to point to the SDK installation:
Expected directory structure:
$PHOTODNA_SDK_ROOT/
├── clientlibrary/
│ ├── libEdgeHashGenerator.so.1.05 # Linux x86_64
│ ├── libEdgeHashGenerator-arm64.so.1.05 # Linux ARM64
│ ├── libEdgeHashGenerator-macos.so.1.05 # macOS x86_64
│ ├── libEdgeHashGenerator-arm64-macos.so.1.05 # macOS ARM64
│ ├── c/
│ │ └── PhotoDnaEdgeHashGenerator.h
│ └── ...
└── webassembly/
└── photoDnaEdgeHash.wasm # For BSD platforms
Build Dependencies
- Rust 1.70 or later
- For the
bindgenfeature: LLVM/Clang development headers
Platform Support
| Platform | Architecture | Support |
|---|---|---|
| Windows | x86_64, x86, ARM64 | Native library |
| Linux | x86_64, x86, ARM64 | Native library |
| macOS | x86_64, ARM64 | Native library |
| OpenBSD | any | WebAssembly (requires wasm feature) |
| FreeBSD | any | WebAssembly (requires wasm feature) |
Features
native(default): Links against native dynamic libraries (.dll/.so).wasm: Embeds the WebAssembly module for platforms without native library support.bindgen: Regenerates bindings from C headers at build time (requires clang).
Usage
Add to your Cargo.toml:
[]
= "1.5"
Example
use *;
use CString;
BSD / WebAssembly Usage
On BSD platforms, use a WASM runtime to execute the PhotoDNA module:
Safety
All FFI functions in this crate are unsafe. Callers must ensure:
- The library has been properly initialized via
EdgeHashGeneratorInit. - All pointers passed to functions are valid and point to sufficient memory.
- Image data buffers match the specified dimensions, stride, and pixel format.
- The library instance is not used after
EdgeHashGeneratorReleaseis called.
Error Handling
Functions return negative error codes on failure. Use error_code_description()
to get a human-readable description:
use ;
let description = error_code_description;
assert_eq!;
Version Compatibility
| Crate Version | SDK Version |
|---|---|
| 1.5.x | 1.05.001 |
License
The Rust bindings in this crate are provided under the MIT license. However, the PhotoDNA library itself is proprietary software owned by Microsoft. You must obtain a separate license from Microsoft to use the PhotoDNA SDK.
Related Projects
- photodna - Safe, high-level wrapper