Skip to content

Commit 75dc0e1

Browse files
committed
(PUP-10639) DRY generating digest as hex
1 parent 944cac4 commit 75dc0e1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/puppet/ssl/state_machine.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def next_state
7171
route = @machine.session.route_to(:ca, ssl_context: @ssl_context)
7272
_, pem = route.get_certificate(Puppet::SSL::CA_NAME, ssl_context: @ssl_context)
7373
if @machine.ca_fingerprint
74-
actual_digest = Puppet::SSL::Digest.new(@machine.digest, pem).to_hex
74+
actual_digest = @machine.digest_as_hex(pem)
7575
expected_digest = @machine.ca_fingerprint.scan(/../).join(':').upcase
7676
if actual_digest == expected_digest
7777
Puppet.info(_("Verified CA bundle with digest (%{digest_type}) %{actual_digest}") %
@@ -139,8 +139,7 @@ def download_ca(ssl_ctx, last_update)
139139
next_ctx = @ssl_provider.create_root_context(cacerts: cacerts, revocation: false)
140140
@cert_provider.save_cacerts(cacerts)
141141

142-
digest = Puppet::SSL::Digest.new(@machine.digest, pem).to_hex
143-
Puppet.info("Refreshed CA certificate: #{digest}")
142+
Puppet.info("Refreshed CA certificate: #{@machine.digest_as_hex(pem)}")
144143

145144
next_ctx
146145
end
@@ -235,8 +234,7 @@ def download_crl(ssl_ctx, last_update)
235234
next_ctx = @ssl_provider.create_root_context(cacerts: ssl_ctx[:cacerts], crls: crls)
236235
@cert_provider.save_crls(crls)
237236

238-
digest = Puppet::SSL::Digest.new(@machine.digest, pem).to_hex
239-
Puppet.info("Refreshed CRL: #{digest}")
237+
Puppet.info("Refreshed CRL: #{@machine.digest_as_hex(pem)}")
240238

241239
next_ctx
242240
end
@@ -517,6 +515,10 @@ def unlock
517515
@lockfile.unlock
518516
end
519517

518+
def digest_as_hex(str)
519+
Puppet::SSL::Digest.new(digest, str).to_hex
520+
end
521+
520522
private
521523

522524
def run_machine(state, stop)

0 commit comments

Comments
 (0)