Class: Rnp::Sign
- Inherits:
-
Object
- Object
- Rnp::Sign
- Defined in:
- lib/rnp/op/sign.rb
Overview
Signing operation
Instance Attribute Summary collapse
- #ptr ⇒ Object readonly private
Class Method Summary collapse
- .destroy(ptr) ⇒ Object private
- .set_signature_options(psig, hash:, creation_time:, expiration_time:) ⇒ Object private
Instance Method Summary collapse
-
#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.
-
#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 the signatures.
-
#initialize(ptr) ⇒ Sign
constructor
private
A new instance of Sign.
- #inspect ⇒ Object
-
#options=(armored: nil, compression: nil, hash: nil, creation_time: nil, expiration_time: nil) ⇒ Object
Set a group of options.
Constructor Details
#initialize(ptr) ⇒ Sign
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 Sign.
18 19 20 21 |
# File 'lib/rnp/op/sign.rb', line 18 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.
15 16 17 |
# File 'lib/rnp/op/sign.rb', line 15 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.
24 25 26 |
# File 'lib/rnp/op/sign.rb', line 24 def self.destroy(ptr) LibRnp.rnp_op_sign_destroy(ptr) end |
.set_signature_options(psig, hash:, creation_time:, expiration_time:) ⇒ 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.
130 131 132 133 134 135 136 |
# File 'lib/rnp/op/sign.rb', line 130 def self.(psig, hash:, creation_time:, expiration_time:) Rnp.call_ffi(:rnp_op_sign_signature_set_hash, psig, value) unless hash.nil? creation_time = creation_time.to_i if creation_time.is_a?(::Time) Rnp.call_ffi(:rnp_op_sign_signature_set_creation_time, psig, value) unless creation_time.nil? Rnp.call_ffi(:rnp_op_sign_signature_set_expiration_time, psig, value) unless expiration_time.nil? end |
Instance Method Details
#add_signer(signer, hash: nil, creation_time: nil, expiration_time: nil) ⇒ self
The optional (per-signature) options here are not supported by RNP internally at the time of this writing.
Add a signer.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rnp/op/sign.rb', line 42 def add_signer(signer, hash: nil, creation_time: nil, expiration_time: nil) pptr = FFI::MemoryPointer.new(:pointer) Rnp.call_ffi(:rnp_op_sign_add_signature, @ptr, signer.ptr, pptr) psig = pptr.read_pointer self.class.( psig, hash: hash, creation_time: creation_time, expiration_time: expiration_time ) end |
#armored=(armored) ⇒ Object
Set whether the output will be ASCII-armored.
74 75 76 |
# File 'lib/rnp/op/sign.rb', line 74 def armored=(armored) Rnp.call_ffi(:rnp_op_sign_set_armor, @ptr, armored) end |
#compression=(compression) ⇒ Object
Set the compression algorithm and level.
85 86 87 88 89 90 91 92 |
# File 'lib/rnp/op/sign.rb', line 85 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_sign_set_compression, @ptr, compression[:algorithm], compression[:level]) end |
#creation_time=(creation_time) ⇒ Object
Set the creation time for signatures.
106 107 108 109 |
# File 'lib/rnp/op/sign.rb', line 106 def creation_time=(creation_time) creation_time = creation_time.to_i if creation_time.is_a?(::Time) Rnp.call_ffi(:rnp_op_sign_set_creation_time, @ptr, creation_time) end |
#execute ⇒ void
This method returns an undefined value.
Execute the operation.
This should only be called once.
125 126 127 |
# File 'lib/rnp/op/sign.rb', line 125 def execute Rnp.call_ffi(:rnp_op_sign_execute, @ptr) end |
#expiration_time=(expiration_time) ⇒ Object
Set the expiration time for signatures.
116 117 118 |
# File 'lib/rnp/op/sign.rb', line 116 def expiration_time=(expiration_time) Rnp.call_ffi(:rnp_op_sign_set_expiration_time, @ptr, expiration_time) end |
#hash=(hash) ⇒ Object
Set the hash algorithm used for the signatures.
97 98 99 |
# File 'lib/rnp/op/sign.rb', line 97 def hash=(hash) Rnp.call_ffi(:rnp_op_sign_set_hash, @ptr, hash) end |
#inspect ⇒ Object
28 29 30 |
# File 'lib/rnp/op/sign.rb', line 28 def inspect Rnp.inspect_ptr(self) end |
#options=(armored: nil, compression: nil, hash: nil, creation_time: nil, expiration_time: nil) ⇒ Object
Set a group of options.
61 62 63 64 65 66 67 68 |
# File 'lib/rnp/op/sign.rb', line 61 def (armored: nil, compression: nil, hash: nil, creation_time: nil, expiration_time: nil) self.armored = armored unless armored.nil? self.compression = compression unless compression.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 |