Skip to main content

LENS v3.2 – Hardened reference implementation for a custom binary data format

Project description

LENS v3.1 – Hardened Reference Implementation

LENS (Lightweight Efficient Network Serialization) is a binary serialization format designed for high performance, type safety, and resilience. This implementation focuses on security hardening to protect against common binary exploitation vectors.

Features (v3.1)

Efficient Encoding: Uses Varints and ZigZag encoding for compact integer storage.

Symbol Tables: Optimized for objects by storing keys in a centralized table to avoid redundancy.

Hardened Security:

Zip-Bomb Protection: Decompression is capped at a strict 512 MB limit.

Trailing Garbage Detection: Rejects payloads with extra data after the valid end-of-file.

Recursion Depth Control: Prevents Stack Overflow attacks (max 500 levels).

Integrity Checks: Built-in CRC32 checksum verification for every frame.

Rich Types: Supports null, bool, int, float, string, bytes, datetime (UTC), arrays, and objects.

Installation

pip install lens-format

Usage

The library is designed to be a drop-in replacement for logic where JSON might be too bulky or insecure.

Basic API

from lens_format import LensFormat, LensError, LensDecodeError
from datetime import datetime

data = {
    "server": "production-01",
    "uptime": 1234567,
    "active": True,
    "last_sync": datetime.utcnow()
}

try:
    # Encoding to binary
    # Set compress=True to enable zlib compression with safety limits
    binary_payload = LensFormat.encode(data, compress=True)

    # Decoding back to Python objects
    parsed_data = LensFormat.decode(binary_payload)
    print(f"Server: {parsed_data['server']}")
    
except LensDecodeError as e:
    print(f"Validation or decoding failed: {e}")
except LensError as e:
    print(f"A general LENS error occurred: {e}")
Exception Hierarchy

LENS provides specific exceptions to help you handle edge cases safely:

  • LensError: The base class for all exceptions.

  • LensDecodeError: Raised if the binary data is malformed, has unexpected EOF, or contains trailing garbage.

  • LensIntegrityError: A subclass of LensDecodeError raised when the CRC32 checksum doesn't match.

LensTypeError: Raised during encoding if a value type is not supported.

Technical Specifications

  • Magic Header: LENS (4 bytes)

  • Version: 31 (v3.1)

  • Safety Limits:

  • Max String/Bytes: 64 MB

  • Max Array/Object Size: 1,000,000 elements

  • Max Symbols: 250,000

  • Max Decompressed Payload: 512 MB

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lens_format-3.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lens_format-3.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file lens_format-3.2.0.tar.gz.

File metadata

  • Download URL: lens_format-3.2.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for lens_format-3.2.0.tar.gz
Algorithm Hash digest
SHA256 44c56d7ea9a69294915b15adc56828163da390f6fd1eaaccbe857a43c9fbd966
MD5 97937ad098d2242fb1139aefb0e976b1
BLAKE2b-256 c9072defbc1cb1d15219af312e620adb9a37e1eedbb9f4480aae350bde7bf464

See more details on using hashes here.

File details

Details for the file lens_format-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: lens_format-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.1

File hashes

Hashes for lens_format-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7596a6b2f36aee639a1e6005e890695f217b413db9760a19b37c3184f323d1f2
MD5 d9a16285217986c8564fe50df131f2a8
BLAKE2b-256 065ac21545eea64bd3f0165605041d989b9bcb043358ca3959aa1e14c7e7e242

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page