gpgme-ffi 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/examples/edit.rb +77 -0
  2. data/examples/genkey.rb +55 -0
  3. data/examples/keylist.rb +7 -0
  4. data/examples/roundtrip.rb +42 -0
  5. data/examples/sign.rb +31 -0
  6. data/examples/verify.rb +8 -0
  7. data/ext/gpgme/Makefile.in +55 -0
  8. data/ext/gpgme/extconf.rb +8 -0
  9. data/ext/gpgme/extract_enums.rb +88 -0
  10. data/ext/gpgme/gpgme-1.3.1.tar.bz2 +0 -0
  11. data/ext/gpgme/libassuan-2.0.2.tar.bz2 +0 -0
  12. data/ext/gpgme/libgpg-error-1.10.tar.bz2 +0 -0
  13. data/ext/gpgme/libgpgme_gem.so +0 -0
  14. data/lib/gpgme/compat.rb +48 -0
  15. data/lib/gpgme/constants.rb +187 -0
  16. data/lib/gpgme/crypto.rb +357 -0
  17. data/lib/gpgme/ctx.rb +462 -0
  18. data/lib/gpgme/data.rb +189 -0
  19. data/lib/gpgme/engine.rb +76 -0
  20. data/lib/gpgme/error.rb +66 -0
  21. data/lib/gpgme/ffi/ctx.rb +36 -0
  22. data/lib/gpgme/ffi/data.rb +24 -0
  23. data/lib/gpgme/ffi/decrypt_result.rb +14 -0
  24. data/lib/gpgme/ffi/encrypt_result.rb +22 -0
  25. data/lib/gpgme/ffi/engine_info.rb +17 -0
  26. data/lib/gpgme/ffi/enums.rb +687 -0
  27. data/lib/gpgme/ffi/functions.rb +364 -0
  28. data/lib/gpgme/ffi/import_result.rb +35 -0
  29. data/lib/gpgme/ffi/import_status.rb +15 -0
  30. data/lib/gpgme/ffi/invalid_key.rb +14 -0
  31. data/lib/gpgme/ffi/key.rb +60 -0
  32. data/lib/gpgme/ffi/key_sig.rb +20 -0
  33. data/lib/gpgme/ffi/library.rb +279 -0
  34. data/lib/gpgme/ffi/meta.rb +57 -0
  35. data/lib/gpgme/ffi/new_signature.rb +18 -0
  36. data/lib/gpgme/ffi/sig_notation.rb +12 -0
  37. data/lib/gpgme/ffi/sign_result.rb +33 -0
  38. data/lib/gpgme/ffi/signature.rb +35 -0
  39. data/lib/gpgme/ffi/sub_key.rb +27 -0
  40. data/lib/gpgme/ffi/trust_item.rb +31 -0
  41. data/lib/gpgme/ffi/user_id.rb +30 -0
  42. data/lib/gpgme/ffi/verify_result.rb +22 -0
  43. data/lib/gpgme/ffi.rb +22 -0
  44. data/lib/gpgme/io_callbacks.rb +21 -0
  45. data/lib/gpgme/key.rb +242 -0
  46. data/lib/gpgme/key_common.rb +43 -0
  47. data/lib/gpgme/key_sig.rb +35 -0
  48. data/lib/gpgme/misc.rb +66 -0
  49. data/lib/gpgme/signature.rb +85 -0
  50. data/lib/gpgme/sub_key.rb +58 -0
  51. data/lib/gpgme/user_id.rb +20 -0
  52. data/lib/gpgme/version.rb +3 -0
  53. data/lib/gpgme.rb +106 -0
  54. data/test/crypto_test.rb +246 -0
  55. data/test/ctx_test.rb +432 -0
  56. data/test/data_test.rb +129 -0
  57. data/test/files/testkey_pub.gpg +52 -0
  58. data/test/files/testkey_sec.gpg +54 -0
  59. data/test/gpgme_test.rb +12 -0
  60. data/test/key_test.rb +209 -0
  61. data/test/signature_test.rb +52 -0
  62. data/test/sub_key_test.rb +48 -0
  63. data/test/support/resources.rb +516 -0
  64. data/test/test_helper.rb +84 -0
  65. metadata +203 -0
