Class: Samlr::Fingerprint
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.normalize(value) ⇒ Object
Converts a string to fingerprint normal form.
-
.x509(certificate) ⇒ Object
Extracts a fingerprint for an x509 certificate.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Fingerprints compare if their values are equal and not blank.
- #compare!(other) ⇒ Object
-
#initialize(value) ⇒ Fingerprint
constructor
A new instance of Fingerprint.
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ Fingerprint
Returns a new instance of Fingerprint.
5 6 7 8 9 10 11 |
# File 'lib/samlr/fingerprint.rb', line 5 def initialize(value) if value.is_a?(OpenSSL::X509::Certificate) @value = Fingerprint.x509(value) else @value = Fingerprint.normalize(value) end end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/samlr/fingerprint.rb', line 3 def value @value end |
Class Method Details
.normalize(value) ⇒ Object
Converts a string to fingerprint normal form
40 41 42 |
# File 'lib/samlr/fingerprint.rb', line 40 def self.normalize(value) value.to_s.upcase.gsub(/[^A-F0-9]/, "").scan(/../).join(":") end |
.x509(certificate) ⇒ Object
Extracts a fingerprint for an x509 certificate
35 36 37 |
# File 'lib/samlr/fingerprint.rb', line 35 def self.x509(certificate) normalize(OpenSSL::Digest::SHA1.new.hexdigest(certificate.to_der)) end |
Instance Method Details
#==(other) ⇒ Object
Fingerprints compare if their values are equal and not blank
14 15 16 |
# File 'lib/samlr/fingerprint.rb', line 14 def ==(other) other.is_a?(Fingerprint) && other.valid? && valid? && other.to_s == to_s end |
#compare!(other) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/samlr/fingerprint.rb', line 18 def compare!(other) if self != other raise FingerprintError.new("Fingerprint mismatch", "#{self} vs. #{other}") else true end end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/samlr/fingerprint.rb', line 30 def to_s value end |
#valid? ⇒ Boolean
26 27 28 |
# File 'lib/samlr/fingerprint.rb', line 26 def valid? value =~ /([A-F0-9]:?)+/ end |