Class: Rnp::Encrypt
- Inherits:
-
Object
- Object
- Rnp::Encrypt
- Defined in:
- lib/rnp/op/encrypt.rb
Overview
Encryption operation
Instance Attribute Summary collapse
- #ptr ⇒ Object readonly private
Class Method Summary collapse
- .destroy(ptr) ⇒ Object private
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, hash: nil, creation_time: nil, expiration_time: nil) ⇒ self
Add a signer.
-
#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.
-
#initialize(ptr) ⇒ Encrypt
constructor
private
A new instance of Encrypt.
- #inspect ⇒ Object
-
#options=(armored: nil, compression: nil, cipher: nil, hash: nil, creation_time: nil, expiration_time: nil) ⇒ Object
Set a group of options.
Constructor Details
#initialize(ptr) ⇒ Encrypt
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Encrypt.
20 21 22 23 |
# File 'lib/rnp/op/encrypt.rb', line 20 def initialize(ptr) raise Rnp::Error, 'NULL pointer' if ptr.null? @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy)) end |
Instance Attribute Details
#ptr ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 |
# File 'lib/rnp/op/encrypt.rb', line 17 def ptr @ptr end |
Class Method Details
.destroy(ptr) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
26 27 28 |
# File 'lib/rnp/op/encrypt.rb', line 26 def self.destroy(ptr) LibRnp.rnp_op_encrypt_destroy(ptr) end |
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.
79 80 81 82 83 84 |
# File 'lib/rnp/op/encrypt.rb', line 79 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, hash: nil, creation_time: nil, expiration_time: nil) ⇒ self
Add a signer.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rnp/op/encrypt.rb', line 50 def add_signer(signer, hash: nil, creation_time: nil, expiration_time: nil) pptr = FFI::MemoryPointer.new(:pointer) Rnp.call_ffi(:rnp_op_encrypt_add_signature, @ptr, signer.ptr, pptr) psig = pptr.read_pointer Sign.( psig, hash: hash, creation_time: creation_time, expiration_time: expiration_time ) self end |
#armored=(armored) ⇒ Object
Set whether the output will be ASCII-armored.
111 112 113 |
# File 'lib/rnp/op/encrypt.rb', line 111 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.
134 135 136 |
# File 'lib/rnp/op/encrypt.rb', line 134 def cipher=(cipher) Rnp.call_ffi(:rnp_op_encrypt_set_cipher, @ptr, cipher) end |
#compression=(compression) ⇒ Object
Set the compression algorithm and level.
122 123 124 125 126 127 128 129 |
# File 'lib/rnp/op/encrypt.rb', line 122 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.
154 155 156 157 |
# File 'lib/rnp/op/encrypt.rb', line 154 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.
176 177 178 |
# File 'lib/rnp/op/encrypt.rb', line 176 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.
167 168 169 |
# File 'lib/rnp/op/encrypt.rb', line 167 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.
143 144 145 |
# File 'lib/rnp/op/encrypt.rb', line 143 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=(armored: nil, compression: nil, cipher: nil, hash: nil, creation_time: nil, expiration_time: nil) ⇒ 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 104 105 |
# File 'lib/rnp/op/encrypt.rb', line 97 def (armored: nil, compression: nil, cipher: nil, hash: nil, creation_time: nil, expiration_time: nil) self.armored = armored unless armored.nil? self.compression = compression unless compression.nil? self.cipher = cipher unless cipher.nil? self.hash = hash unless hash.nil? self.creation_time = creation_time unless creation_time.nil? self.expiration_time = expiration_time unless expiration_time.nil? end |