Class: Samlr::Fingerprint
Direct Known Subclasses
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
- .from_string(string) ⇒ Object
-
.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
- #verify!(certificate) ⇒ Object
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 = self.class.x509(value) else @value = self.class.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
.from_string(string) ⇒ Object
13 14 15 16 17 18 19 20 |
# 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 |
.normalize(value) ⇒ Object
Converts a string to fingerprint normal form
53 54 55 |
# File 'lib/samlr/fingerprint.rb', line 53 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
48 49 50 |
# File 'lib/samlr/fingerprint.rb', line 48 def self.x509(certificate) raise NotImplementedError, 'subclass must implement x509' end |
Instance Method Details
#==(other) ⇒ Object
Fingerprints compare if their values are equal and not blank
23 24 25 |
# File 'lib/samlr/fingerprint.rb', line 23 def ==(other) other.is_a?(Fingerprint) && other.valid? && valid? && other.to_s == to_s end |
#compare!(other) ⇒ Object
27 28 29 30 31 32 33 |
# 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 ⇒ Object
43 44 45 |
# File 'lib/samlr/fingerprint.rb', line 43 def to_s value end |
#valid? ⇒ Boolean
39 40 41 |
# File 'lib/samlr/fingerprint.rb', line 39 def valid? value =~ /([A-F0-9]:?)+/ end |
#verify!(certificate) ⇒ Object
35 36 37 |
# File 'lib/samlr/fingerprint.rb', line 35 def verify!(certificate) compare!(self.class.new(self.class.x509(certificate.x509))) end |