Class: Rnp::Encrypt
- Inherits:
-
Object
- Object
- Rnp::Encrypt
- Defined in:
- lib/rnp/op/encrypt.rb
Overview
Encryption operation
Instance Method Summary collapse
-
#add_password(password, s2k_hash: nil, s2k_iterations: 0, s2k_cipher: nil) ⇒ self
Add a password.
-
#add_recipient(recipient) ⇒ self
Add a recipient.
-
#add_signer(signer, opts = {}) ⇒ self
Add a signer.
-
#aead=(mode) ⇒ Object
Set the AEAD algorithm for encryption.
-
#armored=(armored) ⇒ Object
Set whether the output will be ASCII-armored.
-
#cipher=(cipher) ⇒ Object
Set the cipher used to encrypt the input.
-
#compression=(compression) ⇒ Object
Set the compression algorithm and level.
-
#creation_time=(creation_time) ⇒ Object
Set the creation time for signatures.
-
#execute ⇒ void
Execute the operation.
-
#expiration_time=(expiration_time) ⇒ Object
Set the expiration time for signatures.
-
#hash=(hash) ⇒ Object
Set the hash algorithm used for calculating signatures.
- #inspect ⇒ Object
-
#options=(opts) ⇒ Object
Set a group of options.
Instance Method Details
#add_password(password, s2k_hash: nil, s2k_iterations: 0, s2k_cipher: nil) ⇒ self
This is a separate cipher from the one used to encrypt the main payload/stream (see #cipher=). This cipher may not be used in all circumstances. For example, when encrypting with only a password (no public keys), this cipher would generally not be used. When encrypting with a combination of one or more passwords and one or more public keys, this cipher would generally be used.
Add a password.
78 79 80 81 82 83 |
# File 'lib/rnp/op/encrypt.rb', line 78 def add_password(password, s2k_hash: nil, s2k_iterations: 0, s2k_cipher: nil) Rnp.call_ffi(:rnp_op_encrypt_add_password, @ptr, password, s2k_hash, s2k_iterations, s2k_cipher) self end |
#add_recipient(recipient) ⇒ self
Add a recipient.
38 39 40 41 |
# File 'lib/rnp/op/encrypt.rb', line 38 def add_recipient(recipient) Rnp.call_ffi(:rnp_op_encrypt_add_recipient, @ptr, recipient.ptr) self end |
#add_signer(signer, opts = {}) ⇒ self
Add a signer.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rnp/op/encrypt.rb', line 51 def add_signer(signer, opts = {}) pptr = FFI::MemoryPointer.new(:pointer) Rnp.call_ffi(:rnp_op_encrypt_add_signature, @ptr, signer.ptr, pptr) psig = pptr.read_pointer Sign.( psig, **opts, ) self end |
#aead=(mode) ⇒ Object
Set the AEAD algorithm for encryption.
139 140 141 |
# File 'lib/rnp/op/encrypt.rb', line 139 def aead=(mode) Rnp.call_ffi(:rnp_op_encrypt_set_aead, @ptr, mode.to_s) end |
#armored=(armored) ⇒ Object
Set whether the output will be ASCII-armored.
109 110 111 |
# File 'lib/rnp/op/encrypt.rb', line 109 def armored=(armored) Rnp.call_ffi(:rnp_op_encrypt_set_armor, @ptr, armored) end |
#cipher=(cipher) ⇒ Object
Set the cipher used to encrypt the input.
132 133 134 |
# File 'lib/rnp/op/encrypt.rb', line 132 def cipher=(cipher) Rnp.call_ffi(:rnp_op_encrypt_set_cipher, @ptr, cipher) end |
#compression=(compression) ⇒ Object
Set the compression algorithm and level.
120 121 122 123 124 125 126 127 |
# File 'lib/rnp/op/encrypt.rb', line 120 def compression=(compression) if !compression.is_a?(Hash) || Set.new(compression.keys) != Set.new(%i[algorithm level]) raise ArgumentError, 'Compression option must be of the form: {algorithm: \'zlib\', level: 5}' end Rnp.call_ffi(:rnp_op_encrypt_set_compression, @ptr, compression[:algorithm], compression[:level]) end |
#creation_time=(creation_time) ⇒ Object
This is only valid when there is one or more signer.
Set the creation time for signatures.
159 160 161 162 |
# File 'lib/rnp/op/encrypt.rb', line 159 def creation_time=(creation_time) creation_time = creation_time.to_i if creation_time.is_a?(::Time) Rnp.call_ffi(:rnp_op_encrypt_set_creation_time, @ptr, creation_time) end |
#execute ⇒ void
This method returns an undefined value.
Execute the operation.
This should only be called once.
181 182 183 |
# File 'lib/rnp/op/encrypt.rb', line 181 def execute Rnp.call_ffi(:rnp_op_encrypt_execute, @ptr) end |
#expiration_time=(expiration_time) ⇒ Object
This is only valid when there is one or more signer.
Set the expiration time for signatures.
172 173 174 |
# File 'lib/rnp/op/encrypt.rb', line 172 def expiration_time=(expiration_time) Rnp.call_ffi(:rnp_op_encrypt_set_expiration_time, @ptr, expiration_time) end |
#hash=(hash) ⇒ Object
This is only valid when there is one or more signer.
Set the hash algorithm used for calculating signatures.
148 149 150 |
# File 'lib/rnp/op/encrypt.rb', line 148 def hash=(hash) Rnp.call_ffi(:rnp_op_encrypt_set_hash, @ptr, hash) end |
#inspect ⇒ Object
30 31 32 |
# File 'lib/rnp/op/encrypt.rb', line 30 def inspect Rnp.inspect_ptr(self) end |
#options=(opts) ⇒ Object
Some options are related to signatures and will have no effect if
Set a group of options.
there are no signers.
97 98 99 100 101 102 103 |
# File 'lib/rnp/op/encrypt.rb', line 97 def (opts) %i{armored compression cipher aead hash creation_time expiration_time}.each do |prop| value = opts[prop] send("#{prop}=", value) unless value.nil? end end |