Class: Saml::Kit::Certificate

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

Constant Summary collapse

BEGIN_CERT =
/-----BEGIN CERTIFICATE-----/
END_CERT =
/-----END CERTIFICATE-----/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, use:) ⇒ Certificate

Returns a new instance of Certificate.



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

def initialize(value, use:)
  @value = value
  @use = use.downcase.to_sym
end

Instance Attribute Details

#use ⇒ Object (readonly)

Returns the value of attribute use.



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

def use
  @use
end

#value ⇒ Object (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.to_x509(value) ⇒ Object



65
66
67
68
69
70
# File 'lib/saml/kit/certificate.rb', line 65

def self.to_x509(value)
  OpenSSL::X509::Certificate.new(Base64.decode64(value))
rescue OpenSSL::X509::CertificateError => error
  Saml::Kit.logger.warn(error)
  OpenSSL::X509::Certificate.new(value)
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
# File 'lib/saml/kit/certificate.rb', line 37

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

#encryption? ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/saml/kit/certificate.rb', line 21

def encryption?
  for?(:encryption)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/saml/kit/certificate.rb', line 41

def eql?(other)
  self == other
end

#fingerprint ⇒ Object



13
14
15
# File 'lib/saml/kit/certificate.rb', line 13

def fingerprint
  Fingerprint.new(value)
end

#for?(use) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/saml/kit/certificate.rb', line 17

def for?(use)
  self.use == use.to_sym
end

#hash ⇒ Object



45
46
47
# File 'lib/saml/kit/certificate.rb', line 45

def hash
  value.hash
end

#inspect ⇒ Object



57
58
59
# File 'lib/saml/kit/certificate.rb', line 57

def inspect
  to_h.inspect
end

#public_key ⇒ Object



33
34
35
# File 'lib/saml/kit/certificate.rb', line 33

def public_key
  x509.public_key
end

#signing? ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/saml/kit/certificate.rb', line 25

def signing?
  for?(:signing)
end

#stripped ⇒ Object



61
62
63
# File 'lib/saml/kit/certificate.rb', line 61

def stripped
  value.to_s.gsub(BEGIN_CERT, '').gsub(END_CERT, '').gsub(/\n/, '')
end

#to_h ⇒ Object



53
54
55
# File 'lib/saml/kit/certificate.rb', line 53

def to_h
  { use: @use, x509: @value }
end

#to_s ⇒ Object



49
50
51
# File 'lib/saml/kit/certificate.rb', line 49

def to_s
  value
end

#x509 ⇒ Object



29
30
31
# File 'lib/saml/kit/certificate.rb', line 29

def x509
  self.class.to_x509(value)
end