Class: Rnp::Generate
- Inherits:
-
Object
- Object
- Rnp::Generate
- Defined in:
- lib/rnp/op/generate.rb
Overview
Key generation operation
Instance Method Summary collapse
-
#bits=(len) ⇒ Object
Set the bit length of the key.
-
#curve=(curve) ⇒ Object
Set the desired curve for this ECC key.
-
#execute ⇒ Key
Execute the operation.
-
#hash=(hash) ⇒ Object
Set the hash algorithm used in the self-signature of the key.
- #inspect ⇒ Object
-
#key ⇒ Key
Retrieve the key.
-
#lifetime=(secs) ⇒ Object
Set the number of seconds for this key to remain valid.
-
#options=(opts) ⇒ Object
Set a group of options.
-
#password=(password) ⇒ Object
Set the password used to protect the key.
- #preferences=(prefs) ⇒ Object
-
#protection_mode=(mode) ⇒ Object
Set the protection mode for this key.
-
#qbits=(len) ⇒ Object
Set the bit length of the q parameter for a DSA key.
-
#s2k_cipher=(cipher) ⇒ Object
Set the cipher used to protect the key.
-
#s2k_hash=(hash) ⇒ Object
Set the hash algorithm used to protect the key.
-
#s2k_iterations=(iter) ⇒ Object
Set the s2k iteration count used to protect the key.
-
#usage=(usage) ⇒ Object
Set the usage for this key.
-
#userid=(userid) ⇒ Object
Set the userid for this key.
Instance Method Details
#bits=(len) ⇒ Object
Set the bit length of the key.
60 61 62 |
# File 'lib/rnp/op/generate.rb', line 60 def bits=(len) Rnp.call_ffi(:rnp_op_generate_set_bits, @ptr, len) end |
#curve=(curve) ⇒ Object
This is only valid for ECC keys which permit specifying a curve.
Set the desired curve for this ECC key.
78 79 80 |
# File 'lib/rnp/op/generate.rb', line 78 def curve=(curve) Rnp.call_ffi(:rnp_op_generate_set_curve, @ptr, curve.to_s) end |
#execute ⇒ Key
Execute the operation.
This should only be called once.
180 181 182 183 |
# File 'lib/rnp/op/generate.rb', line 180 def execute Rnp.call_ffi(:rnp_op_generate_execute, @ptr) key end |
#hash=(hash) ⇒ Object
Set the hash algorithm used in the self-signature of the key.
85 86 87 |
# File 'lib/rnp/op/generate.rb', line 85 def hash=(hash) Rnp.call_ffi(:rnp_op_generate_set_hash, @ptr, hash.to_s) end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/rnp/op/generate.rb', line 29 def inspect Rnp.inspect_ptr(self) end |
#key ⇒ Key
Retrieve the key.
This should only be called after #execute.
190 191 192 193 194 195 |
# File 'lib/rnp/op/generate.rb', line 190 def key pptr = FFI::MemoryPointer.new(:pointer) Rnp.call_ffi(:rnp_op_generate_get_key, @ptr, pptr) pkey = pptr.read_pointer Key.new(pkey) unless pkey.null? end |
#lifetime=(secs) ⇒ Object
Set the number of seconds for this key to remain valid.
This determines the expiration time (creation time + lifetime).
133 134 135 |
# File 'lib/rnp/op/generate.rb', line 133 def lifetime=(secs) Rnp.call_ffi(:rnp_op_generate_set_expiration, @ptr, secs) end |
#options=(opts) ⇒ Object
Set a group of options.
48 49 50 51 52 53 54 55 |
# File 'lib/rnp/op/generate.rb', line 48 def (opts) %i{bits qbits curve hash s2k_hash s2k_iterations s2k_cipher password protection_mode lifetime userid usage preferences}.each do |prop| value = opts[prop] send("#{prop}=", value) unless value.nil? end end |
#password=(password) ⇒ Object
Set the password used to protect the key.
113 114 115 |
# File 'lib/rnp/op/generate.rb', line 113 def password=(password) Rnp.call_ffi(:rnp_op_generate_set_protection_password, @ptr, password) end |
#preferences=(prefs) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/rnp/op/generate.rb', line 163 def preferences=(prefs) %i{hashes compression ciphers}.each do |param| Rnp.call_ffi(pref_ffi_call(param, clear: true), @ptr) prefs[param].each do |pref| Rnp.call_ffi(pref_ffi_call(param, add: true), @ptr, pref.to_s) end end Rnp.call_ffi(:rnp_op_generate_set_pref_keyserver, @ptr, prefs[:key_server]) end |
#protection_mode=(mode) ⇒ Object
This is only valid for keys saved in the G10 format.
Set the protection mode for this key.
122 123 124 |
# File 'lib/rnp/op/generate.rb', line 122 def protection_mode=(mode) Rnp.call_ffi(:rnp_op_generate_set_protection_mode, @ptr, mode.to_s) end |
#qbits=(len) ⇒ Object
This is only valid for DSA keys.
Set the bit length of the q parameter for a DSA key.
69 70 71 |
# File 'lib/rnp/op/generate.rb', line 69 def qbits=(len) Rnp.call_ffi(:rnp_op_generate_set_dsa_qbits, @ptr, len) end |
#s2k_cipher=(cipher) ⇒ Object
Set the cipher used to protect the key.
106 107 108 |
# File 'lib/rnp/op/generate.rb', line 106 def s2k_cipher=(cipher) Rnp.call_ffi(:rnp_op_generate_set_protection_cipher, @ptr, cipher.to_s) end |
#s2k_hash=(hash) ⇒ Object
Set the hash algorithm used to protect the key.
92 93 94 |
# File 'lib/rnp/op/generate.rb', line 92 def s2k_hash=(hash) Rnp.call_ffi(:rnp_op_generate_set_protection_hash, @ptr, hash.to_s) end |
#s2k_iterations=(iter) ⇒ Object
Set the s2k iteration count used to protect the key.
99 100 101 |
# File 'lib/rnp/op/generate.rb', line 99 def s2k_iterations=(iter) Rnp.call_ffi(:rnp_op_generate_set_protection_iterations, @ptr, iter) end |
#usage=(usage) ⇒ Object
Set the usage for this key.
148 149 150 151 152 153 154 |
# File 'lib/rnp/op/generate.rb', line 148 def usage=(usage) usage = [usage] unless usage.respond_to?(:each) Rnp.call_ffi(:rnp_op_generate_clear_usage, @ptr) usage.each do |usg| Rnp.call_ffi(:rnp_op_generate_add_usage, @ptr, usg.to_s) end end |
#userid=(userid) ⇒ Object
Set the userid for this key.
140 141 142 |
# File 'lib/rnp/op/generate.rb', line 140 def userid=(userid) Rnp.call_ffi(:rnp_op_generate_set_userid, @ptr, userid) end |