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 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 35 def self.create_finalizer_for(ptr) Proc.new do ptr_ptr = ::FFI::MemoryPointer.new :pointer ptr_ptr.write_pointer ptr ::CZMQ::FFI.zcert_destroy ptr_ptr end end |
.load(filename) ⇒ CZMQ::Zcert
Load certificate from file
104 105 106 107 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 104 def self.load(filename) ptr = ::CZMQ::FFI.zcert_load(filename) __new ptr end |
.new ⇒ CZMQ::Zcert
Create and initialize a new certificate in memory
78 79 80 81 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 78 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
87 88 89 90 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 87 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
48 49 50 51 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 48 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.
59 60 61 62 63 64 65 66 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 59 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.
71 72 73 74 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 71 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.
247 248 249 250 251 252 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 247 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
112 113 114 115 116 117 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 112 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.
258 259 260 261 262 263 264 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 258 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
270 271 272 273 274 275 276 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 270 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.
188 189 190 191 192 193 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 188 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.
199 200 201 202 203 204 205 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 199 def () raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.(self_p) result = Zlist.__new result, false result end |
#null? ⇒ Boolean
43 44 45 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 43 def null? !@ptr or @ptr.null? end |
#print ⇒ void
This method returns an undefined value.
Print certificate contents to stdout
281 282 283 284 285 286 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 281 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
122 123 124 125 126 127 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 122 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
142 143 144 145 146 147 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 142 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”).
212 213 214 215 216 217 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 212 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
223 224 225 226 227 228 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 223 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
234 235 236 237 238 239 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 234 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
132 133 134 135 136 137 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 132 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
152 153 154 155 156 157 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 152 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.
165 166 167 168 169 170 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 165 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.
176 177 178 179 180 181 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 176 def (name) raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.(self_p, name) result end |