Files
gmserialization/asn1/detect_demo.erl
T
Ulf Wiger 6d7ab1e4ad
Gajumaru Serialization Tests / tests (push) Successful in 10s
PoC: ASN.1 / DER serialization experiment
This branch contains a proof-of-concept exploration of representing
the RLP (gmser_rlp) and gmserialization layers using ASN.1 with
DER encoding.

Goals of the experiment:
- Model the static serialization templates and dynamic types in ASN.1.
- Demonstrate reliable detection of legacy RLP data vs. new DER data
  (first byte >= 0xC0 for RLP lists vs. 0x30 for DER SEQUENCE).
- Evaluate wire-size overhead of standard DER TLV encoding compared
  to the extremely compact RLP prefix encoding.
- Verify that the DER path produces deterministic output suitable
  for hashing (idempotent serialization).

Key files:
- GajumaruSerialization.asn   -- the ASN.1 schema
- GajumaruSerialization.{erl,hrl} -- generated encoder/decoder
- detect_demo.erl, size_comparison.erl -- supporting test code

Findings (high level):
- Detection via first byte works cleanly.
- DER is fully deterministic for hashing when the same value is given.
- Small objects pay a significant size overhead (often 3-6x) due to
  TLV tags/lengths and field names in the generic path.
- Concrete SEQUENCE definitions are much more compact than the
  generic templateFields representation.
- Large payloads have acceptable relative overhead.

This is NOT production code. It was created to answer feasibility
questions around ASN.1 modeling, format detection, determinism,
and size characteristics.

Branch created from uw-new-acs for isolated experimentation.
2026-07-07 10:05:30 +02:00

28 lines
1016 B
Erlang

-module(detect_demo).
-export([run/0]).
run() ->
application:ensure_all_started(gmserialization),
code:add_path("asn1"),
Sample = {'GajumaruData', 10, 1,
{templateFields, [
{'TemplateField', <<"foo">>, {intValue, 42}},
{'TemplateField', <<"bar">>, {binaryValue, <<"hello">>}}
]}},
{ok, Der} = 'GajumaruSerialization':encode('GajumaruData', Sample),
io:format("DER first byte: ~p (0x~2.16.0B)~n", [binary:at(Der,0), binary:at(Der,0)]),
{ok, _Dec} = 'GajumaruSerialization':decode('GajumaruData', Der),
io:format("DER roundtrip OK~n"),
Legacy = gmser_chain_objects:serialize(account, 1,
[{foo,int},{bar,binary}],
[{foo,42},{bar,<<"hello">>}]),
<<L0>> = binary:part(Legacy,0,1),
<<D0>> = binary:part(Der,0,1),
io:format("Legacy 0x~2.16.0B (>= 0xC0 -> legacy: ~p)~n", [L0, L0 >= 16#C0]),
io:format("DER 0x~2.16.0B (< 0xC0 -> new DER: ~p)~n", [D0, D0 < 16#C0]),
ok.