Class: Saml::Kit::Fingerprint

Inherits:
Object
  • Object
show all
Defined in:
lib/saml/kit/fingerprint.rb

Overview

This generates a fingerprint for an X509 Certificate.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_certificate) ⇒ Fingerprint

Returns a new instance of Fingerprint.



8
9
10
# File 'lib/saml/kit/fingerprint.rb', line 8

def initialize(raw_certificate)
  @x509 = Certificate.to_x509(raw_certificate)
end

Instance Attribute Details

#x509Object (readonly)

The OpenSSL::X509::Certificate



6
7
8
# File 'lib/saml/kit/fingerprint.rb', line 6

def x509
  @x509
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
# File 'lib/saml/kit/fingerprint.rb', line 20

def ==(other)
  self.to_s == other.to_s
end

#algorithm(algorithm) ⇒ String

Generates a formatted fingerprint using the specified hash algorithm.

Parameters:

  • algorithm (OpenSSL::Digest)

    the openssl algorithm to use ‘OpenSSL::Digest::SHA256`, `OpenSSL::Digest::SHA1`.

Returns:

  • (String)

    in the format of ‘“BF:ED:C5:F1:6C:AB:F5:B2:15:1F:BF:BD:7D:68:1A:F9:A5:4E:4C:19:30:BC:6D:25:B1:8E:98:D4:23:FD:B4:09”`



16
17
18
# File 'lib/saml/kit/fingerprint.rb', line 16

def algorithm(algorithm)
  pretty_fingerprint(algorithm.new.hexdigest(x509.to_der))
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/saml/kit/fingerprint.rb', line 24

def eql?(other)
  self == other
end

#hashObject



28
29
30
# File 'lib/saml/kit/fingerprint.rb', line 28

def hash
  to_s.hash
end

#to_sObject



32
33
34
# File 'lib/saml/kit/fingerprint.rb', line 32

def to_s
  algorithm(OpenSSL::Digest::SHA256)
end