Class: Botan::PK::Decrypt
- Inherits:
-
Object
- Object
- Botan::PK::Decrypt
- Defined in:
- lib/botan/pk/op/decrypt.rb
Overview
Public Key Decrypt Operation
See PrivateKey#decrypt for a simpler interface.
Class Method Summary collapse
- .destroy(ptr) ⇒ Object private
Instance Method Summary collapse
-
#decrypt(msg) ⇒ String
Decrypts the provided data.
-
#initialize(key:, padding: nil) ⇒ Decrypt
constructor
A new instance of Decrypt.
- #inspect ⇒ Object
Constructor Details
#initialize(key:, padding: nil) ⇒ Decrypt
Returns a new instance of Decrypt.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/botan/pk/op/decrypt.rb', line 21 def initialize(key:, padding: nil) padding ||= Botan::DEFAULT_EME unless key.instance_of?(PrivateKey) raise Botan::Error, 'Decryption requires an instance of PrivateKey' end ptr = FFI::MemoryPointer.new(:pointer) flags = 0 Botan.call_ffi(:botan_pk_op_decrypt_create, ptr, key.ptr, padding, flags) ptr = ptr.read_pointer if ptr.null? raise Botan::Error, 'botan_pk_op_decrypt_create returned NULL' end @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy)) 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.
38 39 40 |
# File 'lib/botan/pk/op/decrypt.rb', line 38 def self.destroy(ptr) LibBotan.botan_pk_op_decrypt_destroy(ptr) end |
Instance Method Details
#decrypt(msg) ⇒ String
Decrypts the provided data.
46 47 48 49 50 51 |
# File 'lib/botan/pk/op/decrypt.rb', line 46 def decrypt(msg) msg_buf = FFI::MemoryPointer.from_data(msg) Botan.call_ffi_with_buffer(lambda { |b, bl| LibBotan.botan_pk_op_decrypt(@ptr, b, bl, msg_buf, msg_buf.size) }) end |
#inspect ⇒ Object
53 54 55 |
# File 'lib/botan/pk/op/decrypt.rb', line 53 def inspect Botan.inspect_ptr(self) end |