@@ -0,0 +1,279 @@
1
+ require 'ffi'
2
+
3
+ module GPGME::Library
4
+ extend FFI::Library
5
+
6
+ ffi_lib 'libgpgme.so.11'
7
+
8
+ class SigNotation < FFI::Struct
9
+ layout :next, :pointer,
10
+ :name, :string,
11
+ :value, :string,
12
+ :name_len, :int,
13
+ :value_len, :int,
14
+ :flags, :uint,
15
+ # packed: human_readable, critical, _unused
16
+ :bits, :uint
17
+ end
18
+
19
+ class Signature < FFI::Struct
20
+ layout :next, :pointer,
21
+ :summary, :int,
22
+ :fpr, :string,
23
+ :status, :uint,
24
+ :notations, :pointer,
25
+ :timestamp, :ulong,
26
+ :exp_timestamp, :ulong,
27
+ # packed: wrong_key_usage, pka_trust, chain_model, _unused
28
+ :flags, :uint,
29
+ :validity, :uint,
30
+ :validity_reason, :uint,
31
+ :pubkey_algo, :uint,
32
+ :hash_algo, :uint,
33
+ :pka_address, :string
34
+ end
35
+
36
+ class EngineInfo < FFI::Struct
37
+ layout :next, :pointer,
38
+ :protocol, :uint,
39
+ :file_name, :string,
40
+ :version, :string,
41
+ :req_version, :string,
42
+ :home_dir, :string
43
+ end
44
+
45
+ class Callbacks < FFI::Struct
46
+ layout :read, :pointer,
47
+ :write, :pointer,
48
+ :seek, :pointer,
49
+ :release, :pointer
50
+ end
51
+
52
+ class ImportStatus < FFI::Struct
53
+ layout :next, :pointer,
54
+ :fpr, :string,
55
+ :result, :uint,
56
+ :status, :uint
57
+ end
58
+
59
+ class ImportResult < FFI::Struct
60
+ layout :considered, :int,
61
+ :no_user_id, :int,
62
+ :imported, :int,
63
+ :imported_rsa, :int,
64
+ :unchanged, :int,
65
+ :new_user_ids, :int,
66
+ :new_sub_keys, :int,
67
+ :new_signatures, :int,
68
+ :new_revocations, :int,
69
+ :secret_read, :int,
70
+ :secret_imported, :int,
71
+ :secret_unchanged, :int,
72
+ :skipped_new_keys, :int,
73
+ :not_imported, :int,
74
+ :imports, :pointer
75
+ end
76
+
77
+ class TrustItem < FFI::Struct
78
+ layout :_refs, :uint,
79
+ :keyid, :string,
80
+ :_keyid, [ :uint8, 16 + 1 ],
81
+ :type, :int,
82
+ :level, :int,
83
+ :owner_trust, :string,
84
+ :_owner_trust, [ :uint8, 2 ],
85
+ :validity, :string,
86
+ :_validity, [ :uint8, 2 ],
87
+ :name, :string
88
+ end
89
+
90
+ class Key < FFI::Struct
91
+ layout :_refs, :uint,
92
+ # packed: revoked, expired, disabled, invalid, can_encrypt, can_sign, can_certify,
93
+ # secret, can_authenticate, is_qualified, _unused
94
+ :flags, :uint,
95
+ :protocol, :uint,
96
+ :issuer_serial, :string,
97
+ :issuer_name, :string,
98
+ :chain_id, :string,
99
+ :owner_trust, :uint,
100
+ :subkeys, :pointer,
101
+ :uids, :pointer,
102
+ :_last_subkey, :pointer,
103
+ :_last_uid, :pointer,
104
+ :keylist_mode, :uint
105
+ end
106
+
107
+ class SubKey < FFI::Struct
108
+ layout :next, :pointer,
109
+ # packed, see above + is_cardkey
110
+ :flags, :uint,
111
+ :pubkey_algo, :uint,
112
+ :length, :uint,
113
+ :keyid, :string,
114
+ :_keyid, [ :uint8, 16 + 1],
115
+ :fpr, :string,
116
+ :timestamp, :long,
117
+ :expires, :long,
118
+ :card_number, :string
119
+ end
120
+
121
+ class UserID < FFI::Struct
122
+ layout :next, :pointer,
123
+ # packed: revoked, invalid
124
+ :flags, :uint,
125
+ :validity, :uint,
126
+ :uid, :string,
127
+ :name, :string,
128
+ :email, :string,
129
+ :comment, :string,
130
+ :signatures, :pointer,
131
+ :_last_keysig, :pointer
132
+ end
133
+
134
+ class KeySig < FFI::Struct
135
+ layout :next, :pointer,
136
+ # packed: revoked, expired, invalid, exportable
137
+ :flags, :uint,
138
+ :pubkey_algo, :uint,
139
+ :keyid, :string,
140
+ :_keyid, [ :uint8, 16 + 1 ],
141
+ :timestamp, :long,
142
+ :expires, :long,
143
+ :status, :uint,
144
+ :_obsolete_class, :uint,
145
+ :uid, :string,
146
+ :name, :string,
147
+ :email, :string,
148
+ :comment, :string,
149
+ :sig_class, :uint,
150
+ :notations, :pointer,
151
+ :_last_notation, :pointer
152
+ end
153
+
154
+ class DecryptResult < FFI::Struct
155
+ layout :unsupported_algorithm, :string,
156
+ # packed: wrong_key_usage
157
+ :flags, :uint,
158
+ :recipients, :pointer,
159
+ :file_name, :string
160
+ end
161
+
162
+ class VerifyResult < FFI::Struct
163
+ layout :signatures, :pointer,
164
+ :file_name, :string
165
+ end
166
+
167
+ class SignResult < FFI::Struct
168
+ layout :invalid_signers, :pointer,
169
+ :signatures, :pointer
170
+ end
171
+
172
+ class InvalidKey < FFI::Struct
173
+ layout :next, :pointer,
174
+ :fpr, :string,
175
+ :reason, :uint
176
+ end
177
+
178
+ class EncryptResult < FFI::Struct
179
+ layout :invalid_recipients, :pointer
180
+ end
181
+
182
+ class NewSignature < FFI::Struct
183
+ layout :next, :pointer,
184
+ :type, :uint,
185
+ :pubkey_algo, :uint,
186
+ :hash_algo, :uint,
187
+ :_obsolete_class, :ulong,
188
+ :timestamp, :long,
189
+ :fpr, :string,
190
+ :_obsolete_class_2, :uint,
191
+ :sig_class, :uint
192
+ end
193
+
194
+ attach_function :gpgme_check_version_internal, [ :buffer_in, :size_t ], :string
195
+ attach_function :gpgme_engine_check_version, [ :uint ], :uint
196
+ attach_function :gpgme_get_engine_info, [ :pointer ], :uint
197
+ attach_function :gpgme_set_engine_info, [ :uint, :buffer_in, :buffer_in ], :uint
198
+ attach_function :gpgme_pubkey_algo_name, [ :uint ], :string
199
+ attach_function :gpgme_hash_algo_name, [ :uint ], :string
200
+ attach_function :gpgme_strerror, [ :uint ], :string
201
+ attach_function :gpgme_data_new, [ :pointer ], :uint
202
+ attach_function :gpgme_data_new_from_mem, [ :pointer, :buffer_in, :size_t, :int ], :uint
203
+ attach_function :gpgme_data_new_from_fd, [ :pointer, :int ], :uint
204
+ attach_function :gpgme_data_new_from_cbs, [ :pointer, :pointer, :pointer ], :uint
205
+ attach_function :gpgme_data_release, [ :pointer ], :void
206
+ attach_function :gpgme_data_read, [ :pointer, :buffer_out, :size_t ], :ssize_t
207
+ attach_function :gpgme_data_write, [ :pointer, :buffer_in, :size_t ], :ssize_t
208
+ attach_function :gpgme_data_seek, [ :pointer, :off_t, :int ], :off_t
209
+ attach_function :gpgme_data_get_encoding, [ :pointer ], :uint
210
+ attach_function :gpgme_data_set_encoding, [ :pointer, :uint ], :uint
211
+ attach_function :gpgme_new, [ :pointer ], :uint
212
+ attach_function :gpgme_release, [ :pointer ], :void
213
+ attach_function :gpgme_set_protocol, [ :pointer, :uint ], :uint
214
+ attach_function :gpgme_get_protocol, [ :pointer ], :uint
215
+ attach_function :gpgme_set_armor, [ :pointer, :uint ], :void
216
+ attach_function :gpgme_get_armor, [ :pointer ], :uint
217
+ attach_function :gpgme_set_textmode, [ :pointer, :uint ], :void
218
+ attach_function :gpgme_get_textmode, [ :pointer ], :uint
219
+ attach_function :gpgme_set_include_certs, [ :pointer, :uint ], :void
220
+ attach_function :gpgme_get_include_certs, [ :pointer ], :uint
221
+ attach_function :gpgme_set_keylist_mode, [ :pointer, :uint ], :uint
222
+ attach_function :gpgme_get_keylist_mode, [ :pointer ], :uint
223
+ attach_function :gpgme_set_passphrase_cb, [ :pointer, :pointer, :pointer ], :void
224
+ attach_function :gpgme_get_passphrase_cb, [ :pointer, :pointer, :pointer ], :void
225
+ attach_function :gpgme_set_progress_cb, [ :pointer, :pointer, :pointer ], :void
226
+ attach_function :gpgme_get_progress_cb, [ :pointer, :pointer, :pointer ], :void
227
+ attach_function :gpgme_set_locale, [ :pointer, :int, :buffer_in ], :uint
228
+ attach_function :gpgme_op_keylist_start, [ :pointer, :buffer_in, :int ], :uint
229
+ attach_function :gpgme_op_keylist_ext_start, [ :pointer, :buffer_in, :int, :int ], :uint
230
+ attach_function :gpgme_op_keylist_next, [ :pointer, :buffer_out ], :uint
231
+ attach_function :gpgme_op_keylist_end, [ :pointer ], :uint
232
+ attach_function :gpgme_get_key, [ :pointer, :buffer_in, :buffer_out, :int ], :uint
233
+ attach_function :gpgme_key_ref, [ :pointer ], :void
234
+ attach_function :gpgme_key_unref, [ :pointer ], :void
235
+ attach_function :gpgme_op_genkey, [ :pointer, :buffer_in, :pointer, :pointer ], :uint
236
+ attach_function :gpgme_op_genkey_start, [ :pointer, :buffer_in, :pointer, :pointer ], :uint
237
+ attach_function :gpgme_op_export, [ :pointer, :buffer_in, :int, :pointer ], :uint
238
+ attach_function :gpgme_op_export_start, [ :pointer, :buffer_in, :int, :pointer ], :uint
239
+ attach_function :gpgme_op_export_ext, [ :pointer, :buffer_in, :int, :pointer ], :uint
240
+ attach_function :gpgme_op_export_ext_start, [ :pointer, :buffer_in, :int, :pointer ], :uint
241
+ attach_function :gpgme_op_export_keys, [ :pointer, :buffer_in, :int, :pointer ], :uint
242
+ attach_function :gpgme_op_export_keys_start, [ :pointer, :buffer_in, :int, :pointer ], :uint
243
+ attach_function :gpgme_op_import, [ :pointer, :pointer ], :uint
244
+ attach_function :gpgme_op_import_start, [ :pointer, :pointer ], :uint
245
+ attach_function :gpgme_op_import_keys, [ :pointer, :buffer_in ], :uint
246
+ attach_function :gpgme_op_import_keys_start, [ :pointer, :buffer_in ], :uint
247
+ attach_function :gpgme_op_import_result, [ :pointer ], :pointer
248
+ attach_function :gpgme_op_delete, [ :pointer, :pointer, :int ], :uint
249
+ attach_function :gpgme_op_delete_start, [ :pointer, :pointer, :int ], :uint
250
+ attach_function :gpgme_op_edit, [ :pointer, :pointer, :pointer, :pointer, :pointer ], :uint
251
+ attach_function :gpgme_op_edit_start, [ :pointer, :pointer, :pointer, :pointer, :pointer ], :uint
252
+ attach_function :gpgme_op_card_edit, [ :pointer, :pointer, :pointer, :pointer, :pointer ], :uint
253
+ attach_function :gpgme_op_card_edit_start, [ :pointer, :pointer, :pointer, :pointer, :pointer ], :uint
254
+ attach_function :gpgme_op_trustlist_start, [ :pointer, :buffer_in, :int ], :uint
255
+ attach_function :gpgme_op_trustlist_next, [ :pointer, :buffer_out ], :uint
256
+ attach_function :gpgme_op_trustlist_end, [ :pointer ], :uint
257
+ attach_function :gpgme_trust_item_ref, [ :pointer ], :void
258
+ attach_function :gpgme_trust_item_unref, [ :pointer ], :void
259
+ attach_function :gpgme_op_decrypt, [ :pointer, :pointer, :pointer ], :uint
260
+ attach_function :gpgme_op_decrypt_start, [ :pointer, :pointer, :pointer ], :uint
261
+ attach_function :gpgme_op_decrypt_result, [ :pointer ], :pointer
262
+ attach_function :gpgme_op_verify, [ :pointer, :pointer, :pointer, :pointer ], :uint
263
+ attach_function :gpgme_op_verify_start, [ :pointer, :pointer, :pointer, :pointer ], :uint
264
+ attach_function :gpgme_op_verify_result, [ :pointer ], :pointer
265
+ attach_function :gpgme_op_decrypt_verify, [ :pointer, :pointer, :pointer ], :uint
266
+ attach_function :gpgme_op_decrypt_verify_start, [ :pointer, :pointer, :pointer ], :uint
267
+ attach_function :gpgme_signers_clear, [ :pointer ], :void
268
+ attach_function :gpgme_signers_add, [ :pointer, :pointer ], :uint
269
+ attach_function :gpgme_signers_enum, [ :pointer, :int ], :pointer
270
+ attach_function :gpgme_op_sign, [ :pointer, :pointer, :pointer, :uint ], :uint
271
+ attach_function :gpgme_op_sign_start, [ :pointer, :pointer, :pointer, :uint ], :uint
272
+ attach_function :gpgme_op_sign_result, [ :pointer ], :pointer
273
+ attach_function :gpgme_op_encrypt, [ :pointer, :buffer_in, :uint, :pointer, :pointer ], :uint
274
+ attach_function :gpgme_op_encrypt_start, [ :pointer, :buffer_in, :uint, :pointer, :pointer ], :uint
275
+ attach_function :gpgme_op_encrypt_sign, [ :pointer, :buffer_in, :uint, :pointer, :pointer ], :uint
276
+ attach_function :gpgme_op_encrypt_sign_start, [ :pointer, :buffer_in, :uint, :pointer, :pointer ], :uint
277
+ attach_function :gpgme_op_encrypt_result, [ :pointer ], :pointer
278
+ attach_function :gpgme_wait, [ :pointer, :buffer_out, :int ], :pointer
279
+ end
@@ -0,0 +1,57 @@
1
+ module GPGME
2
+ module Meta
3
+ def self.ffize_value(arg)
4
+ if arg.respond_to?(:context_pointer)
5
+ arg.context_pointer
6
+
7
+ elsif arg.kind_of?(String)
8
+ FFI::MemoryPointer.from_string arg
9
+
10
+ elsif arg.kind_of?(Array)
11
+ buf = FFI::Buffer.new :pointer, arg.length + 1
12
+
13
+ pointers = arg.map { |item| ffize_value item }
14
+ pointers << FFI::Pointer::NULL
15
+ buf.put_array_of_pointer 0, pointers
16
+
17
+ buf
18
+
19
+ elsif arg.nil?
20
+ FFI::Pointer::NULL
21
+ else
22
+ arg
23
+ end
24
+ end
25
+
26
+ def self.define_ffi_forwarder(*functions)
27
+ functions.each do |id|
28
+ GPGME.define_singleton_method(id) do |*args|
29
+ args = args.map! { |arg| Meta.ffize_value arg }
30
+
31
+ GPGME::Library.send id, *args
32
+ end
33
+ end
34
+ end
35
+
36
+ def self.common_gpgme_edit(context, key, ruby_callback, ruby_handle, data, receiver)
37
+ callback = FFI::Function.new(:uint, [ :pointer, :uint, :string, :int ]) do |handle, status, args, fd|
38
+ ruby_callback.call ruby_handle, status, args, fd
39
+
40
+ GPGME.gpgme_err_make GPGME::GPG_ERR_SOURCE_USER_1, GPGME::GPG_ERR_NO_ERROR
41
+ end
42
+
43
+ context.edit_callback = callback
44
+
45
+ receiver.call context.context_pointer, key.context_pointer, callback, FFI::Pointer::NULL,
46
+ data.context_pointer
47
+ end
48
+
49
+ def self.define_op_edit(*functions)
50
+ functions.each do |function|
51
+ GPGME.define_singleton_method(function) do |*args|
52
+ common_gpgme_edit *args, GPGME::Library.method(function)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ module GPGME
2
+ class NewSignature
3
+ def self.new_from_struct(struct)
4
+ instance = allocate
5
+
6
+ instance.instance_exec do
7
+ @type = struct[:type]
8
+ @pubkey_algo = struct[:pubkey_algo]
9
+ @hash_algo = struct[:hash_algo]
10
+ @sig_class = struct[:sig_class]
11
+ @timestamp = struct[:timestamp]
12
+ @fpr = struct[:fpr]
13
+ end
14
+
15
+ instance
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module GPGME
2
+ class SigNotation
3
+ def self.new_from_struct(struct)
4
+ instance = allocate
5
+
6
+ instance.instance_exec do
7
+ @name = struct[:name]
8
+ @value = struct[:value]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ module GPGME
2
+ class SignResult
3
+ def self.new_from_struct(struct)
4
+ instance = allocate
5
+
6
+ instance.instance_exec do
7
+ @invalid_signers = []
8
+
9
+ pointer = struct[:invalid_signers]
10
+ until pointer.null?
11
+ key = Library::InvalidKey.new pointer
12
+
13
+ @invalid_signers << InvalidKey.new_from_struct(key)
14
+
15
+ pointer = key[:next]
16
+ end
17
+
18
+ @signatures = []
19
+
20
+ pointer = struct[:signatures]
21
+ until pointer.null?
22
+ signature = Library::NewSignature.new pointer
23
+
24
+ @signatures << NewSignature.new_from_struct(signature)
25
+
26
+ pointer = key[:next]
27
+ end
28
+ end
29
+
30
+ instance
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ module GPGME
2
+ class Signature
3
+ def self.new_from_struct(struct)
4
+ instance = allocate
5
+
6
+ instance.instance_exec do
7
+ @summary = struct[:summary]
8
+ @fpr = struct[:fpr]
9
+ @status = struct[:status]
10
+
11
+ @notations = []
12
+
13
+ pointer = struct[:notations]
14
+ until pointer.null?
15
+ notation = Library::SigNotation.new pointer
16
+
17
+ @notations << SigNotation.new_from_struct(notation)
18
+
19
+ pointer = notation[:next]
20
+ end
21
+
22
+ @timestamp = struct[:timestamp]
23
+ @exp_timestamp = struct[:exp_timestamp]
24
+ @wrong_key_usage = (struct[:flags] >> 0) & 1
25
+ @pka_trust = (struct[:flags] >> 1) & 3
26
+ @chain_model = (struct[:flags] >> 3) & 1
27
+ @validity = struct[:validity]
28
+ @validity_reason = struct[:validity_reason]
29
+ @pka_address = struct[:pka_address]
30
+ end
31
+
32
+ instance
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ module GPGME
2
+ class SubKey
3
+ def self.new_from_struct(struct)
4
+ instance = allocate
5
+
6
+ instance.instance_exec do
7
+ @revoked = (struct[:flags] >> 0) & 1
8
+ @expired = (struct[:flags] >> 1) & 1
9
+ @disabled = (struct[:flags] >> 2) & 1
10
+ @invalid = (struct[:flags] >> 3) & 1
11
+ @can_encrypt = (struct[:flags] >> 4) & 1
12
+ @can_sign = (struct[:flags] >> 5) & 1
13
+ @can_certify = (struct[:flags] >> 6) & 1
14
+ @secret = (struct[:flags] >> 7) & 1
15
+ @can_authenticate = (struct[:flags] >> 8) & 1
16
+ @pubkey_algo = struct[:pubkey_algo]
17
+ @length = struct[:length]
18
+ @keyid = struct[:keyid]
19
+ @fpr = struct[:fpr]
20
+ @timestamp = struct[:timestamp]
21
+ @expires = struct[:expires]
22
+ end
23
+
24
+ instance
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ module GPGME
2
+ class TrustItem
3
+ class Pointer < FFI::AutoPointer
4
+ def self.release(ptr)
5
+ GPGME::Library.gpgme_trust_item_unref ptr
6
+ end
7
+ end
8
+
9
+ def self.new_from_struct(pointer)
10
+ instance = allocate
11
+
12
+ instance.instance_exec do
13
+ @ptr = Pointer.new pointer
14
+
15
+ structure = Library::TrustItem.new @ptr
16
+ @keyid = structure[:keyid]
17
+ @type = structure[:type]
18
+ @level = structure[:level]
19
+ @owner_trust = structure[:owner_trust]
20
+ @validity = structure[:validity]
21
+ @name = structure[:name]
22
+ end
23
+
24
+ instance
25
+ end
26
+
27
+ def context_pointer
28
+ @ptr
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ module GPGME
2
+ class UserID
3
+ def self.new_from_struct(struct)
4
+ instance = allocate
5
+
6
+ instance.instance_exec do
7
+ @revoked = (struct[:flags] >> 0) & 1
8
+ @invalid = (struct[:flags] >> 1) & 1
9
+ @validity = struct[:validity]
10
+ @uid = struct[:uid]
11
+ @name = struct[:name]
12
+ @email = struct[:email]
13
+ @comment = struct[:comment]
14
+
15
+ @signatures = []
16
+ pointer = struct[:signatures]
17
+
18
+ until pointer.null?
19
+ signature = Library::KeySig
20
+
21
+ @signatures << KeySig.new_from_struct(signature)
22
+
23
+ pointer = signature[:next]
24
+ end
25
+ end
26
+
27
+ instance
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ module GPGME
2
+ class VerifyResult
3
+ def self.new_from_struct(struct)
4
+ instance = allocate
5
+
6
+ instance.instance_exec do
7
+ @signatures = []
8
+
9
+ pointer = struct[:signatures]
10
+ until pointer.null?
11
+ signature = Library::Signature.new pointer
12
+
13
+ @signatures << Signature.new_from_struct(signature)
14
+
15
+ pointer = signature[:next]
16
+ end
17
+ end
18
+
19
+ instance
20
+ end
21
+ end
22
+ end
data/lib/gpgme/ffi.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "gpgme/ffi/enums"
2
+ require "gpgme/ffi/library"
3
+ require "gpgme/ffi/engine_info"
4
+ require "gpgme/ffi/ctx"
5
+ require "gpgme/ffi/data"
6
+ require "gpgme/ffi/key"
7
+ require "gpgme/ffi/sub_key"
8
+ require "gpgme/ffi/user_id"
9
+ require "gpgme/ffi/key_sig"
10
+ require "gpgme/ffi/decrypt_result"
11
+ require "gpgme/ffi/verify_result"
12
+ require "gpgme/ffi/sign_result"
13
+ require "gpgme/ffi/encrypt_result"
14
+ require "gpgme/ffi/signature"
15
+ require "gpgme/ffi/sig_notation"
16
+ require "gpgme/ffi/trust_item"
17
+ require "gpgme/ffi/invalid_key"
18
+ require "gpgme/ffi/new_signature"
19
+ require "gpgme/ffi/import_result"
20
+ require "gpgme/ffi/import_status"
21
+ require "gpgme/ffi/meta"
22
+ require "gpgme/ffi/functions"
@@ -0,0 +1,21 @@
1
+ module GPGME
2
+ class IOCallbacks
3
+ def initialize(io)
4
+ @io = io
5
+ end
6
+
7
+ def read(hook, length)
8
+ @io.read(length)
9
+ end
10
+
11
+ def write(hook, buffer, length)
12
+ @io.write(buffer[0 .. length])
13
+ end
14
+
15
+ def seek(hook, offset, whence)
16
+ return @io.pos if offset == 0 && whence == IO::SEEK_CUR
17
+ @io.seek(offset, whence)
18
+ @io.pos
19
+ end
20
+ end
21
+ end