def _compare_extensions(
        self,
        other: 'TLSClientHelloSignature',
        allow_tls_permutation: bool = False
    ):
        """Compare the TLS extensions of two Client Hello messages."""
        # Check that the extension lists are identical in content.
        if set(self.extension_list) != set(other.extension_list):
            symdiff = list(set(self.extension_list).symmetric_difference(
                other.extension_list
            ))
            return False, (f"TLS extension lists differ: "
                           f"Symmatric difference {symdiff}")

        if not allow_tls_permutation and self.extension_list != other.extension_list:
            return False, "TLS extension lists identical but differ in order"

        # Check the extensions' parameters.
        for i, ext in enumerate(self.extensions):
            if allow_tls_permutation and self._is_permuted_extension(ext):
                # If TLS extension permutation is enabled, locate this extension
                # in the other signature by type.
                other_ext = next(
                    e for e in other.extensions if e.ext_type == ext.ext_type
                )
            else:
                other_ext = other.extensions[i]
            if not ext.equals(other_ext):
                ours = ext.to_dict()
                ours.pop("type")
                theirs = other_ext.to_dict()
                theirs.pop("type")
                msg = (f"TLS extension {ext.ext_type.name} is different. "
                       f"{ours} != {theirs}")
                return False, msg

        return True, None
Compare the TLS extensions of two Client Hello messages.
tests/signature.py