How ruitard/jsonsign works
Project Type & Purpose
• Type: A cross-platform C++ Command-Line Tool (CLI)
• Purpose: Sign and verify JSON files using RSA/ECDSA digital signatures, independent of JSON key ordering.
High-Level Components
A. CLI Frontend
• Source: cli/json_sign.cpp
• Uses: CLI11 for parsing commands (generate-key-pair, sign, verify).
B. Core Library (reusable modules in src/)
1. keycore.hpp / .cpp
• Key generation (RSA/ECDSA) interfaces
2. pk.cpp
• Sign & verify operations, wraps MbedTLS APIs
3. base64.cpp
• Encodes/decodes signatures to Base64 for embedding in JSON
4. helper.hpp
• JSON normalization (order-independent hashing) via nlohmann-json
C. External Dependencies
• MbedTLS (crypto primitives)
• nlohmann-json (JSON parsing/serialization)
• CLI11 (command-line interface)
D. Test Suite
• Source: test/
• Validates end-to-end signing/verifying, uses sample license.json.
E. Build System
• CMake scripts (CMakeLists.txt, cmake/) orchestrate targets, find dependencies, and configure vcpkg toolchain.
Interactions & Data Flows
• User → CLI Frontend:
• User invokes jsign sign or jsign verify.
• CLI11 parses flags (--key, --file) and routes to the correct command handler.
• CLI Frontend → Core Library:
• Calls generateKeyPair(), signJson(), or verifyJson().
• Core Library ↔ MbedTLS:
• keycore invokes RSA/ECDSA keygen, pk invokes sign/verify primitives.
• Core Library ↔ nlohmann-json:
• helper normalizes JSON (sorting, hashing), merges in signature field.
• Core Library → base64:
• Encodes raw signature bytes into the "|signature|" JSON field.
• Core Library → File System:
• Reads/writes JSON files and key files.
• Test Suite → Core Library & CLI:
• Executes commands in an isolated environment; asserts correct output.
Architectural Patterns & Principles
• Modularity: Clear separation between CLI layer and reusable signing library.
• Dependency Injection: Core library doesn’t know about CLI11; CLI imports only the public API.
• Single Responsibility: Each .cpp/.hpp in src/ handles one concern (crypto, JSON, encoding).
• Platform Abstraction: CMake + vcpkg ensure cross-platform build consistency.