Class: CZTop::CertStore
- Inherits:
-
Object
- Object
- CZTop::CertStore
- 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
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(location = nil) ⇒ CertStore
constructor
Initializes a new certificate store.
-
#insert(cert) ⇒ void
Inserts a new certificate into the store.
-
#lookup(pubkey) ⇒ Certificate?
Looks up a certificate in the store by its public key.
Methods included from HasFFIDelegate::ClassMethods
ffi_delegate, from_ffi_delegate
Methods included from HasFFIDelegate
#attach_ffi_delegate, #from_ffi_delegate, raise_zmq_err, #to_ptr
Constructor Details
#initialize(location = nil) ⇒ CertStore
Initializes a new certificate store.
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
.new ⇒ Object
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.
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.
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 |