gpgme-ffi 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/edit.rb +77 -0
- data/examples/genkey.rb +55 -0
- data/examples/keylist.rb +7 -0
- data/examples/roundtrip.rb +42 -0
- data/examples/sign.rb +31 -0
- data/examples/verify.rb +8 -0
- data/ext/gpgme/Makefile.in +55 -0
- data/ext/gpgme/extconf.rb +8 -0
- data/ext/gpgme/extract_enums.rb +88 -0
- data/ext/gpgme/gpgme-1.3.1.tar.bz2 +0 -0
- data/ext/gpgme/libassuan-2.0.2.tar.bz2 +0 -0
- data/ext/gpgme/libgpg-error-1.10.tar.bz2 +0 -0
- data/ext/gpgme/libgpgme_gem.so +0 -0
- data/lib/gpgme/compat.rb +48 -0
- data/lib/gpgme/constants.rb +187 -0
- data/lib/gpgme/crypto.rb +357 -0
- data/lib/gpgme/ctx.rb +462 -0
- data/lib/gpgme/data.rb +189 -0
- data/lib/gpgme/engine.rb +76 -0
- data/lib/gpgme/error.rb +66 -0
- data/lib/gpgme/ffi/ctx.rb +36 -0
- data/lib/gpgme/ffi/data.rb +24 -0
- data/lib/gpgme/ffi/decrypt_result.rb +14 -0
- data/lib/gpgme/ffi/encrypt_result.rb +22 -0
- data/lib/gpgme/ffi/engine_info.rb +17 -0
- data/lib/gpgme/ffi/enums.rb +687 -0
- data/lib/gpgme/ffi/functions.rb +364 -0
- data/lib/gpgme/ffi/import_result.rb +35 -0
- data/lib/gpgme/ffi/import_status.rb +15 -0
- data/lib/gpgme/ffi/invalid_key.rb +14 -0
- data/lib/gpgme/ffi/key.rb +60 -0
- data/lib/gpgme/ffi/key_sig.rb +20 -0
- data/lib/gpgme/ffi/library.rb +279 -0
- data/lib/gpgme/ffi/meta.rb +57 -0
- data/lib/gpgme/ffi/new_signature.rb +18 -0
- data/lib/gpgme/ffi/sig_notation.rb +12 -0
- data/lib/gpgme/ffi/sign_result.rb +33 -0
- data/lib/gpgme/ffi/signature.rb +35 -0
- data/lib/gpgme/ffi/sub_key.rb +27 -0
- data/lib/gpgme/ffi/trust_item.rb +31 -0
- data/lib/gpgme/ffi/user_id.rb +30 -0
- data/lib/gpgme/ffi/verify_result.rb +22 -0
- data/lib/gpgme/ffi.rb +22 -0
- data/lib/gpgme/io_callbacks.rb +21 -0
- data/lib/gpgme/key.rb +242 -0
- data/lib/gpgme/key_common.rb +43 -0
- data/lib/gpgme/key_sig.rb +35 -0
- data/lib/gpgme/misc.rb +66 -0
- data/lib/gpgme/signature.rb +85 -0
- data/lib/gpgme/sub_key.rb +58 -0
- data/lib/gpgme/user_id.rb +20 -0
- data/lib/gpgme/version.rb +3 -0
- data/lib/gpgme.rb +106 -0
- data/test/crypto_test.rb +246 -0
- data/test/ctx_test.rb +432 -0
- data/test/data_test.rb +129 -0
- data/test/files/testkey_pub.gpg +52 -0
- data/test/files/testkey_sec.gpg +54 -0
- data/test/gpgme_test.rb +12 -0
- data/test/key_test.rb +209 -0
- data/test/signature_test.rb +52 -0
- data/test/sub_key_test.rb +48 -0
- data/test/support/resources.rb +516 -0
- data/test/test_helper.rb +84 -0
- metadata +203 -0
data/lib/gpgme/engine.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module GPGME
|
2
|
+
|
3
|
+
##
|
4
|
+
# Convenience methods to check different aspects of the gpg system
|
5
|
+
# installation.
|
6
|
+
module Engine
|
7
|
+
class << self
|
8
|
+
|
9
|
+
##
|
10
|
+
# Verify that the engine implementing the protocol +proto+ is installed in
|
11
|
+
# the system. Can be one of +PROTOCOL_OpenPGP+ or +PROTOCOL_CMS+.
|
12
|
+
#
|
13
|
+
# @return [Boolean] true if the engine is installed.
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# GPGME::Engine.check_version(GPGME::PROTOCOL_OpenPGP) # => true
|
17
|
+
#
|
18
|
+
def check_version(proto)
|
19
|
+
err = GPGME::gpgme_engine_check_version(proto)
|
20
|
+
exc = GPGME::error_to_exception(err)
|
21
|
+
!exc
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Return an array of {GPGME::EngineInfo} structures of enabled engines.
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# GPGME::Engine.info.first
|
29
|
+
# # => #<GPGME::EngineInfo:0x00000100d4fbd8
|
30
|
+
# @file_name="/usr/local/bin/gpg",
|
31
|
+
# @protocol=0,
|
32
|
+
# @req_version="1.3.0",
|
33
|
+
# @version="1.4.11">
|
34
|
+
#
|
35
|
+
def info
|
36
|
+
rinfo = []
|
37
|
+
GPGME::gpgme_get_engine_info(rinfo)
|
38
|
+
rinfo
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Change the default configuration of the crypto engine implementing
|
43
|
+
# protocol +proto+.
|
44
|
+
#
|
45
|
+
# @param proto
|
46
|
+
# Can be one of +PROTOCOL_OpenPGP+ or +PROTOCOL_CMS+.
|
47
|
+
#
|
48
|
+
# @param file_name
|
49
|
+
# The file name of the executable program implementing the protocol.
|
50
|
+
#
|
51
|
+
# @param home_dir
|
52
|
+
# The directory name of the configuration directory.
|
53
|
+
#
|
54
|
+
# @example
|
55
|
+
# GPGME::Engine.set
|
56
|
+
#
|
57
|
+
def set_info(proto, file_name, home_dir)
|
58
|
+
err = GPGME::gpgme_set_engine_info(proto, file_name, home_dir)
|
59
|
+
exc = GPGME::error_to_exception(err)
|
60
|
+
raise exc if exc
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Sets the home dir for the configuration options. This way one could,
|
65
|
+
# for example, load the keys from a customized keychain.
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
# GPGME::Engine.home_dir = '/tmp'
|
69
|
+
#
|
70
|
+
def home_dir=(home_dir)
|
71
|
+
current = info.first
|
72
|
+
set_info current.protocol, current.file_name, home_dir
|
73
|
+
end
|
74
|
+
end # class << self
|
75
|
+
end # class Engine
|
76
|
+
end # module GPGME
|
data/lib/gpgme/error.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module GPGME
|
2
|
+
class Error < StandardError
|
3
|
+
def initialize(error)
|
4
|
+
@error = error
|
5
|
+
end
|
6
|
+
attr_reader :error
|
7
|
+
|
8
|
+
# Return the error code.
|
9
|
+
#
|
10
|
+
# The error code indicates the type of an error, or the reason why
|
11
|
+
# an operation failed.
|
12
|
+
def code
|
13
|
+
GPGME::gpgme_err_code(@error)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return the error source.
|
17
|
+
#
|
18
|
+
# The error source has not a precisely defined meaning. Sometimes
|
19
|
+
# it is the place where the error happened, sometimes it is the
|
20
|
+
# place where an error was encoded into an error value. Usually
|
21
|
+
# the error source will give an indication to where to look for
|
22
|
+
# the problem. This is not always true, but it is attempted to
|
23
|
+
# achieve this goal.
|
24
|
+
def source
|
25
|
+
GPGME::gpgme_err_source(@error)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Return a description of the error code.
|
29
|
+
def message
|
30
|
+
GPGME::gpgme_strerror(@error)
|
31
|
+
end
|
32
|
+
|
33
|
+
class General < self; end
|
34
|
+
class InvalidValue < self; end
|
35
|
+
class UnusablePublicKey < self
|
36
|
+
attr_accessor :keys
|
37
|
+
end
|
38
|
+
class UnusableSecretKey < self
|
39
|
+
attr_accessor :keys
|
40
|
+
end
|
41
|
+
class NoData < self; end
|
42
|
+
class Conflict < self; end
|
43
|
+
class NotImplemented < self; end
|
44
|
+
class DecryptFailed < self; end
|
45
|
+
class BadPassphrase < self; end
|
46
|
+
class Canceled < self; end
|
47
|
+
class InvalidEngine < self; end
|
48
|
+
class AmbiguousName < self; end
|
49
|
+
class WrongKeyUsage < self
|
50
|
+
attr_accessor :key_usage
|
51
|
+
end
|
52
|
+
class CertificateRevoked < self; end
|
53
|
+
class CertificateExpired < self; end
|
54
|
+
class NoCRLKnown < self; end
|
55
|
+
class NoPolicyMatch < self; end
|
56
|
+
class NoSecretKey < self; end
|
57
|
+
class MissingCertificate < self; end
|
58
|
+
class BadCertificateChain < self; end
|
59
|
+
class UnsupportedAlgorithm < self
|
60
|
+
attr_accessor :algorithm
|
61
|
+
end
|
62
|
+
class BadSignature < self; end
|
63
|
+
class NoPublicKey < self; end
|
64
|
+
class InvalidVersion < self; end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module GPGME
|
2
|
+
class Ctx
|
3
|
+
attr_accessor :context_passphrase_callback
|
4
|
+
attr_accessor :context_progress_callback
|
5
|
+
|
6
|
+
class Pointer < FFI::AutoPointer
|
7
|
+
def self.release(ptr)
|
8
|
+
GPGME::Library.gpgme_release ptr
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.new_from_struct(pointer)
|
13
|
+
instance = allocate
|
14
|
+
|
15
|
+
instance.instance_exec do
|
16
|
+
@context_passphrase_callback = [ nil, nil, nil ]
|
17
|
+
@context_progress_callback = [ nil, nil, nil ]
|
18
|
+
|
19
|
+
@ptr = Pointer.new pointer
|
20
|
+
end
|
21
|
+
|
22
|
+
instance
|
23
|
+
end
|
24
|
+
|
25
|
+
def release_pointer
|
26
|
+
raise ArgumentError, "released ctx" if @ptr.nil?
|
27
|
+
@ptr.free
|
28
|
+
@ptr = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def context_pointer
|
32
|
+
raise "context is already released" if @ptr.nil?
|
33
|
+
@ptr
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module GPGME
|
2
|
+
class Data
|
3
|
+
class Pointer < FFI::AutoPointer
|
4
|
+
def self.release(ptr)
|
5
|
+
GPGME::Library.gpgme_data_release ptr
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.new_from_struct(pointer, cbs = nil)
|
10
|
+
instance = allocate
|
11
|
+
|
12
|
+
instance.instance_exec do
|
13
|
+
@ptr = Pointer.new pointer
|
14
|
+
@cbs = cbs
|
15
|
+
end
|
16
|
+
|
17
|
+
instance
|
18
|
+
end
|
19
|
+
|
20
|
+
def context_pointer
|
21
|
+
@ptr
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GPGME
|
2
|
+
class DecryptResult
|
3
|
+
def self.new_from_struct(struct)
|
4
|
+
instance = allocate
|
5
|
+
|
6
|
+
instance.instance_exec do
|
7
|
+
@unsupported_algorithm = struct[:unsupported_algorithm]
|
8
|
+
@wrong_key_usage = (struct[:flags] >> 0) & 1
|
9
|
+
end
|
10
|
+
|
11
|
+
instance
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module GPGME
|
2
|
+
class EncryptResult
|
3
|
+
def self.new_from_struct(struct)
|
4
|
+
instance = allocate
|
5
|
+
|
6
|
+
instance.instance_exec do
|
7
|
+
@invalid_recipients = []
|
8
|
+
|
9
|
+
pointer = struct[:invalid_recipients]
|
10
|
+
until pointer.null?
|
11
|
+
key = Library::InvalidKey.new pointer
|
12
|
+
|
13
|
+
@invalid_recipients << InvalidKey.new_from_struct(key)
|
14
|
+
|
15
|
+
pointer = key[:next]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
instance
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module GPGME
|
2
|
+
class EngineInfo
|
3
|
+
def self.new_from_struct(info)
|
4
|
+
instance = allocate
|
5
|
+
|
6
|
+
instance.instance_exec do
|
7
|
+
@protocol = info[:protocol]
|
8
|
+
@file_name = info[:file_name]
|
9
|
+
@version = info[:version]
|
10
|
+
@req_version = info[:req_version]
|
11
|
+
@home_dir = info[:home_dir]
|
12
|
+
end
|
13
|
+
|
14
|
+
instance
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|