Skip to content

Commit

Permalink
use constants for sum types
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Aug 7, 2014
1 parent 4a14e4b commit 1f78d77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/lib/registration/ssl_certificate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module Registration
class SslCertificate
attr_reader :x509_cert

SHA1_SUM = "SHA1"
SHA256_SUM = "SHA256"

def initialize(x509_cert)
@x509_cert = x509_cert
end
Expand Down Expand Up @@ -83,9 +86,9 @@ def issuer_organization_unit
# check whether SSL certificate matches the expected fingerprint
def fingerprint_match?(fingerprint_type, fingerprint)
case fingerprint_type.upcase
when "SHA1"
when SHA1_SUM
sha1_fingerprint.upcase == fingerprint.upcase
when "SHA256"
when SHA256_SUM
sha256_fingerprint.upcase == fingerprint.upcase
else
false
Expand Down
4 changes: 2 additions & 2 deletions src/lib/registration/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def export_ssl_config
ret = { "reg_server_cert" => reg_server_cert }

if reg_server_cert_fingerprint_type &&
reg_server_cert_fingerprint_type.upcase == "SHA1" ||
reg_server_cert_fingerprint_type.upcase == "SHA256"
reg_server_cert_fingerprint_type.upcase == SslCertificate::SHA1_SUM ||
reg_server_cert_fingerprint_type.upcase == SslCertificate::SHA256_SUM

ret["reg_server_cert_fingerprint_type"] = reg_server_cert_fingerprint_type
ret["reg_server_cert_fingerprint"] = reg_server_cert_fingerprint
Expand Down
11 changes: 7 additions & 4 deletions src/lib/registration/ui/autoyast_config_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def content_reg_code_settings
end

def content_server_settings
sha1 = ::Registration::SslCertificate::SHA1_SUM
sha256 = ::Registration::SslCertificate::SHA256_SUM
fingerprint_type = config.reg_server_cert_fingerprint_type.upcase

VBox(
# Translators: Text for UI Label - capitalized
Frame(_("Server Settings"),
Expand Down Expand Up @@ -119,10 +123,9 @@ def content_server_settings
_("Optional SSL Server Certificate Fingerprint"),
[
Item(Id(""), _("none"),
config.reg_server_cert_fingerprint_type != "SHA1" &&
config.reg_server_cert_fingerprint_type != "SHA256"),
Item(Id("SHA1"), "SHA1", config.reg_server_cert_fingerprint_type == "SHA1"),
Item(Id("SHA256"), "SHA256", config.reg_server_cert_fingerprint_type == "SHA256")
fingerprint_type != sha1 && fingerprint_type != sha256),
Item(Id(sha1), sha1, fingerprint_type == sha1),
Item(Id(sha256), sha256, fingerprint_type == sha256)
]
)
),
Expand Down

0 comments on commit 1f78d77

Please sign in to comment.