<commit_before>class CheckWorker
	include Sidekiq::Worker
	sidekiq_options retry: false

	def key_to_json(key)
		key.nil? ? nil : { type: key.type, size: key.size, rsa_size: key.rsa_equivalent_size }
	end

	def perform(host, port=nil)
		host    = SimpleIDN.to_ascii host.downcase
		result = begin
			grade  = self.analyze *(port ? [host, port] : [host])
			server = grade.server
			result = {
					key:       key_to_json(server.key),
					dh:        server.dh.collect { |k| key_to_json k },
					protocols: server.supported_protocols,
					ciphers:   server.supported_ciphers.collect { |c| { protocol: c.protocol, name: c.name, size: c.size, dh: key_to_json(c.dh) } },
					score:     {
							rank:    grade.grade,
							details: {
									score:            grade.score,
									protocol:         grade.protocol_score,
									key_exchange:     grade.key_exchange_score,
									cipher_strengths: grade.cipher_strengths_score
							},
							error:   grade.error,
							danger:  grade.danger,
							warning: grade.warning,
							success: grade.success
					}
			}

			self.result server, grade, result
		rescue CryptCheck::Tls::Server::TLSNotAvailableException
			{ no_tls: true }
		end
		Datastore.post self.type, host, port, result
	end

	protected
	def result(_, _, result)
		result
	end
end
<commit_msg>Fix error in render in case of no TLS<commit_after>class CheckWorker
	include Sidekiq::Worker
	sidekiq_options retry: false

	def key_to_json(key)
		key.nil? ? nil : { type: key.type, size: key.size, rsa_size: key.rsa_equivalent_size }
	end

	def perform(host, port=nil)
		host    = SimpleIDN.to_ascii host.downcase
		result = begin
			grade  = self.analyze *(port ? [host, port] : [host])
			raise CryptCheck::Tls::Server::TLSNotAvailableException if grade.is_a? CryptCheck::Tls::TlsNotSupportedGrade
			server = grade.server
			result = {
					key:       key_to_json(server.key),
					dh:        server.dh.collect { |k| key_to_json k },
					protocols: server.supported_protocols,
					ciphers:   server.supported_ciphers.collect { |c| { protocol: c.protocol, name: c.name, size: c.size, dh: key_to_json(c.dh) } },
					score:     {
							rank:    grade.grade,
							details: {
									score:            grade.score,
									protocol:         grade.protocol_score,
									key_exchange:     grade.key_exchange_score,
									cipher_strengths: grade.cipher_strengths_score
							},
							error:   grade.error,
							danger:  grade.danger,
							warning: grade.warning,
							success: grade.success
					}
			}

			self.result server, grade, result
		rescue CryptCheck::Tls::Server::TLSNotAvailableException
			{ no_tls: true }
		end
		Datastore.post self.type, host, port, result
	end

	protected
	def result(_, _, result)
		result
	end
end

{'fraction_non_alphanumeric': 0.10469314079422383, 'fraction_numerical': 0.0, 'mean_word_length': 2.7045454545454546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5295040', 'n_tokens_mistral': 1184, 'n_tokens_neox': 911, 'n_words': 207}