Class: ZATCA::Signing::Certificate

Inherits:
Object
  • Object
show all
Defined in:
lib/zatca/signing/certificate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(openssl_certificate:) ⇒ Certificate

Returns a new instance of Certificate.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zatca/signing/certificate.rb', line 17

def initialize(openssl_certificate:)
  super()

  @serial_number = nil
  @issuer_name = nil
  @cert_content_without_headers = nil
  @hash = nil
  @public_key = nil
  @public_key_without_headers = nil
  @public_key_bytes = nil
  @signature = nil

  @openssl_certificate = openssl_certificate

  parse_certificate
end

Instance Attribute Details

#cert_content_without_headersObject

Returns the value of attribute cert_content_without_headers.



2
3
4
# File 'lib/zatca/signing/certificate.rb', line 2

def cert_content_without_headers
  @cert_content_without_headers
end

#hashObject

Returns the value of attribute hash.



2
3
4
# File 'lib/zatca/signing/certificate.rb', line 2

def hash
  @hash
end

#issuer_nameObject

Returns the value of attribute issuer_name.



2
3
4
# File 'lib/zatca/signing/certificate.rb', line 2

def issuer_name
  @issuer_name
end

#public_keyObject

Returns the value of attribute public_key.



2
3
4
# File 'lib/zatca/signing/certificate.rb', line 2

def public_key
  @public_key
end

#public_key_bytesObject

Returns the value of attribute public_key_bytes.



2
3
4
# File 'lib/zatca/signing/certificate.rb', line 2

def public_key_bytes
  @public_key_bytes
end

#public_key_without_headersObject

Returns the value of attribute public_key_without_headers.



2
3
4
# File 'lib/zatca/signing/certificate.rb', line 2

def public_key_without_headers
  @public_key_without_headers
end

#serial_numberObject

Returns the value of attribute serial_number.



2
3
4
# File 'lib/zatca/signing/certificate.rb', line 2

def serial_number
  @serial_number
end

#signatureObject

Returns the value of attribute signature.



2
3
4
# File 'lib/zatca/signing/certificate.rb', line 2

def signature
  @signature
end

Class Method Details

.generate_base64_hash(base64_certificate) ⇒ Object

Returns the certificate hashed with SHA256 then Base64 encoded



7
8
9
# File 'lib/zatca/signing/certificate.rb', line 7

def self.generate_base64_hash(base64_certificate)
  ZATCA::Hashing.generate_hashes(base64_certificate)[:hexdigest_base64]
end

.read_certificate(certificate_path) ⇒ Object



11
12
13
14
15
# File 'lib/zatca/signing/certificate.rb', line 11

def self.read_certificate(certificate_path)
  certificate = OpenSSL::X509::Certificate.new(File.read(certificate_path))

  new(openssl_certificate: certificate)
end