lib/rnp/ffi/librnp.rb in rnp-1.0.2 vs lib/rnp/ffi/librnp.rb in rnp-1.0.3
- old
+ new
@@ -2,10 +2,12 @@
# (c) 2018 Ribose Inc.
require 'ffi'
+require 'rnp/error'
+
# @api private
module LibRnp
extend FFI::Library
ffi_lib %w[rnp-0 rnp]
@@ -285,9 +287,44 @@
:uint32
attach_function :rnp_identifier_iterator_destroy,
%i[pointer],
:uint32
+ # some newer APIs that may not be present
+ {
+ # key export
+ rnp_key_export: [%i[pointer pointer uint32], :uint32],
+ # enarmor/dearmor
+ rnp_enarmor: [%i[pointer pointer pointer], :uint32],
+ rnp_dearmor: [%i[pointer pointer], :uint32],
+ # versioning
+ rnp_version_string: [%i[], :string],
+ rnp_version_string_full: [%i[], :string],
+ rnp_version: [%i[], :uint32],
+ rnp_version_for: [%i[uint32 uint32 uint32], :uint32],
+ rnp_version_major: [%i[uint32], :uint32],
+ rnp_version_minor: [%i[uint32], :uint32],
+ rnp_version_patch: [%i[uint32], :uint32]
+ }.each do |name, signature|
+ present = ffi_libraries[0].find_function(name.to_s)
+ if !present
+ class_eval do
+ define_singleton_method(name) do |*|
+ raise Rnp::FeatureNotAvailableError, name
+ end
+ end
+ else
+ attach_function name, signature[0], signature[1]
+ end
+ class_eval do
+ const_set("HAVE_#{name.upcase}", present)
+ end
+ end
+
+ RNP_KEY_EXPORT_ARMORED = (1 << 0)
+ RNP_KEY_EXPORT_PUBLIC = (1 << 1)
+ RNP_KEY_EXPORT_SECRET = (1 << 2)
+ RNP_KEY_EXPORT_SUBKEYS = (1 << 3)
RNP_LOAD_SAVE_PUBLIC_KEYS = (1 << 0)
RNP_LOAD_SAVE_SECRET_KEYS = (1 << 1)
RNP_JSON_PUBLIC_MPIS = (1 << 0)