aka: the ISIM application of a card, its identity files and the identity they hold

An ISIM holds the parameters a registration starts from (TS 24.229
5.1.1.1A): the private identity in EF_IMPI, the home domain in
EF_DOMAIN and public identities in EF_IMPU (TS 31.103 4.2.2 to 4.2.4),
of which the first record's is the one to register (GSMA IR.92 2.2.1).
TS 23.003 has a UE derive its home domain and a temporary public
identity from the IMSI "if there is no ISIM application" (13.2, 13.4B);
those derived names are the only ones imsd has. This is the part of
reading an ISIM that has no I/O; the daemon does not use it yet.

ParseIsimApp finds the ISIM application of one slot in qmicli's card
status, in whatever state the modem lists it. On the two cards with an
ISIM that a read-only probe read (a US card, 2026-11-23, and a
Norwegian one, 2026-11-21) the Fairphone 6's modem lists the ISIM
`detected` beside the `ready` USIM, and on both a logical channel
opened on it and its identity files were read.

The commands are the ones that probe sent: SELECT by file identifier,
READ BINARY, READ RECORD (TS 102 221 11.1.1, 11.1.3, 11.1.5).
ApduAnswer is a card's answer, '90 00', '91 XX' and '92 XX' its normal
endings (10.2.1.1), and ApduFollowUp the command it asks for next when
the answer brought no data: GET RESPONSE for '61 XX', a command without
data again with the length named for '6C XX' (7.3.1.1.5); an answer
with data is taken for the command's last. HoldsRead takes a read's
data under the warning '62 82' as well (10.2.1.3). ParseIsimValue takes
the value of the data object with tag '80' that a file begins with,
cuts 'FF' bytes from the end of its length as the probe does, and gives
none for a value with a blank or a byte that is not printable ASCII.
IsimIdentity checks the three values before they replace the derived
names: they are written into a quoted string and between the angle
brackets of SIP header fields. It refuses a value with a quote, a
backslash, an angle bracket, a blank, a line break or another byte
outside printable ASCII, a private or a public identity of more than
255 characters, a private identity without an @ between two parts, a
domain that is not labels of letters, digits and inner hyphens, 63
characters a label and 253 in all at most, and a public identity that
does not begin sip: or is that alone.

The two readers of the card status share how they read a line;
ParseCardStatus gives what it gave.

Tested: tests/Aka (the application out of a card status with the US
card's two applications, in either order, and out of a second slot with
the Norwegian card's AID; the commands, the answers and their
follow-ups, the values, the identity and what is refused) and
tests/Messages (the two REGISTERs of an ISIM's identity against the
pinned ones).
This commit is contained in:
Jorijn van der Graaf 2026-11-23 19:32:58 +01:00
commit 3754687b0d
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
4 changed files with 653 additions and 46 deletions

View file

