PHP code example of twarimitswe-aaron / gatekeeper-cdr

1. Go to this page and download the library: Download twarimitswe-aaron/gatekeeper-cdr library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

twarimitswe-aaron / gatekeeper-cdr example snippets



// Install:
//   Add the compiled libgatekeeper.so to your php.ini:
//   extension=/path/to/gatekeeper_cdr.so
//
//   Or via Composer (planned):
//   composer n";

// --- Sanitize (Dual-Output ABI returns both Native and PNG formats) ---
$result = gatekeeper_disarm($raw);

file_put_contents('clean.' . strtolower($result['output_format']), $result['buffer']);

if (!empty($result['png_buffer'])) {
    file_put_contents('clean_zerotrust.png', $result['png_buffer']);
}

echo "Sanitized: {$result['original_size_bytes']} bytes -> {$result['final_size_bytes']} bytes\n";
rust
pub enum CdrError {
    PayloadTooShort      { got: usize },
    PayloadTooLarge      { got: usize, limit: usize },
    UnknownFormat        { magic: [u8; 4] },
    JpegMissingEoi,
    PngMissingIhdr,
    JpegDecodeFailed     { source: zune_jpeg::errors::DecodeErrors },
    PngDecodeFailed      { source: png::DecodingError },
    GifDecodeFailed      { source: gif::DecodingError },
    MissingImageInfo,
    DegenerateDimensions { width: u32, height: u32 },
    DimensionTooLarge    { dimension: u32, limit: u32 },
    ImageTooLarge        { bytes: usize, limit: usize },
    PixelBufferMismatch  { expected: usize, got: usize },
    PngEncodeFailed      { source: png::EncodingError },
    GifEncodeFailed      { source: gif::EncodingError },
    Unimplemented        { format: &'static str },  // stub — fails closed
}