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

- (FileReaderWriter) initialize

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

- (Object) crl_list_file

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

- (Object) crl_number_file

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

- (Object) read_list(admin)

Reads a CRL list file from a file or StringIO

Parameters:



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

def read_list(admin)
  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
    admin.revoke_cert(serial, reason, revoke_time, false)
  end
  nil
end

- (Object) read_number

read the CRL number from a file or StringIO



94
95
96
97
98
# File 'lib/r509/crl/reader_writer.rb', line 94

def read_number
  return 0 if @crl_number_file.nil?

  read_data(@crl_number_file).to_i
end

- (Object) remove_list_entry(serial)

Remove a CRL list entry

Parameters:

  • serial (Integer)

    serial number of the certificate to remove from the list



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

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

- (Object) write_list_entry(serial, revoke_time, reason)

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)


66
67
68
69
70
71
# File 'lib/r509/crl/reader_writer.rb', line 66

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

- (Object) write_number(crl_number)

write the CRL number to a file or StringIO



101
102
103
104
105
# File 'lib/r509/crl/reader_writer.rb', line 101

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

  write_data(@crl_number_file,crl_number.to_s)
end