Class: CertificateTransparency::PreCert

Inherits:
Object
  • Object
show all
Defined in:
lib/certificate-transparency/pre_cert.rb

Overview

An RFC6962 PreCert structure.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#issuer_key_hashObject

Returns the value of attribute issuer_key_hash.



4
5
6
# File 'lib/certificate-transparency/pre_cert.rb', line 4

def issuer_key_hash
  @issuer_key_hash
end

#tbs_certificateObject

Returns the value of attribute tbs_certificate.



4
5
6
# File 'lib/certificate-transparency/pre_cert.rb', line 4

def tbs_certificate
  @tbs_certificate
end

Class Method Details

.from_blob(blob) ⇒ CertificateTransparency::PreCert

Parse a binary blob into a PreCert structure.

It is uncommon to call this directly. Because of the way that the PreCert is encoded, you have to parse the component parts out of the TimestampedEntry; however, this method is here if you need it.

Parameters:

Returns:



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/certificate-transparency/pre_cert.rb', line 16

def self.from_blob(blob)
  new.tap do |pc|
    pc.issuer_key_hash, tbs_blob = blob.unpack("a32a*")
    tbs_opaque, rest = TLS::Opaque.from_blob(tbs_blob, 2**24-1)
    unless rest == ""
      raise ArgumentError,
            "Invalid blob (extra data after end of structure: #{rest.inspect}"
    end

    pc.tbs_certificate = tbs_opaque.value
  end
end

Instance Method Details

#to_blobString

Turn this structure into an encoded binary blob.

Returns:

Raises:

  • (RuntimeError)

    if some of the fields in the structure aren't filled out.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/certificate-transparency/pre_cert.rb', line 36

def to_blob
  if @issuer_key_hash.nil?
    raise RuntimeError,
          "issuer_key_hash is not set"
  end

  if @tbs_certificate.nil?
    raise RuntimeError,
          "tbs_certificate is not set"
  end

  [
   @issuer_key_hash,
   TLS::Opaque.new(@tbs_certificate, 2**24-1).to_blob
  ].pack("a32a*")
end