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

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


19
20
21
22
# File 'lib/cztop/cert_store.rb', line 19

def initialize(location = nil)
  location = location.to_s if location
  attach_ffi_delegate(Zcertstore.new(location))
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


42
43
44
45
46
47
48
49
50
51
# File 'lib/cztop/cert_store.rb', line 42

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


29
30
31
32
33
# File 'lib/cztop/cert_store.rb', line 29

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