Class: R509::CRL::SQLiteReaderWriter

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

Overview

SQLite-based reader/writer for CRL data.

Instance Method Summary collapse

Constructor Details

#initialize(filename_or_db) ⇒ SQLiteReaderWriter

Create an SQLite based persistence

Parameters:

  • filename_or_db

    filepath to an SQLite database or an SQLite3::Database object



8
9
10
11
12
13
14
15
16
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 8

def initialize(filename_or_db)
  if filename_or_db.is_a? SQLite3::Database
    @db = filename_or_db
  else
    @db = SQLite3::Database.new(file)
  end
  # create tables if missing
  ensure_schema
end

Instance Method Details

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

Reads a CRL list file from the SQLite database

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)


23
24
25
26
27
28
29
30
31
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 23

def read_list
  @db.execute('SELECT serial,reason,revoked_at from revoked_serials') do |row|
    serial = row[0].to_i
    reason = row[1]
    revoke_time = row[2]
    yield serial, reason, revoke_time
  end
  nil
end

#read_numberObject

read the CRL number from SQLite



48
49
50
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 48

def read_number
  @db.get_first_value 'SELECT number from crl_number'
end

#remove_list_entry(serial) ⇒ Object

Remove a CRL list entry from SQLite

Parameters:

  • serial (Integer)

    serial number of the certificate to remove from the list



43
44
45
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 43

def remove_list_entry(serial)
  @db.execute('DELETE FROM revoked_serials WHERE serial=?', serial.to_s)
end

#write_list_entry(serial, revoke_time, reason) ⇒ Object

Appends a CRL list entry to the SQLite database

Parameters:

  • serial (Integer)

    serial number of the certificate to revoke

  • reason (Integer, nil)

    reason for revocation

  • revoke_time (Integer)


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

def write_list_entry(serial, revoke_time, reason)
  @db.execute('INSERT INTO revoked_serials (serial, revoked_at, reason) VALUES (?,?,?)', serial.to_s, revoke_time, reason)
end

#write_number(crl_number) ⇒ Object

write the CRL number to SQLite



53
54
55
# File 'lib/r509/crl/sqlite_reader_writer.rb', line 53

def write_number(crl_number)
  @db.execute('UPDATE crl_number SET number=?', crl_number)
end