From 2219e752884db69b55c0554fb741487ec1e80953 Mon Sep 17 00:00:00 2001 From: Andres Toom Date: Tue, 7 Nov 2023 18:44:53 +0200 Subject: [PATCH] Improve the names of enum literals generated from IANA registries * The names are simplified by keeping only the first word of the original string. * When either (Deprecated) or (Obsolete) is contained in the original string, then add the respective prefix. * Update generated specifications * Update manually written specifications (tls_handshake.rflx) Ref. eng/recordflux/RecordFlux#1451 --- CHANGELOG.md | 1 + examples/specs/arp_parameters.rflx | 18 +++---- examples/specs/bootp_dhcp_parameters.rflx | 48 ++++++++--------- examples/specs/protocol_numbers.rflx | 10 ++-- examples/specs/tls_extensiontype_values.rflx | 8 +-- examples/specs/tls_handshake.rflx | 20 +++---- examples/specs/tls_parameters.rflx | 6 +-- rflx/converter/iana.py | 23 +++++++- tests/unit/converter_test.py | 56 ++++++++++++++++++++ 9 files changed, 134 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67f909e2c..e1bd73a78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Syntax for passing repeated `-i` and `-v` options to `rflx validate` (eng/recordflux/RecordFlux#1441) - Simplified setter code and removed internal `Successor` function (eng/recordflux/RecordFlux#1448) +- Improve the names of enum literals generated from IANA registries (eng/recordflux/RecordFlux#1451) ### Fixed diff --git a/examples/specs/arp_parameters.rflx b/examples/specs/arp_parameters.rflx index ad7e69f37..03a0ea330 100644 --- a/examples/specs/arp_parameters.rflx +++ b/examples/specs/arp_parameters.rflx @@ -1,5 +1,5 @@ -- AUTOMATICALLY GENERATED. DO NOT EDIT. --- Generation date: 2022-10-05 +-- Generation date: 2023-11-03 -- Address Resolution Protocol (ARP) Parameters -- Registry last updated on 2016-07-20 @@ -87,10 +87,10 @@ package Arp_Parameters is type Hardware_Types is (-- Ref: Jon_Postel - Ethernet_10Mb => 1, + Ethernet => 1, -- Ref: Jon_Postel - Experimental_Ethernet_3Mb => 2, + Experimental_Ethernet => 2, -- Ref: Philip_Koch Amateur_Radio_AX_25 => 3, @@ -120,7 +120,7 @@ package Arp_Parameters is LocalTalk => 11, -- xref = Joseph Murdock - LocalNet_IBM_PCNet_Or_SYTEK_LocalNET => 12, + LocalNet => 12, -- Ref: Rajiv_Dhingra Ultra_Link => 13, @@ -132,7 +132,7 @@ package Arp_Parameters is Frame_Relay => 15, -- xref = [JXB2] - Asynchronous_Transmission_Mode_ATM_16 => 16, + Asynchronous_Transmission_Mode_16 => 16, -- Ref: Jon_Postel HDLC => 17, @@ -141,13 +141,13 @@ package Arp_Parameters is Fibre_Channel => 18, -- Ref: rfc2225 - Asynchronous_Transmission_Mode_ATM_19 => 19, + Asynchronous_Transmission_Mode_19 => 19, -- Ref: Jon_Postel Serial_Line => 20, -- Ref: Mike_Burrows - Asynchronous_Transmission_Mode_ATM_21 => 21, + Asynchronous_Transmission_Mode_21 => 21, -- Ref: Herb_Jensen MIL_STD_188_220 => 22, @@ -181,11 +181,11 @@ package Arp_Parameters is IPsec_Tunnel => 31, -- Ref: rfc4391 - InfiniBand_TM => 32, + InfiniBand => 32, -- xref = Jeff Anderson, Telecommunications Industry of America (TIA) TR-8.5 -- Formulating Group, , June 2004 - TIA_102_Project_25_Common_Air_Interface_CAI => 33, + TIA_102_Project_25_Common_Air_Interface => 33, -- Ref: Scott_Guthery_2 Wiegand_Interface => 34, diff --git a/examples/specs/bootp_dhcp_parameters.rflx b/examples/specs/bootp_dhcp_parameters.rflx index eba88d8bd..3b7ab0ee8 100644 --- a/examples/specs/bootp_dhcp_parameters.rflx +++ b/examples/specs/bootp_dhcp_parameters.rflx @@ -1,6 +1,7 @@ -- AUTOMATICALLY GENERATED. DO NOT EDIT. --- Generation date: 2022-10-05 --- Dynamic Host Configuration Protocol (DHCP) and Bootstrap Protocol (BOOTP) Parameters +-- Generation date: 2023-11-03 +-- Dynamic Host Configuration Protocol (DHCP) and Bootstrap Protocol (BOOTP) +-- Parameters -- Registry last updated on 2021-01-15 package Bootp_Dhcp_Parameters is @@ -571,47 +572,46 @@ package Bootp_Dhcp_Parameters is V_I_Vendor_Specific_Information => 125, -- Ref: rfc4578 - -- alternative_name = PXE_Undefined_Vendor_Specific + -- alternative_name = PXE_Undefined -- alternative_name = Etherboot_Signature_6_Bytes_E4_45_74_68_00_00 -- alternative_name = DOCSIS_Full_Security_Server_IP_Address - -- alternative_name = TFTP_Server_IP_Address_For_IP_Phone_Software_Load + -- alternative_name = TFTP_Server_IP_Address BOOTP_Vendor_Extensions_And_DHCP_Options_128 => 128, -- Ref: rfc4578 - -- alternative_name = PXE_Undefined_Vendor_Specific + -- alternative_name = PXE_Undefined -- alternative_name = Kernel_Options_Variable_Length_String -- alternative_name = Call_Server_IP_Address BOOTP_Vendor_Extensions_And_DHCP_Options_129 => 129, -- Ref: rfc4578 - -- alternative_name = PXE_Undefined_Vendor_Specific + -- alternative_name = PXE_Undefined -- alternative_name = Ethernet_Interface_Variable_Length_String - -- alternative_name = Discrimination_String_To_Identify_Vendor + -- alternative_name = Discrimination_String BOOTP_Vendor_Extensions_And_DHCP_Options_130 => 130, -- Ref: rfc4578 - -- alternative_name = PXE_Undefined_Vendor_Specific + -- alternative_name = PXE_Undefined -- alternative_name = Remote_Statistics_Server_IP_Address BOOTP_Vendor_Extensions_And_DHCP_Options_131 => 131, -- Ref: rfc4578 - -- alternative_name = PXE_Undefined_Vendor_Specific + -- alternative_name = PXE_Undefined -- alternative_name = IEEE_802_1Q_VLAN_ID BOOTP_Vendor_Extensions_And_DHCP_Options_132 => 132, -- Ref: rfc4578 - -- alternative_name = PXE_Undefined_Vendor_Specific + -- alternative_name = PXE_Undefined -- alternative_name = IEEE_802_1D_P_Layer_2_Priority BOOTP_Vendor_Extensions_And_DHCP_Options_133 => 133, -- Ref: rfc4578 - -- alternative_name = PXE_Undefined_Vendor_Specific - -- alternative_name = - -- Diffserv_Code_Point_DSCP_For_VoIP_Signalling_And_Media_Streams + -- alternative_name = PXE_Undefined + -- alternative_name = Diffserv_Code_Point BOOTP_Vendor_Extensions_And_DHCP_Options_134 => 134, -- Ref: rfc4578 - -- alternative_name = PXE_Undefined_Vendor_Specific + -- alternative_name = PXE_Undefined -- alternative_name = HTTP_Proxy_For_Phone_Specific_Applications BOOTP_Vendor_Extensions_And_DHCP_Options_135 => 135, @@ -733,11 +733,11 @@ package Bootp_Dhcp_Parameters is -- description = Manufacturer Usage Descriptions -- Ref: rfc8520 OPTION_MUD_URL_V4 => 161, - Etherboot_Tentatively_Assigned_2005_06_23 => 175, - IP_Telephone_Tentatively_Assigned_2005_06_23 => 176, + Etherboot => 175, + IP_Telephone => 176, - -- alternative_name = Etherboot_Tentatively_Assigned_2005_06_23 - -- alternative_name = PacketCable_And_CableHome_Replaced_By_122 + -- alternative_name = Etherboot + -- alternative_name = PacketCable_And_CableHome BOOTP_Vendor_Extensions_And_DHCP_Options_177 => 177, -- length = 4 @@ -777,7 +777,7 @@ package Bootp_Dhcp_Parameters is Subnet_Allocation_Option => 220, -- Ref: rfc6607 - Virtual_Subnet_Selection_VSS_Option => 221, + Virtual_Subnet_Selection => 221, -- length = 0 -- description = None @@ -976,10 +976,10 @@ package Bootp_Dhcp_Parameters is Vertical_Datum_WGS_84_Defined_By_EPSG_CRS_Code_4327 => 1, -- Ref: rfc6225 - Vertical_Datum_NAD83_Defined_By_EPSG_CRS_Code_4269_With_North_American_Vertical_Datum_Of_1988_NAVD88 => 2, + Vertical_Datum_NAD83_Defined_By_EPSG_CRS_Code_4269_With_North_American_Vertical_Datum_Of_1988 => 2, -- Ref: rfc6225 - Vertical_Datum_NAD83_Defined_By_EPSG_CRS_Code_4269_With_Mean_Lower_Low_Water_MLLW_As_Associated_Vert_3 => 3) + Vertical_Datum_NAD83_Defined_By_EPSG_CRS_Code_4269_With_Mean_Lower_Low_Water => 3) with Size => 3; type GeoLoc_Option_Version_Registry is @@ -1065,7 +1065,7 @@ package Bootp_Dhcp_Parameters is DHCPv4_Delayed_Authentication => 1, -- Ref: rfc8415 - DHCPv6_Delayed_Authentication_Obsolete => 2, + Obsolete_DHCPv6_Delayed_Authentication => 2, -- Ref: rfc8415 DHCPv6_Reconfigure_Key_Authentication => 3) @@ -1094,14 +1094,14 @@ package Bootp_Dhcp_Parameters is type VSS_Type_Options is (-- Ref: rfc6607 - Network_Virtual_Terminal_NVT_ASCII_VPN_Identifier => 0, + Network_Virtual_Terminal => 0, -- Ref: rfc2685 -- Ref: rfc6607 RFC2685_VPN_ID => 1, -- Ref: rfc6926 - All_VPNs_Wildcard => 254, + All_VPNs => 254, -- Ref: rfc6607 Global_Default_VPN => 255) diff --git a/examples/specs/protocol_numbers.rflx b/examples/specs/protocol_numbers.rflx index 3473a9c6f..88aa5e98b 100644 --- a/examples/specs/protocol_numbers.rflx +++ b/examples/specs/protocol_numbers.rflx @@ -1,5 +1,5 @@ -- AUTOMATICALLY GENERATED. DO NOT EDIT. --- Generation date: 2022-10-05 +-- Generation date: 2023-11-03 -- Protocol Numbers -- Registry last updated on 2021-02-26 @@ -69,7 +69,7 @@ package Protocol_Numbers is -- description = ARGUS -- Ref: Robert_W_Scheifler - ARGUS_Deprecated => 13, + Deprecated_ARGUS => 13, -- description = EMCON -- xref = @@ -258,7 +258,7 @@ package Protocol_Numbers is -- description = IP with Encryption -- Ref: John_Ioannidis - SWIPE_Deprecated => 53, + Deprecated_SWIPE => 53, -- description = NBMA Address Resolution Protocol -- Ref: rfc1735 @@ -439,7 +439,7 @@ package Protocol_Numbers is -- description = Mobile Internetworking Control Pro. -- Ref: John_Ioannidis - MICP_Deprecated => 95, + Deprecated_MICP => 95, -- description = Semaphore Communications Sec. Pro. -- Ref: Howard_Hart @@ -550,7 +550,7 @@ package Protocol_Numbers is -- description = Simple Multicast Protocol -- Ref: Jon_Crowcroft -- Ref: draft-perlman-simple-multicast - SM_Deprecated => 122, + Deprecated_SM => 122, -- description = Performance Transparency Protocol -- Ref: Michael_Welzl diff --git a/examples/specs/tls_extensiontype_values.rflx b/examples/specs/tls_extensiontype_values.rflx index 3c7c2f10e..95c1ccb08 100644 --- a/examples/specs/tls_extensiontype_values.rflx +++ b/examples/specs/tls_extensiontype_values.rflx @@ -1,5 +1,5 @@ -- AUTOMATICALLY GENERATED. DO NOT EDIT. --- Generation date: 2023-09-10 +-- Generation date: 2023-11-03 -- Transport Layer Security (TLS) Extensions -- Registry last updated on 2023-07-13 @@ -74,7 +74,7 @@ package Tls_Extensiontype_Values is -- rec = Y -- Ref: rfc8422 -- Ref: rfc7919 - Supported_Groups_Renamed_From_Elliptic_Curves => 10, + Supported_Groups => 10, -- tls13 = - -- dtls-only = N @@ -225,7 +225,7 @@ package Tls_Extensiontype_Values is -- rec = Y -- Ref: rfc5077 -- Ref: rfc8447 - Session_Ticket_Renamed_From_SessionTicket_TLS => 35, + Session_Ticket => 35, -- tls13 = - -- dtls-only = N @@ -321,7 +321,7 @@ package Tls_Extensiontype_Values is -- dtls-only = Y -- rec = N -- Ref: rfc9146 - Connection_Id_Deprecated => 53, + Deprecated_Connection_Id => 53, -- tls13 = CH, SH -- dtls-only = Y diff --git a/examples/specs/tls_handshake.rflx b/examples/specs/tls_handshake.rflx index 31597a159..49fb6e9ca 100644 --- a/examples/specs/tls_handshake.rflx +++ b/examples/specs/tls_handshake.rflx @@ -120,12 +120,12 @@ package TLS_Handshake is Tag /= Tls_Extensiontype_Values::Token_Binding and Tag /= Tls_Extensiontype_Values::Cached_Info and Tag /= Tls_Extensiontype_Values::Tls_Lts and - Tag /= Tls_Extensiontype_Values::Session_Ticket_Renamed_From_SessionTicket_TLS and + Tag /= Tls_Extensiontype_Values::Session_Ticket and Tag /= Tls_Extensiontype_Values::TLMSP and Tag /= Tls_Extensiontype_Values::TLMSP_Proxying and Tag /= Tls_Extensiontype_Values::TLMSP_Delegate and Tag /= Tls_Extensiontype_Values::Oid_Filters and - Tag /= Tls_Extensiontype_Values::Connection_Id_Deprecated and + Tag /= Tls_Extensiontype_Values::Deprecated_Connection_Id and Tag /= Tls_Extensiontype_Values::Connection_Id and Tag /= Tls_Extensiontype_Values::Sequence_Number_Encryption_Algorithms and Tag /= Tls_Extensiontype_Values::Renegotiation_Info @@ -167,12 +167,12 @@ package TLS_Handshake is Tag /= Tls_Extensiontype_Values::Token_Binding and Tag /= Tls_Extensiontype_Values::Cached_Info and Tag /= Tls_Extensiontype_Values::Tls_Lts and - Tag /= Tls_Extensiontype_Values::Session_Ticket_Renamed_From_SessionTicket_TLS and + Tag /= Tls_Extensiontype_Values::Session_Ticket and Tag /= Tls_Extensiontype_Values::TLMSP and Tag /= Tls_Extensiontype_Values::TLMSP_Proxying and Tag /= Tls_Extensiontype_Values::TLMSP_Delegate and Tag /= Tls_Extensiontype_Values::Oid_Filters and - Tag /= Tls_Extensiontype_Values::Connection_Id_Deprecated and + Tag /= Tls_Extensiontype_Values::Deprecated_Connection_Id and Tag /= Tls_Extensiontype_Values::Renegotiation_Info ); Data_Length : Data_Length; @@ -317,7 +317,7 @@ package TLS_Handshake is -- Tag = Tls_Extensiontype_Values::Server_Name or Tag = Tls_Extensiontype_Values::Max_Fragment_Length or - Tag = Tls_Extensiontype_Values::Supported_Groups_Renamed_From_Elliptic_Curves or + Tag = Tls_Extensiontype_Values::Supported_Groups or Tag = Tls_Extensiontype_Values::Use_Srtp or Tag = Tls_Extensiontype_Values::Heartbeat or Tag = Tls_Extensiontype_Values::Application_Layer_Protocol_Negotiation or @@ -821,10 +821,10 @@ package TLS_Handshake is end message; for TLS_Handshake use (Payload => New_Session_Ticket) - if Tag = TLS_Parameters::New_Session_Ticket_Renamed_From_NewSessionTicket; + if Tag = TLS_Parameters::New_Session_Ticket; for DTLS_Handshake use (Payload => New_Session_Ticket) - if Tag = TLS_Parameters::New_Session_Ticket_Renamed_From_NewSessionTicket; + if Tag = TLS_Parameters::New_Session_Ticket; type Key_Update_Request is ( Update_Not_Requested => 0, @@ -1062,11 +1062,11 @@ package TLS_Handshake is end message; for CH_Extension_TLS use (Data => Supported_Groups) - if Tag = TLS_ExtensionType_Values::Supported_Groups_Renamed_From_Elliptic_Curves; + if Tag = TLS_ExtensionType_Values::Supported_Groups; for CH_Extension_DTLS use (Data => Supported_Groups) - if Tag = TLS_ExtensionType_Values::Supported_Groups_Renamed_From_Elliptic_Curves; + if Tag = TLS_ExtensionType_Values::Supported_Groups; for EE_Extension use (Data => Supported_Groups) - if Tag = TLS_ExtensionType_Values::Supported_Groups_Renamed_From_Elliptic_Curves; + if Tag = TLS_ExtensionType_Values::Supported_Groups; -- Key Share Extension diff --git a/examples/specs/tls_parameters.rflx b/examples/specs/tls_parameters.rflx index 4416da188..995327548 100644 --- a/examples/specs/tls_parameters.rflx +++ b/examples/specs/tls_parameters.rflx @@ -1,5 +1,5 @@ -- AUTOMATICALLY GENERATED. DO NOT EDIT. --- Generation date: 2023-08-24 +-- Generation date: 2023-11-03 -- Transport Layer Security (TLS) Parameters -- Registry last updated on 2023-07-19 @@ -1989,7 +1989,7 @@ package Tls_Parameters is -- Ref: rfc4507 -- Ref: rfc8446 -- Ref: rfc8447 - New_Session_Ticket_Renamed_From_NewSessionTicket => 4, + New_Session_Ticket => 4, -- dtls = Y -- Ref: rfc8446 @@ -2287,7 +2287,7 @@ package Tls_Parameters is -- dtls = Y -- rec = N -- Ref: draft-kwiatkowski-tls-ecdhe-kyber-01 - -- comment = Combining Secp256r1 ECDH with pre-standards version of Kyber768 + -- comment = Combining secp256r1 ECDH with pre-standards version of Kyber768 SecP256r1Kyber768Draft00 => 25498, -- dtls = Y diff --git a/rflx/converter/iana.py b/rflx/converter/iana.py index 1887d1020..210a056b4 100644 --- a/rflx/converter/iana.py +++ b/rflx/converter/iana.py @@ -162,7 +162,8 @@ def _convert_registry_to_enum_type( assert isinstance(name_element.text, str) rflx_value, bit_length = _normalize_value(value_element.text) - rflx_name = _normalize_name(name_element.text) + + rflx_name = _normalize_literal_name(name_element.text) if bit_length > enum_literal_highest_bit_len: enum_literal_highest_bit_len = bit_length @@ -368,6 +369,26 @@ def _normalize_name(description_text: str) -> str: return "_".join([s[0].upper() + s[1:] for s in name.split()]) +def _normalize_literal_name(description_text: str) -> str: + """ + Normalize the given text to be used as the name of an enum literal. + + The input text is expected to be a potentially multiline string that + sometimes contains additional comments in parentheses. Only the part up to + the first parenthesis is kept. The rest is normalized in the same way + as in _normalize_name. In addition, if the original string contains either + "(deprecated)" or "(obsolete)", then those words are prefixed to the + normalized name. + """ + description_prefix = re.sub(r"\(.*", "", description_text, flags=re.S) + rflx_name = _normalize_name(description_prefix) + if re.search(r"\(obsolete\)", description_text, re.IGNORECASE | re.S): + rflx_name = "Obsolete_" + rflx_name + if re.search(r"\(deprecated\)", description_text, re.IGNORECASE | re.S): + rflx_name = "Deprecated_" + rflx_name + return rflx_name + + def _normalize_value(value: str) -> tuple[str, int]: """ Return hex string and required bit length. diff --git a/tests/unit/converter_test.py b/tests/unit/converter_test.py index 7f5aea09b..d34f2545f 100644 --- a/tests/unit/converter_test.py +++ b/tests/unit/converter_test.py @@ -401,6 +401,62 @@ def test_convert_iana_invalid_no_registry_id(tmp_path: Path) -> None: """, id="with skipped registry", ), + pytest.param( + """ + + Test registry + + Test registry 1000 + + 1001 + Long name + (with + extra information in + parentheses) + and even more text + + + + 1002 + DHCPv6 Delayed Authentication (Obsolete) + + + + 1003 + DHCPv6-multiline Delayed Authentication + (Obsolete) + + + + 1004 + SWIPE (deprecated) + + + + 1005 + SWIPE-multiline + (deprecated) + + + + + """, + """\ + -- Test registry + package Test_Registry is + + type Test_Registry_1000 is + (Long_Name => 1001, + Obsolete_DHCPv6_Delayed_Authentication => 1002, + Obsolete_DHCPv6_Multiline_Delayed_Authentication => 1003, + Deprecated_SWIPE => 1004, + Deprecated_SWIPE_Multiline => 1005) + with Size => 10; + + end Test_Registry; + """, + id="with extra name parts", + ), ], ) def test_convert_iana(xml_str: str, rflx_str: str, tmp_path: Path) -> None: