Class: CZMQ::FFI::Zcert
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zcert
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zcert.rb
Overview
This class is 100% generated using zproject.
work with CURVE security certificates
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.load(filename) ⇒ CZMQ::Zcert
Load certificate from file.
-
.new ⇒ CZMQ::Zcert
Create and initialize a new certificate in memory.
-
.new_from(public_key, secret_key) ⇒ CZMQ::Zcert
Accepts public/secret key pair from caller.
-
.new_from_txt(public_txt, secret_txt) ⇒ CZMQ::Zcert
Accepts public/secret key text pair from caller.
-
.test(verbose) ⇒ void
Self test of this class.
Instance Method Summary collapse
-
#__ptr ⇒ ::FFI::Pointer
(also: #to_ptr)
Return internal pointer.
-
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
Nullify internal pointer and return pointer pointer.
-
#__undef_finalizer ⇒ void
Undefines the finalizer for this object.
-
#apply(socket) ⇒ void
Apply certificate to socket, i.e.
-
#destroy ⇒ void
Destroy a certificate in memory.
-
#dup ⇒ Zcert
Return copy of certificate; if certificate is NULL or we exhausted heap memory, returns NULL.
-
#eq(compare) ⇒ Boolean
Return true if two certificates have the same keys.
-
#initialize(ptr, finalize = true) ⇒ Zcert
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
-
#meta(name) ⇒ String
Get metadata value from certificate; if the metadata value doesn’t exist, returns NULL.
-
#meta_keys ⇒ Zlist
Get list of metadata fields from certificate.
- #null? ⇒ Boolean
-
#print ⇒ void
Print certificate contents to stdout.
-
#public_key ⇒ ::FFI::Pointer
Return public part of key pair as 32-byte binary string.
-
#public_txt ⇒ String
Return public part of key pair as Z85 armored string.
-
#save(filename) ⇒ Integer
Save full certificate (public + secret) to file for persistent storage This creates one public file and one secret file (filename + “_secret”).
-
#save_public(filename) ⇒ Integer
Save public certificate only to file for persistent storage.
-
#save_secret(filename) ⇒ Integer
Save secret certificate only to file for persistent storage.
-
#secret_key ⇒ ::FFI::Pointer
Return secret part of key pair as 32-byte binary string.
-
#secret_txt ⇒ String
Return secret part of key pair as Z85 armored string.
-
#set_meta(name, format, *args) ⇒ void
Set certificate metadata from formatted string.
-
#unset_meta(name) ⇒ void
Unset certificate metadata.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zcert
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
24 25 26 27 28 29 30 31 32 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 24 def initialize(ptr, finalize = true) @ptr = ptr if @ptr.null? @ptr = nil # Remove null pointers so we don't have to test for them. elsif finalize @finalizer = self.class.create_finalizer_for @ptr ObjectSpace.define_finalizer self, @finalizer end end |
Class Method Details
.__new ⇒ Object
18 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 18 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 42 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 35 def self.create_finalizer_for(ptr) ptr_ptr = ::FFI::MemoryPointer.new :pointer Proc.new do ptr_ptr.write_pointer ptr ::CZMQ::FFI.zcert_destroy ptr_ptr end end |
.load(filename) ⇒ CZMQ::Zcert
Load certificate from file
105 106 107 108 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 105 def self.load(filename) ptr = ::CZMQ::FFI.zcert_load(filename) __new ptr end |
.new ⇒ CZMQ::Zcert
Create and initialize a new certificate in memory
79 80 81 82 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 79 def self.new() ptr = ::CZMQ::FFI.zcert_new() __new ptr end |
.new_from(public_key, secret_key) ⇒ CZMQ::Zcert
Accepts public/secret key pair from caller
88 89 90 91 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 88 def self.new_from(public_key, secret_key) ptr = ::CZMQ::FFI.zcert_new_from(public_key, secret_key) __new ptr end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
49 50 51 52 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 49 def __ptr raise DestroyedError unless @ptr @ptr end |
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
This detaches the current instance from the native object and thus makes it unusable.
Nullify internal pointer and return pointer pointer.
60 61 62 63 64 65 66 67 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 60 def __ptr_give_ref raise DestroyedError unless @ptr ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer @ptr __undef_finalizer if @finalizer @ptr = nil ptr_ptr end |
#__undef_finalizer ⇒ void
Only use this if you need to and can guarantee that the native object will be freed by other means.
This method returns an undefined value.
Undefines the finalizer for this object.
72 73 74 75 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 72 def __undef_finalizer ObjectSpace.undefine_finalizer self @finalizer = nil end |
#apply(socket) ⇒ void
This method returns an undefined value.
Apply certificate to socket, i.e. use for CURVE security on socket. If certificate was loaded from public file, the secret key will be undefined, and this certificate will not work successfully.
248 249 250 251 252 253 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 248 def apply(socket) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_apply(self_p, socket) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a certificate in memory
113 114 115 116 117 118 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 113 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zcert_destroy(self_p) result end |
#dup ⇒ Zcert
Return copy of certificate; if certificate is NULL or we exhausted heap memory, returns NULL.
259 260 261 262 263 264 265 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 259 def dup() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_dup(self_p) result = Zcert.__new result, true result end |
#eq(compare) ⇒ Boolean
Return true if two certificates have the same keys
271 272 273 274 275 276 277 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 271 def eq(compare) raise DestroyedError unless @ptr self_p = @ptr compare = compare.__ptr if compare result = ::CZMQ::FFI.zcert_eq(self_p, compare) result end |
#meta(name) ⇒ String
Get metadata value from certificate; if the metadata value doesn’t exist, returns NULL.
189 190 191 192 193 194 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 189 def (name) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.(self_p, name) result end |
#meta_keys ⇒ Zlist
Get list of metadata fields from certificate. Caller is responsible for destroying list. Caller should not modify the values of list items.
200 201 202 203 204 205 206 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 200 def () raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.(self_p) result = Zlist.__new result, false result end |
#null? ⇒ Boolean
44 45 46 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 44 def null? !@ptr or @ptr.null? end |
#print ⇒ void
This method returns an undefined value.
Print certificate contents to stdout
282 283 284 285 286 287 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 282 def print() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_print(self_p) result end |
#public_key ⇒ ::FFI::Pointer
Return public part of key pair as 32-byte binary string
123 124 125 126 127 128 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 123 def public_key() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_public_key(self_p) result end |
#public_txt ⇒ String
Return public part of key pair as Z85 armored string
143 144 145 146 147 148 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 143 def public_txt() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_public_txt(self_p) result end |
#save(filename) ⇒ Integer
Save full certificate (public + secret) to file for persistent storage This creates one public file and one secret file (filename + “_secret”).
213 214 215 216 217 218 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 213 def save(filename) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_save(self_p, filename) result end |
#save_public(filename) ⇒ Integer
Save public certificate only to file for persistent storage
224 225 226 227 228 229 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 224 def save_public(filename) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_save_public(self_p, filename) result end |
#save_secret(filename) ⇒ Integer
Save secret certificate only to file for persistent storage
235 236 237 238 239 240 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 235 def save_secret(filename) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_save_secret(self_p, filename) result end |
#secret_key ⇒ ::FFI::Pointer
Return secret part of key pair as 32-byte binary string
133 134 135 136 137 138 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 133 def secret_key() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_secret_key(self_p) result end |
#secret_txt ⇒ String
Return secret part of key pair as Z85 armored string
153 154 155 156 157 158 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 153 def secret_txt() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zcert_secret_txt(self_p) result end |
#set_meta(name, format, *args) ⇒ void
This method returns an undefined value.
Set certificate metadata from formatted string.
166 167 168 169 170 171 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 166 def (name, format, *args) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.(self_p, name, format, *args) result end |
#unset_meta(name) ⇒ void
This method returns an undefined value.
Unset certificate metadata.
177 178 179 180 181 182 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 177 def (name) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.(self_p, name) result end |