Class: R509::CRL::FileReaderWriter

Inherits:
ReaderWriter show all
Defined in:
lib/r509/crl/reader_writer.rb

Overview

File-based implementation of the CRL reader/writer. Uses the crl_number_file and crl_list_file attributes in CAConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileReaderWriter

Returns a new instance of FileReaderWriter



39
40
41
42
# File 'lib/r509/crl/reader_writer.rb', line 39

def initialize
  @crl_number_file = nil
  @crl_list_file = nil
end

Instance Attribute Details

#crl_list_fileObject

Returns the value of attribute crl_list_file



37
38
39
# File 'lib/r509/crl/reader_writer.rb', line 37

def crl_list_file
  @crl_list_file
end

#crl_number_fileObject

Returns the value of attribute crl_number_file



37
38
39
# File 'lib/r509/crl/reader_writer.rb', line 37

def crl_number_file
  @crl_number_file
end

Instance Method Details

#read_list {|serial, reason, revoke_time| ... } ⇒ Object

Reads a CRL list file from a file or StringIO

Yields:

  • For each revoked certificate in the CRL

Yield Parameters:

  • serial (Integer)

    revoked certificate's serial number

  • reason (Integer, nil)

    reason for revocation.

  • revoke_time (Integer)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/r509/crl/reader_writer.rb', line 49

def read_list
  return nil if @crl_list_file.nil?

  data = read_data(@crl_list_file)

  data.each_line do |line|
    line.chomp!
    serial,  revoke_time, reason = line.split(',', 3)
    serial = serial.to_i
    reason = (reason == '') ? nil : reason.to_i
    revoke_time = (revoke_time == '') ? nil : revoke_time.to_i
    yield serial, reason, revoke_time
  end
  nil
end

#read_numberObject

read the CRL number from a file or StringIO



97
98
99
100
101
# File 'lib/r509/crl/reader_writer.rb', line 97

def read_number
  return 0 if @crl_number_file.nil?

  read_data(@crl_number_file).to_i
end

#remove_list_entry(serial) ⇒ Object

Remove a CRL list entry

Parameters:

  • serial (Integer)

    serial number of the certificate to remove from the list



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/r509/crl/reader_writer.rb', line 78

def remove_list_entry(serial)
  return nil if @crl_list_file.nil?

  data = read_data(@crl_list_file)

  updated_list = []

  data.each_line do |line|
    line.chomp!
    revoke_info = line.split(',', 3)
    if revoke_info[0].to_i != serial
      updated_list.push(line)
    end
  end
  write_data(@crl_list_file, updated_list.join("\n") + "\n")
  nil
end

#write_list_entry(serial, revoke_time, reason) ⇒ Object

Appends a CRL list entry to a file or StringIO

Parameters:

  • serial (Integer)

    serial number of the certificate to revoke

  • reason (Integer, nil)

    reason for revocation

  • revoke_time (Integer)


69
70
71
72
73
74
# File 'lib/r509/crl/reader_writer.rb', line 69

def write_list_entry(serial, revoke_time, reason)
  return nil if @crl_list_file.nil?

  entry = [serial, revoke_time, reason].join(",")
  write_data(@crl_list_file, entry + "\n", 'a:ascii-8bit')
end

#write_number(crl_number) ⇒ Object

write the CRL number to a file or StringIO



104
105
106
107
108
# File 'lib/r509/crl/reader_writer.rb', line 104

def write_number(crl_number)
  return nil if @crl_number_file.nil?

  write_data(@crl_number_file, crl_number.to_s)
end