Class: CZTop::CertStore

Inherits:
Object
  • Object
show all
Extended by:
HasFFIDelegate::ClassMethods
Includes:
CZMQ::FFI, HasFFIDelegate
Defined in:
lib/cztop/cert_store.rb

Overview

A store for CURVE security certificates, either backed by files on disk or in-memory.

Instance Attribute Summary

Attributes included from HasFFIDelegate

#ffi_delegate

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasFFIDelegate::ClassMethods

ffi_delegate, from_ffi_delegate

Methods included from HasFFIDelegate

#attach_ffi_delegate, #from_ffi_delegate, raise_zmq_err, #raise_zmq_err, #to_ptr

Constructor Details

#initialize(location = nil) ⇒ CertStore

Initializes a new certificate store.

Parameters:

  • location (String, #to_s, nil) (defaults to: nil)

    location the path to the directories to load certificates from, or nil if no certificates need to be loaded from the disk



27
28
29
30
# File 'lib/cztop/cert_store.rb', line 27

def initialize(location = nil)
  location = location.to_s if location
  attach_ffi_delegate(Zcertstore.new(location))
end

Class Method Details

.newObject



17
18
19
# File 'lib/cztop/cert_store.rb', line 17

def self.new(...)
  fail NotImplementedError
end

Instance Method Details

#insert(cert) ⇒ void

Note:

The same public key must not be inserted more than once.

This method returns an undefined value.

Inserts a new certificate into the store.

Parameters:

Raises:

  • (ArgumentError)

    if the given certificate is not a Certificate object or has been inserted before already



53
54
55
56
57
58
59
60
61
62
# File 'lib/cztop/cert_store.rb', line 53

def insert(cert)
  raise ArgumentError unless cert.is_a?(Certificate)

  @_inserted_pubkeys ||= Set.new
  pubkey               = cert.public_key
  raise ArgumentError if @_inserted_pubkeys.include? pubkey

  ffi_delegate.insert(cert.ffi_delegate)
  @_inserted_pubkeys << pubkey
end

#lookup(pubkey) ⇒ Certificate?

Looks up a certificate in the store by its public key.

Parameters:

  • pubkey (String)

    the public key in question, in Z85 format

Returns:

  • (Certificate)

    the matching certificate, if found

  • (nil)

    if no matching certificate was found



38
39
40
41
42
43
# File 'lib/cztop/cert_store.rb', line 38

def lookup(pubkey)
  ptr = ffi_delegate.lookup(pubkey)
  return nil if ptr.null?

  Certificate.from_ffi_delegate(ptr)
end