@ -4,6 +4,10 @@
// Imsd:Aka unit tests — the AKAv1-MD5 digest against a vector cross-computed
// with the Python reference, identity assembly, the qmicli/mmcli text
// parsers (fed real device output), and the AUTHENTICATE APDU build/parse.
// Then the ISIM (since 1.2.3): the application of the slot in use out of a
// card status, the commands its files are read with, a card's answer and
// the command it asks for next, the value an identity file holds, and the
// check of the three values before they are an identity.
import std;
import Imsd;
@ -36,6 +40,69 @@ namespace {
"\t\t\tA0:00:00:00:87:10:02:FF:31:F0:04:89:0E:00:00:01\n"
"\t\tPIN1 state: 'disabled'\n";
// A card with a USIM and an ISIM in one slot. The two applications,
// their states and their AIDs are those the fp6 journal's probe read off
// a reporter's card on 2026-11-23 (the modem lists the ISIM `detected`
// beside the `ready` USIM); the lines are the ones qmicli prints for an
// application, as in the fixture above: the probe prints its own listing
// of a card, not qmicli's.
constexpr std::string_view CardStatusIsim =
"[qrtr://0] Successfully got card status\n"
"Provisioning applications:\n"
"\tPrimary GW: slot '1', application '1'\n"
"Slot [1]:\n"
"\tCard state: 'present'\n"
"\tUPIN state: 'not-initialized'\n"
"\tApplication [1]:\n"
"\t\tApplication type: 'usim (2)'\n"
"\t\tApplication state: 'ready'\n"
"\t\tApplication ID:\n"
"\t\t\tA0:00:00:00:87:10:02:FF:FF:FF:FF:89:03:02:00:00\n"
"\t\tPIN1 state: 'disabled'\n"
"\tApplication [2]:\n"
"\t\tApplication type: 'isim (5)'\n"
"\t\tApplication state: 'detected'\n"
"\t\tApplication ID:\n"
"\t\t\tA0:00:00:00:87:10:04:FF:FF:FF:FF:89:03:02:00:00\n"
"\t\tPIN1 state: 'disabled'\n"
"Slot [2]:\n"
"\tCard state: 'absent'\n";
// The same two applications with the ISIM listed first, and a second
// card in slot 2 that has an ISIM of its own (its AID the twelve bytes
// of the other card with an ISIM the probe read, 2026-11-21) beside a USIM
// that is not ready.
constexpr std::string_view CardStatusIsimFirst =
"Slot [1]:\n"
"\tCard state: 'present'\n"
"\tApplication [1]:\n"
"\t\tApplication type: 'isim (5)'\n"
"\t\tApplication state: 'detected'\n"
"\t\tApplication ID:\n"
"\t\t\tA0:00:00:00:87:10:04:FF:FF:FF:FF:89:03:02:00:00\n"
"\tApplication [2]:\n"
"\t\tApplication type: 'usim (2)'\n"
"\t\tApplication state: 'ready'\n"
"\t\tApplication ID:\n"
"\t\t\tA0:00:00:00:87:10:02:FF:FF:FF:FF:89:03:02:00:00\n"
"Slot [2]:\n"
"\tCard state: 'present'\n"
"\tApplication [1]:\n"
"\t\tApplication type: 'usim (2)'\n"
"\t\tApplication state: 'detected'\n"
"\t\tApplication ID:\n"
"\t\t\tA0:00:00:00:87:10:02:FF:49:FF:05:89\n"
"\tApplication [2]:\n"
"\t\tApplication type: 'isim (5)'\n"
"\t\tApplication state: 'ready'\n"
"\t\tApplication ID:\n"
"\t\t\ta0:00:00:00:87:10:04:ff:49:ff:05:89\n"
"\tApplication [3]:\n"
"\t\tApplication type: 'isim (5)'\n"
"\t\tApplication state: 'detected'\n"
"\t\tApplication ID:\n"
"\t\t\tA0:00:00:00:87:10:04:FF:49:FF:05:99\n";
constexpr std::string_view MmcliSim =
" Properties | active: yes\n"
" | imsi: 001010123456789\n"
@ -72,6 +139,10 @@ int main() {
Check(sel && sel->aid == "A0000000871002FF31F004890E000001", "AID uppercased, colons stripped");
}
Check(!ParseCardStatus("Slot [1]:\n\tCard state: 'absent'\n").has_value(), "no ready USIM -> nullopt");
{
auto odd = ParseCardStatus("Slot [2]:\n\tCard state: 'absent'\nSlot [x]:\n\tApplication [1]:\n\t\tApplication type: 'usim (2)'\n\t\tApplication state: 'ready'\n\t\tApplication ID:\n\t\t\tA0:00:00:00:87:10:02:FF\n");
Check(odd && odd->slot == 0, "a slot line whose number does not parse is slot 0, not the slot before it");
}
// ---- mmcli parsers
Check(ParsePrimarySimPath(" SIM | primary sim path: /org/freedesktop/ModemManager1/SIM/0\n") == "/org/freedesktop/ModemManager1/SIM/0", "primary sim path");
@ -126,6 +197,13 @@ int main() {
Check(r && r->res.size() == 8 && r->res[0] == 0xA0, "RES extracted");
Check(r && r->ck.size() == 16 && r->ck[0] == 0xC0, "CK extracted");
Check(r && r->ik.size() == 16 && r->ik[0] == 0xD0, "IK extracted");
// the same answer parted into its data and its status word
auto parted = ParseApduAnswer(body);
auto r2 = parted ? ParseAkaResponse(*parted) : std::nullopt;
Check(r2 && r2->res == r->res && r2->ck == r->ck && r2->ik == r->ik, "an ApduAnswer's AKA result is the raw answer's");
std::vector<std::uint8_t> refused = {0x69, 0x82};
auto no = ParseApduAnswer(refused);
Check(no && !ParseAkaResponse(*no).has_value(), "a status word alone is no AKA result");
}
{
// sync-failure tag (0xDC) or truncated body -> nullopt
@ -158,6 +236,212 @@ int main() {
Check(!ParsePani(Zeros).has_value(), "PANI all-zero cell rejected");
}
// ---- the ISIM application of the slot in use
{
auto sel = ParseCardStatus(CardStatusIsim);
Check(sel && sel->slot == 1 && sel->aid == "A0000000871002FFFFFFFF8903020000", "the ready USIM beside an ISIM is still the USIM read");
auto isim = ParseIsimApp(CardStatusIsim, 1);
Check(isim.has_value(), "the ISIM of slot 1 is found");
Check(isim && isim->aid == "A0000000871004FFFFFFFF8903020000", "its AID, uppercase, colons stripped");
Check(isim && isim->state == "detected", "its state is the modem's word, detected");
Check(!ParseIsimApp(CardStatusIsim, 2).has_value(), "an absent card in the slot asked for: no ISIM");
Check(!ParseIsimApp(CardStatus, 2).has_value(), "a card with a USIM only: no ISIM");
Check(!ParseIsimApp(CardStatus, 1).has_value(), "a slot with no card: no ISIM");
Check(!ParseIsimApp("", 1).has_value(), "no card status: no ISIM");
}
{
auto sel = ParseCardStatus(CardStatusIsimFirst);
Check(sel && sel->slot == 1 && sel->aid == "A0000000871002FFFFFFFF8903020000", "the USIM listed after an ISIM is read");
auto first = ParseIsimApp(CardStatusIsimFirst, 1);
Check(first && first->aid == "A0000000871004FFFFFFFF8903020000" && first->state == "detected", "the ISIM listed before the USIM is found");
// slot 2's ISIM is not slot 1's: each slot's reader gets its own card's
auto other = ParseIsimApp(CardStatusIsimFirst, 2);
Check(other && other->aid == "A0000000871004FF49FF0589", "the other slot's ISIM for the other slot: a twelve-byte AID, lower case made upper");
Check(other && other->state == "ready", "its state, ready");
Check(first && other && first->aid != other->aid, "slot 1 is not answered with slot 2's ISIM");
Check(!ParseIsimApp(CardStatusIsimFirst, 3).has_value(), "a slot the status does not list: no ISIM");
}
{
// an application of another type keeps its AID to itself, and an
// ISIM whose state line is missing is found with no state
auto none = ParseIsimApp("Slot [1]:\n\tApplication [1]:\n\t\tApplication type: 'csim (4)'\n\t\tApplication state: 'detected'\n\t\tApplication ID:\n\t\t\tA0:00:00:03:43:10:02:FF\n", 1);
Check(!none.has_value(), "a CSIM is no ISIM");
auto bare = ParseIsimApp("Slot [1]:\n\tApplication [1]:\n\t\tApplication type: 'isim (5)'\n\t\tApplication ID:\n\t\t\tA0:00:00:00:87:10:04:FF\n", 1);
Check(bare && bare->aid == "A0000000871004FF" && bare->state.empty(), "an ISIM without a state line: found, the state empty");
// the state of the application before it is not taken for the ISIM's
auto after = ParseIsimApp("Slot [1]:\n\tApplication [1]:\n\t\tApplication type: 'usim (2)'\n\t\tApplication state: 'ready'\n\t\tApplication ID:\n\t\t\tA0:00:00:00:87:10:02:FF\n\tApplication [2]:\n\t\tApplication type: 'isim (5)'\n\t\tApplication ID:\n\t\t\tA0:00:00:00:87:10:04:FF\n", 1);
Check(after && after->state.empty(), "the USIM's state is not the ISIM's");
}
// ---- the commands a file of the selected application is read with
Check(EfImpi == 0x6F02 && EfDomain == 0x6F03 && EfImpu == 0x6F04, "the three identity files' identifiers (TS 31.103 4.2.2 to 4.2.4)");
Check(BuildSelectFileApdu(1, EfImpi) == "01a40004026f02", "SELECT EF_IMPI on channel 1");
Check(BuildSelectFileApdu(5, EfDomain) == "41a40004026f03", "SELECT EF_DOMAIN on channel 5: the extended class byte");
Check(BuildSelectFileApdu(2, 0x00AD) == "02a400040200ad", "a file identifier below 1000 keeps its four digits");
Check(BuildReadBinaryApdu(1) == "01b0000000", "READ BINARY from offset 0, Le 00");
Check(BuildReadBinaryApdu(4) == "40b0000000", "READ BINARY on channel 4");
Check(BuildReadRecordApdu(1, 1) == "01b2010400", "READ RECORD 1, absolute, Le 00");
Check(BuildReadRecordApdu(6, 2) == "42b2020400", "READ RECORD 2 on channel 6");
// ---- a card's answer, and the command it asks for next
{
std::vector<std::uint8_t> offer = {0x61, 0x19};
auto a = ParseApduAnswer(offer);
Check(a && a->data.empty() && a->sw1 == 0x61 && a->sw2 == 0x19, "61 19: no data, the status word");
Check(a && !a->Ok() && a->Status() == "6119", "61 19 is not 90 00; written 6119");
Check(a && Selected(*a), "a SELECT answered 61 XX has selected the file");
Check(a && ApduFollowUp(1, "01a40004026f02", *a) == "01c0000019", "61 19 asks for GET RESPONSE with Le 19");
Check(a && ApduFollowUp(5, "41b0000000", *a) == "41c0000019", "GET RESPONSE on the command's channel");
std::vector<std::uint8_t> data = {0x80, 0x03, 'a', '.', 'b', 0x90, 0x00};
auto d = ParseApduAnswer(data);
Check(d && d->data.size() == 5 && d->data[0] == 0x80 && d->data[4] == 'b', "data before 90 00 is the answer's data");
Check(d && d->Ok() && d->Status() == "9000" && Selected(*d), "90 00 is Ok");
Check(d && !ApduFollowUp(1, "01b0000000", *d).has_value(), "90 00 with data asks for nothing");
std::vector<std::uint8_t> len = {0x6C, 0x23};
auto l = ParseApduAnswer(len);
Check(l && ApduFollowUp(1, "01b0000000", *l) == "01b0000023", "6C 23 to READ BINARY: the command again with Le 23");
Check(l && ApduFollowUp(4, "40b2010400", *l) == "40b2010423", "6C 23 to READ RECORD: the command again with Le 23");
Check(l && !ApduFollowUp(1, "0188008122" "10" "11111111111111111111111111111111" "10" "22222222222222222222222222222222", *l).has_value(), "6C XX to a command that carries data: nothing to send again");
Check(l && !Selected(*l), "6C XX is no selected file");
std::vector<std::uint8_t> missing = {0x6A, 0x82};
auto m = ParseApduAnswer(missing);
Check(m && m->Status() == "6a82" && !m->Ok() && !Selected(*m), "6A 82: file not found, nothing selected");
Check(m && !ApduFollowUp(1, "01a40004026f09", *m).has_value(), "an error asks for nothing");
std::vector<std::uint8_t> more = {0x80, 0x01, 'a', 0x61, 0x05};
auto w = ParseApduAnswer(more);
Check(w && !ApduFollowUp(1, "01b0000000", *w).has_value(), "data with 61 XX is not followed");
std::vector<std::uint8_t> one = {0x90};
Check(!ParseApduAnswer(one).has_value(), "one byte is no answer");
Check(!ParseApduAnswer({}).has_value(), "no bytes is no answer");
std::vector<std::uint8_t> sw = {0x90, 0x00};
auto e = ParseApduAnswer(sw);
Check(e && e->data.empty() && e->Ok(), "90 00 alone: Ok, no data");
// a card with a proactive command waiting ends a command 91 XX, one
// with a data transfer session going on 92 XX
std::vector<std::uint8_t> proactive = {0x80, 0x03, 'a', '.', 'b', 0x91, 0x0B};
auto p = ParseApduAnswer(proactive);
Check(p && p->Ok() && Selected(*p) && HoldsRead(*p) && p->data.size() == 5, "91 XX is a normal ending");
std::vector<std::uint8_t> transfer = {0x80, 0x03, 'a', '.', 'b', 0x92, 0x10};
auto x = ParseApduAnswer(transfer);
Check(x && x->Ok() && Selected(*x) && HoldsRead(*x), "92 XX is a normal ending");
std::vector<std::uint8_t> n9001 = {0x90, 0x01}, n9300 = {0x93, 0x00};
Check(!ParseApduAnswer(n9001)->Ok(), "90 01 is no normal ending");
Check(!ParseApduAnswer(n9300)->Ok(), "93 00 is no normal ending");
// a read may end 62 82 with all the file holds
std::vector<std::uint8_t> eof = {0x80, 0x03, 'a', '.', 'b', 0x62, 0x82};
auto f = ParseApduAnswer(eof);
Check(f && !f->Ok() && HoldsRead(*f) && !Selected(*f), "data under 62 82 is what a read holds, and no normal ending");
Check(d && HoldsRead(*d), "data under 90 00 is what a read holds");
std::vector<std::uint8_t> bare6282 = {0x62, 0x82}, d6281 = {0x80, 0x01, 'a', 0x62, 0x81}, d6382 = {0x80, 0x01, 'a', 0x63, 0x82};
Check(!HoldsRead(*ParseApduAnswer(bare6282)), "62 82 without data holds nothing");
Check(!HoldsRead(*ParseApduAnswer(d6281)), "data under 62 81 is not taken");
Check(!HoldsRead(*ParseApduAnswer(d6382)), "data under 63 82 is not taken");
Check(m && !HoldsRead(*m), "6A 82 holds nothing");
}
// ---- the value an ISIM identity file holds (the data object with tag 80)
{
auto bytes = [](std::initializer_list<std::uint8_t> head, std::string_view text, std::size_t pad) {
std::vector<std::uint8_t> v(head);
v.insert(v.end(), text.begin(), text.end());
v.insert(v.end(), pad, 0xFF);
return v;
};
Check(ParseIsimValue(bytes({0x80, 0x0F}, "ims.example.net", 17)) == "ims.example.net", "the value of the object, the file's FF padding after it not read");
Check(ParseIsimValue(bytes({0x80, 0x0F}, "ims.example.net", 0)) == "ims.example.net", "the value with nothing after it");
Check(ParseIsimValue(bytes({0x80, 0x81, 0x0F}, "ims.example.net", 3)) == "ims.example.net", "a length in the 81 form");
Check(ParseIsimValue(bytes({0x80, 0x82, 0x00, 0x0F}, "ims.example.net", 3)) == "ims.example.net", "a length in the 82 form");
Check(ParseIsimValue(bytes({0x80, 0x23}, "001010123456789@private.example.net", 29)) == "001010123456789@private.example.net", "a private identity");
Check(ParseIsimValue(bytes({0x80, 0x22}, "sip:001010123456789@ims.example.net", 30)) == "sip:001010123456789@ims.example.ne", "the length decides, not the bytes that follow");
std::vector<std::uint8_t> unused(64, 0xFF);
Check(!ParseIsimValue(unused).has_value(), "an unused record, all FF: no value");
Check(!ParseIsimValue(bytes({0x81, 0x0F}, "ims.example.net", 0)).has_value(), "another tag: no value");
Check(!ParseIsimValue(bytes({0x80, 0x10}, "ims.example.net", 0)).has_value(), "a length past the data: no value");
Check(!ParseIsimValue(bytes({0x80, 0x00}, "", 4)).has_value(), "a length of zero: no value");
Check(!ParseIsimValue(bytes({0x80, 0x83, 0x00, 0x00, 0x0F}, "ims.example.net", 0)).has_value(), "a length form of three bytes: no value");
Check(!ParseIsimValue(bytes({0x80, 0x81}, "", 0)).has_value(), "an 81 form with no length byte: no value");
Check(!ParseIsimValue(bytes({0x80, 0x82, 0x00}, "", 0)).has_value(), "an 82 form cut short: no value");
Check(!ParseIsimValue(bytes({0x80}, "", 0)).has_value(), "the tag alone: no value");
Check(!ParseIsimValue({}).has_value(), "no bytes: no value");
Check(ParseIsimValue(bytes({0x80, 0x12}, "ims.example.net", 3)) == "ims.example.net", "FF at the end of the length are padding counted into it");
std::vector<std::uint8_t> ffInside = {0x80, 0x05, 'a', '.', 0xFF, '.', 'b'};
Check(!ParseIsimValue(ffInside).has_value(), "an FF before the value's end: no value");
std::vector<std::uint8_t> ffOnly = {0x80, 0x03, 0xFF, 0xFF, 0xFF, 0xFF};
Check(!ParseIsimValue(ffOnly).has_value(), "a length of nothing but FF: no value");
Check(!ParseIsimValue(bytes({0x80, 0x0F}, "ims example.net", 0)).has_value(), "a blank in the value: no value");
Check(!ParseIsimValue(bytes({0x80, 0x11}, "ims.example.net\r\n", 0)).has_value(), "a line break in the value: no value");
std::vector<std::uint8_t> nul = {0x80, 0x03, 'a', 0x00, 'b'};
Check(!ParseIsimValue(nul).has_value(), "a NUL in the value: no value");
std::vector<std::uint8_t> utf8 = {0x80, 0x03, 'a', 0xC3, 0xA9};
Check(!ParseIsimValue(utf8).has_value(), "a byte above ASCII in the value: no value");
}
// ---- the identity an ISIM holds
{
const Identity derived = MakeIdentity("001010123456789", "001", "01");
// names unlike the derived ones: a domain of the operator's own
auto id = IsimIdentity(derived, "001010123456789@private.example.net", "one.example.net", "sip:001010123456789@one.example.net");
Check(id.has_value(), "an ISIM's three values make an identity");
Check(id && id->impi == "001010123456789@private.example.net", "the private identity is the card's");
Check(id && id->domain == "one.example.net", "the home domain is the card's");
Check(id && id->impu == "sip:001010123456789@one.example.net", "the public identity is the card's");
Check(id && id->regUri == "sip:one.example.net", "the registration URI is that domain's");
Check(id && id->imsi == derived.imsi && id->mcc == derived.mcc && id->mnc == derived.mnc, "the IMSI and the operator stay");
// an ISIM that holds the names the IMSI gives: the same identity
auto same = IsimIdentity(derived, derived.impi, derived.domain, derived.impu);
Check(same && same->impi == derived.impi && same->domain == derived.domain && same->impu == derived.impu && same->regUri == derived.regUri, "the derived names from an ISIM give the derived identity");
// a public identity that is a number, a domain with a hyphen and digits
Check(IsimIdentity(derived, "user@realm.example", "ims-1.example.net", "sip:+15555550100@ims-1.example.net").has_value(), "a number as the public identity, a hyphen in the domain");
auto no = [&](std::string_view impi, std::string_view domain, std::string_view impu) { return !IsimIdentity(derived, impi, domain, impu).has_value(); };
const std::string_view P = "001010123456789@private.example.net", D = "one.example.net", U = "sip:001010123456789@one.example.net";
Check(no("001010123456789", D, U), "a private identity without a realm is refused");
Check(no("@private.example.net", D, U), "a private identity without a user is refused");
Check(no("001010123456789@", D, U), "a private identity that ends at the @ is refused");
Check(no("", D, U), "an empty private identity is refused");
Check(no("0010101\"23456789@private.example.net", D, U), "a quote in the private identity is refused (it stands in a quoted string)");
Check(no("001010123456789\\@private.example.net", D, U), "a backslash in the private identity is refused");
Check(no("001010123456789@private.example.net\r\nVia: x", D, U), "a line break in the private identity is refused");
Check(no("0010101 23456789@private.example.net", D, U), "a blank in the private identity is refused");
Check(no(P, "", U), "an empty domain is refused");
Check(no(P, "one.example.net>", U), "an angle bracket in the domain is refused");
Check(no(P, "one_example.net", U), "an underscore in the domain is refused");
Check(no(P, "one..example.net", U), "an empty label in the domain is refused");
Check(no(P, ".one.example.net", U), "a domain that begins with a dot is refused");
Check(no(P, "one.example.net.", U), "a domain that ends with a dot is refused");
Check(no(P, "-one.example.net", U), "a label that begins with a hyphen is refused");
Check(no(P, "one-.example.net", U), "a label that ends with a hyphen is refused");
Check(no(P, "one.example.net-", U), "a domain that ends with a hyphen is refused");
Check(no(P, "one.example.net:5060", U), "a port on the domain is refused");
Check(no(P, "one.example.net;lr", U), "a parameter on the domain is refused");
Check(no(P, "one.example.net\r\nRoute: <sip:x>", U), "a line break in the domain is refused");
Check(no(P, D, "tel:+15555550100"), "a tel: public identity is refused");
Check(no(P, D, "sip:"), "a public identity that is the scheme alone is refused");
Check(no(P, D, "001010123456789@one.example.net"), "a public identity without a scheme is refused");
Check(no(P, D, "sip:001010123456789@one.example.net>;tag=x"), "an angle bracket in the public identity is refused (it stands between two)");
Check(no(P, D, "sip:001010123456789@one.example.net<sip:x@y"), "an opening angle bracket in the public identity is refused");
Check(no(P, std::string(63, 'a') + "." + std::string(63, 'b') + "." + std::string(63, 'c') + "." + std::string(63, 'd'), U), "a domain of 255 characters is refused");
Check(!no(P, std::string(63, 'a') + "." + std::string(63, 'b') + "." + std::string(63, 'c') + "." + std::string(61, 'd'), U), "a domain of 253 characters is taken");
Check(no(P, std::string(63, 'a') + "." + std::string(63, 'b') + "." + std::string(63, 'c') + "." + std::string(62, 'd'), U), "a domain of 254 characters is refused");
Check(no(P, D, "sip:001010123456789@one.example.net\r\nTo: <sip:x>"), "a line break in the public identity is refused");
Check(no(P, D, "sip:0010101 23456789@one.example.net"), "a blank in the public identity is refused");
Check(no(P, D, "sip:us\xC3\xA9r@one.example.net"), "a byte above ASCII in the public identity is refused");
Check(no(P, std::string(64, 'a') + ".example.net", U), "a label of 64 characters in the domain is refused");
Check(!no(P, std::string(63, 'a') + ".example.net", U), "a label of 63 characters is taken");
Check(no(std::string(300, 'a') + "@x.example", D, U), "a private identity of 300 characters is refused");
Check(no(std::string(246, 'a') + "@x.example", D, U), "a private identity of 256 characters is refused");
Check(!no(std::string(245, 'a') + "@x.example", D, U), "a private identity of 255 characters is taken");
Check(no(P, D, "sip:" + std::string(252, 'a')), "a public identity of 256 characters is refused");
Check(!no(P, D, "sip:" + std::string(251, 'a')), "a public identity of 255 characters is taken");
}
if (Failures == 0) std::println("Aka: all tests passed");
return Failures != 0; // not the count: `crafter-build test` takes an exit status of 77 for a skipped suite, and an exit status keeps 8 bits
}