Class: Krypt::FFI::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/krypt/provider/ffi/provider.rb

Overview

A Krypt::Provider implementation for C-based implementations of the krypt Provider C API (krypt-provider.h). Provides the necessary “glue” to link the native implementation to the corresponding Ruby interfaces.

Instance Method Summary collapse

Constructor Details

#initialize(native_provider) ⇒ Provider

call-seq:

Krypt::FFI::Provider.new(native_provider) -> Provider

The native_provider is typically obtained by a separate FFI call to a publicly visible function offered by the implementation of the krypt Provider C API.



18
19
20
21
# File 'lib/krypt/provider/ffi/provider.rb', line 18

def initialize(native_provider)
  @provider = Krypt::FFI::ProviderAPI::ProviderInterface.new(native_provider)
  @provider[:init].call(@provider, nil)
end

Instance Method Details

#finalizeObject

call-seq:

provider.finalize -> nil

Depending on its implementation, it may be possible that a native krypt provider needs to do some cleanup before it is subject to GC. This method delegates to the native krypt_provider implementation of finalize. It is called whenever a Provider::delete is called to remove a specific provider.



61
62
63
# File 'lib/krypt/provider/ffi/provider.rb', line 61

def finalize
  @provider[:finalize].call(@provider)
end

#nameObject

call-seq:

provider.name -> String

Every Provider has a default name identifying it.



29
30
31
# File 'lib/krypt/provider/ffi/provider.rb', line 29

def name
  @provider[:name]
end

#new_service(klass, *args) ⇒ Object

call-seq:

provider.new_service(klass, [arg1, arg2, ...]) -> service

Provides access to the individual services offered by this provider. klass is the Ruby class of the desired service (e.g. Krypt::Digest), followed by optional additional arguments needed to create an instance of the service.

Example

digest = provider.new_service(Krypt::Digest, “SHA1”)



46
47
48
49
# File 'lib/krypt/provider/ffi/provider.rb', line 46

def new_service(klass, *args)
  return new_digest(*args) if klass == Krypt::Digest
  nil
end