ident: isolate non-system component of member

This enables more efficient representation in contexts inherently namespaced to the current system.

Signed-off-by: Yonah <contrib@gensokyo.uk>
This commit is contained in:
2026-03-22 17:28:52 +09:00
parent 87f59d0cf9
commit 22b8cc3884
3 changed files with 108 additions and 30 deletions

View File

@@ -9,6 +9,48 @@ import (
"git.gensokyo.uk/cofront/cof-spec/ident"
)
func TestPartM(t *testing.T) {
t.Parallel()
rTestCases[ident.PartM, *ident.PartM]{
{"short", ident.PartM{}, nil, &ident.UnexpectedSizeError{
Data: nil,
Want: ident.EncodedSizeMember - ident.EncodedSizeSystem,
}},
{"malformed", ident.PartM{}, []byte{
0xfe, 0xe1, 0xde, 0xad,
0xfe, 0xe1, 0xde, 0xad,
0xfe, 0xe1, 0xde, 0xad,
0xfe, 0xe1, 0xde, 0xad,
0xfe, 0xe1, 0xde, 0xad,
0xfe, 0xe1, 0xde, 0xad,
0xfe, 0xe1, 0xde, 0xad,
0xfe, 0xe1, 0xde, 0xad,
}, base64.CorruptInputError(0)},
{"newline", ident.PartM{}, []byte(
"AAAA" + strings.Repeat("\n", ident.EncodedSizeMember-ident.EncodedSizeSystem-4),
), ident.ErrNewline},
{"valid", ident.PartM{
Serial: 0xfdfdfdfdfdfdfdfd,
Time: uint64(time.Date(
0xfd, 7, 15,
23, 59, 59, 0xcab,
time.UTC,
).UnixNano()),
ID: 0x2e736e64,
}, base64.URLEncoding.AppendEncode(nil, []byte{
/* serial: */ 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
/* time: */ 0xab, 0x42, 0x42, 0xce, 0xf1, 0x92, 0x4a, 0x10,
/* id: */ 0x64, 0x6e, 0x73, 0x2e, 0, 0, 0, 0,
}), nil},
}.run(t)
}
func TestM(t *testing.T) {
t.Parallel()
@@ -43,15 +85,17 @@ func TestM(t *testing.T) {
), ident.ErrNewline},
{"valid", ident.M{
Serial: 0xfdfdfdfdfdfdfdfd,
PartM: ident.PartM{
Serial: 0xfdfdfdfdfdfdfdfd,
Time: uint64(time.Date(
0xfd, 7, 15,
23, 59, 59, 0xcab,
time.UTC,
).UnixNano()),
Time: uint64(time.Date(
0xfd, 7, 15,
23, 59, 59, 0xcab,
time.UTC,
).UnixNano()),
ID: 0x2e736e64,
ID: 0x2e736e64,
},
System: ident.S{
Site: ident.TrivialSite,