How ankraft/akasn1lib works
Project type and purpose
• AKASN1Lib is a C-level library (not a full-stack app or service) whose sole purpose is to encode and decode ASN.1 data using Basic Encoding Rules (BER).
• It provides per-type encoder/decoder modules for INTEGER, OCTETSTRING, NULL, OBJECTID, ENUMERATED, SEQUENCE/SET, all string classes, plus generic tag/length support and basic file I/O.
File structure
• Top-level:
• src/ – C code broken out by type (booldec.c, boolenc.c, …, tagdec.c, tagenc.c, writebuf.c, readbuf.c).
• src/*.h – Public headers (akasn1.h, vlARGS.h).
• test/ – a minimal test harness (test.c).
• doc/ – auto-generated Doxygen HTML docs.
• Makefile, LICENSE, README.md.
• Architectural patterns:
• Layered: public API ⟶ type‐specific encoders/decoders ⟶ shared tag/length routines ⟶ buffer I/O ⟶ file handling.
• Modular: each ASN.1 type lives in its own C module.
• Single‐process runtime, no network or external services.
Additional insights from README
• Library entry point: functions exposed in akasn1.h.
• Dependency: ANSI C99, no external libs.
• Limitations: primitive file handling, 32-bit values.
Main components and their interactions
a. Components
1. Public API layer (akasn1.h)
2. Type encoder modules (e.g. intenc.c, octenc.c, tagenc.c)
3. Type decoder modules (e.g. intdec.c, octdec.c, tagdec.c)
4. Tag & length support (taglenrd.c, tagwr.c, writebuf.c, readbuf.c)
5. File I/O layer (clfile.c, skipfile.c, asnfseek.c/asnftell.c)
6. Test harness (test.c)
7. Doxygen docs (doc/html)
b. Relationships & data flow
• Client app calls API → dispatch to specific encoder/decoder
• Encoder/decoder calls tag/length routines to write header
• Buffer routines manage in-memory buffers
• File I/O routines write/read to physical file
• Decoder pulls from file via readbuf & skipfile
c. Architectural patterns
• Layered, single‐address‐space library
• Module per data type for easy extensibility
• Shared utility modules (tag/length, buffers, file)
d. Technologies
• ANSI C (C99), Makefile for build
• Doxygen for docs
• MIT license
Diagramming recommendations
• Use clear labels for each component (e.g. “intenc.c – INTEGER Encoder”).
• API → Encoder/Decoder
• Encoder/Decoder → Tag/Length → Buffer → File I/O
• Decoder → Buffer → File I/O
• Green for encoders, yellow for decoders
• Gray for shared utilities
• Orange for file I/O
• Rectangles for modules