class Samlr::Fingerprint
Attributes
value[RW]
Public Class Methods
from_string(string)
click to toggle source
# File lib/samlr/fingerprint.rb, line 13 def self.from_string(string) normalized = normalize(string) if string.gsub(':', '').length == 64 FingerprintSHA256.new(normalized) else FingerprintSHA1.new(normalized) end end
new(value)
click to toggle source
# File lib/samlr/fingerprint.rb, line 5 def initialize(value) if value.is_a?(OpenSSL::X509::Certificate) @value = self.class.x509(value) else @value = self.class.normalize(value) end end
normalize(value)
click to toggle source
Converts a string to fingerprint normal form
# File lib/samlr/fingerprint.rb, line 53 def self.normalize(value) value.to_s.upcase.gsub(/[^A-F0-9]/, "").scan(/../).join(":") end
x509(certificate)
click to toggle source
Extracts a fingerprint for an x509 certificate
# File lib/samlr/fingerprint.rb, line 48 def self.x509(certificate) raise NotImplementedError, 'subclass must implement x509' end
Public Instance Methods
==(other)
click to toggle source
Fingerprints compare if their values are equal and not blank
# File lib/samlr/fingerprint.rb, line 23 def ==(other) other.is_a?(Fingerprint) && other.valid? && valid? && other.to_s == to_s end
compare!(other)
click to toggle source
# File lib/samlr/fingerprint.rb, line 27 def compare!(other) if self != other raise FingerprintError.new("Fingerprint mismatch", "#{self} vs. #{other}") else true end end
to_s()
click to toggle source
# File lib/samlr/fingerprint.rb, line 43 def to_s value end
valid?()
click to toggle source
# File lib/samlr/fingerprint.rb, line 39 def valid? value =~ /([A-F0-9]:?)+/ end
verify!(certificate)
click to toggle source
# File lib/samlr/fingerprint.rb, line 35 def verify!(certificate) compare!(self.class.new(self.class.x509(certificate.x509))) end