Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 711 lines (595 sloc) 17.434 kb
3406379 @ueno Fixed comment.
ueno authored
1 # gpgme.rb -- OO interface to GPGME
bb638cc @ueno Rearrange the repository layout.
ueno authored
2 # Copyright (C) 2003,2006 Daiki Ueno
3
4 # This file is a part of Ruby-GPGME.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Emacs; see the file COPYING. If not, write to the
18 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 # Boston, MA 02110-1301, USA.
20
21 require 'gpgme_n'
22
23 module GPGME
24 class GpgmeError < StandardError
25 def initialize(error)
26 @error = error
27 end
28 attr_reader :error
29
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
30 def code
31 GPGME::gpgme_err_code(@error)
32 end
33
34 def source
35 GPGME::gpgme_err_source(@error)
36 end
37
bb638cc @ueno Rearrange the repository layout.
ueno authored
38 def message
39 GPGME::gpgme_strerror(@error)
40 end
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
41
42 class General < self; end
43 class InvalidValue < self; end
44 class UnusablePublicKey < self; end
45 class UnusableSecretKey < self; end
46 class NoData < self; end
47 class Conflict < self; end
48 class NotImplemented < self; end
49 class DecryptFailed < self; end
50 class BadPassphrase < self; end
51 class Canceled < self; end
52 class InvalidEngine < self; end
53 class AmbiguousName < self; end
54 class WrongKeyUsage < self; end
55 class CertificateRevoked < self; end
56 class CertificateExpired < self; end
57 class NoCRLKnown < self; end
58 class NoPolicyMatch < self; end
59 class NoSecretKey < self; end
60 class MissingCertificate < self; end
61 class BadCertificateChain < self; end
62 class UnsupportedAlgorithm < self; end
63 class BadSignature < self; end
64 class NoPublicKey < self; end
bb638cc @ueno Rearrange the repository layout.
ueno authored
65 end
66 Error = GpgmeError
67
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
68 private
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
69 def check_error(err)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
70 case GPGME::gpgme_err_code(err)
71 when GPG_ERR_EOF
bb638cc @ueno Rearrange the repository layout.
ueno authored
72 raise EOFError
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
73 when GPG_ERR_NO_ERROR
74 when GPG_ERR_GENERAL
75 raise GpgmeError::General.new(err)
76 when GPG_ERR_ENOMEM
77 raise Errno::ENOMEM
78 when GPG_ERR_INV_VALUE
79 raise GpgmeError::InvalidValue.new(err)
80 when GPG_ERR_UNUSABLE_PUBKEY
81 raise GpgmeError::UnusablePublicKey.new(err)
82 when GPG_ERR_UNUSABLE_SECKEY
83 raise GpgmeError::UnusableSecretKey.new(err)
84 when GPG_ERR_NO_DATA
85 raise GpgmeError::NoData.new(err)
86 when GPG_ERR_CONFLICT
87 raise GpgmeError::Conflict.new(err)
88 when GPG_ERR_NOT_IMPLEMENTED
89 raise GpgmeError::NotImplemented.new(err)
90 when GPG_ERR_DECRYPT_FAILED
91 raise GpgmeError::DecryptFailed.new(err)
92 when GPG_ERR_BAD_PASSPHRASE
93 raise GpgmeError::BadPassphrase.new(err)
94 when GPG_ERR_CANCELED
95 raise GpgmeError::Canceled.new(err)
96 when GPG_ERR_INV_ENGINE
97 raise GpgmeError::InvalidEngine.new(err)
98 when GPG_ERR_AMBIGUOUS_NAME
99 raise GpgmeError::AmbiguousName.new(err)
100 when GPG_ERR_WRONG_KEY_USAGE
101 raise GpgmeError::WrongKeyUsage.new(err)
102 when GPG_ERR_CERT_REVOKED
103 raise GpgmeError::CertificateRevoked.new(err)
104 when GPG_ERR_CERT_EXPIRED
105 raise GpgmeError::CertificateExpired.new(err)
106 when GPG_ERR_NO_CRL_KNOWN
107 raise GpgmeError::NoCRLKnown.new(err)
108 when GPG_ERR_NO_POLICY_MATCH
109 raise GpgmeError::NoPolicyMatch.new(err)
110 when GPG_ERR_NO_SECKEY
111 raise GpgmeError::NoSecretKey.new(err)
112 when GPG_ERR_MISSING_CERT
113 raise GpgmeError::MissingCertificate.new(err)
114 when GPG_ERR_BAD_CERT_CHAIN
115 raise GpgmeError::BadCertificateChain.new(err)
116 when GPG_ERR_UNSUPPORTED_ALGORITHM
117 raise GpgmeError::UnsupportedAlgorithm.new(err)
118 when GPG_ERR_BAD_SIGNATURE
119 raise GpgmeError::BadSignature.new(err)
120 when GPG_ERR_NO_PUBKEY
121 raise GpgmeError::NoPublicKey.new(err)
122 else
bb638cc @ueno Rearrange the repository layout.
ueno authored
123 raise GpgmeError.new(err)
124 end
125 end
126 module_function :check_error
127
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
128 public
bb638cc @ueno Rearrange the repository layout.
ueno authored
129 def engine_info
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
130 rinfo = Array.new
131 GPGME::gpgme_get_engine_info(rinfo)
132 rinfo
bb638cc @ueno Rearrange the repository layout.
ueno authored
133 end
134 module_function :engine_info
135
136 # A class for managing data buffers.
137 class GpgmeData
138 BLOCK_SIZE = 4096
139
140 # Create a new GpgmeData instance.
141 def self.new
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
142 rdh = Array.new
143 err = GPGME::gpgme_data_new(rdh)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
144 GPGME::check_error(err)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
145 rdh[0]
bb638cc @ueno Rearrange the repository layout.
ueno authored
146 end
147
148 # Create a new GpgmeData instance with internal buffer.
149 def self.new_from_mem(buf, copy = false)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
150 rdh = Array.new
151 err = GPGME::gpgme_data_new_from_mem(rdh, buf, buf.length, copy ? 1 : 0)
64da248 @ueno Fixed.
ueno authored
152 GPGME::check_error(err)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
153 rdh[0]
bb638cc @ueno Rearrange the repository layout.
ueno authored
154 end
155
a412fc5 @ueno Fixed cbs.
ueno authored
156 def self.new_from_file(filename, copy = false)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
157 rdh = Array.new
158 err = GPGME::gpgme_data_new_from_file(rdh, filename, copy ? 1 : 0)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
159 GPGME::check_error(err)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
160 rdh[0]
a412fc5 @ueno Fixed cbs.
ueno authored
161 end
162
f871e80 @ueno (GPGME::GpgmeData.new_from_fd): New constructor.
ueno authored
163 def self.new_from_fd(fd)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
164 rdh = Array.new
165 err = GPGME::gpgme_data_new_from_fd(rdh, fd)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
166 GPGME::check_error(err)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
167 rdh[0]
f871e80 @ueno (GPGME::GpgmeData.new_from_fd): New constructor.
ueno authored
168 end
169
a412fc5 @ueno Fixed cbs.
ueno authored
170 def self.new_from_cbs(cbs, hook_value = nil)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
171 rdh = Array.new
172 err = GPGME::gpgme_data_new_from_cbs(rdh, cbs, hook_value)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
173 GPGME::check_error(err)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
174 rdh[0]
a412fc5 @ueno Fixed cbs.
ueno authored
175 end
176
bb638cc @ueno Rearrange the repository layout.
ueno authored
177 def _read(len)
178 buf = "\x0" * len
179 nread = GPGME::gpgme_data_read(self, buf, len)
180 if nread > 0
181 buf[0 .. nread - 1]
182 elsif nread == 0
183 raise EOFError
184 else
185 raise 'error reading data'
186 end
187 end
188 private :_read
189
190 # Read bytes from this object. If len is supplied, it causes
191 # this method to read up to the number of bytes.
192 def read(len = nil)
193 if len
194 _read(len)
195 else
196 buf = ''
197 begin
198 loop do
199 buf << _read(BLOCK_SIZE)
200 end
201 rescue EOFError
202 buf
203 end
204 end
205 end
206
4f081f4 @ueno [] -> Array.new
ueno authored
207 # Reset the data pointer.
bb638cc @ueno Rearrange the repository layout.
ueno authored
208 def rewind
da57d44 @ueno (rb_s_gpgme_op_sign_result): New function.
ueno authored
209 seek(0)
4f081f4 @ueno [] -> Array.new
ueno authored
210 end
211
212 # Seek the data pointer.
213 def seek(offset, whence = IO::SEEK_SET)
214 GPGME::gpgme_data_seek(self, offset, IO::SEEK_SET)
bb638cc @ueno Rearrange the repository layout.
ueno authored
215 end
216
217 # Write bytes into this object. If len is supplied, it causes
218 # this method to write up to the number of bytes.
219 def write(buf, len = buf.length)
220 GPGME::gpgme_data_write(self, buf, len)
221 end
222
223 # Return the encoding of the underlying data.
224 def encoding
225 GPGME::gpgme_data_get_encoding(self)
226 end
227
228 # Set the encoding of the underlying data.
229 def encoding=(enc)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
230 err = gpgme_data_set_encoding(self, enc)
231 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
232 enc
233 end
234 end
235 Data = GpgmeData
236
237 class GpgmeEngineInfo
238 private_class_method :new
239
240 attr_reader :protocol, :file_name, :version, :req_version
241 end
242 EngineInfo = GpgmeEngineInfo
243
244 # A context within which all cryptographic operations are performed.
245 class GpgmeCtx
246 # Create a new GpgmeCtx object.
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
247 def self.new(attrs = Hash.new)
248 rctx = Array.new
249 err = GPGME::gpgme_new(rctx)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
250 GPGME::check_error(err)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
251 ctx = rctx[0]
252 attrs.each_pair do |key, value|
253 case key
254 when :protocol
255 ctx.protocol = value
256 when :armor
257 ctx.armor = value
258 when :textmode
259 ctx.textmode = value
260 when :keylist_mode
261 ctx.keylist_mode = value
262 end
263 end
264 ctx
bb638cc @ueno Rearrange the repository layout.
ueno authored
265 end
266
267 # Set the protocol used within this context.
268 def protocol=(proto)
64da248 @ueno Fixed.
ueno authored
269 err = GPGME::gpgme_set_protocol(self, proto)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
270 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
271 proto
272 end
273
274 # Return the protocol used within this context.
275 def protocol
276 GPGME::gpgme_get_protocol(self)
277 end
278
279 # Tell whether the output should be ASCII armored.
280 def armor=(yes)
281 GPGME::gpgme_set_armor(self, yes ? 1 : 0)
282 yes
283 end
284
285 # Return true if the output is ASCII armored.
286 def armor
287 GPGME::gpgme_get_armor(self)
288 end
289
290 # Tell whether canonical text mode should be used.
291 def textmode=(yes)
292 GPGME::gpgme_set_textmode(self, yes ? 1 : 0)
293 yes
294 end
295
296 # Return true if canonical text mode is enabled.
297 def textmode
298 GPGME::gpgme_get_textmode(self)
299 end
300
301 # Change the default behaviour of the key listing functions.
302 def keylist_mode=(mode)
303 GPGME::gpgme_set_keylist_mode(self, mode)
304 mode
305 end
306
307 # Returns the current key listing mode.
308 def keylist_mode
309 GPGME::gpgme_get_keylist_mode(self)
310 end
311
312 # Set the passphrase callback with given hook value.
313 def set_passphrase_cb(passfunc, hook_value = nil)
314 GPGME::gpgme_set_passphrase_cb(self, passfunc, hook_value)
315 end
316 # An array which contains a Proc and an Object.
317 # The former is the passphrase callback and the latter is hook value
318 # passed to it.
319 attr_reader :passphrase_cb
320
321 # Set the progress callback with given hook value.
322 def set_progress_cb(progfunc, hook_value = nil)
323 GPGME::gpgme_set_progress_cb(self, progfunc, hook_value)
324 end
325 # An array which contains a Proc and an Object.
326 # The former is the progress callback used when progress
327 # information is available and the latter is hook value
328 # passed to it.
329 attr_reader :progress_cb
330
331 # Initiates a key listing operation for given pattern.
332 # If pattern is nil, all available keys are returned.
333 # If secret_only is true, the list is restricted to secret keys only.
334 def keylist_start(pattern = nil, secret_only = false)
64da248 @ueno Fixed.
ueno authored
335 err = GPGME::gpgme_op_keylist_start(self, pattern, secret_only ? 1 : 0)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
336 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
337 end
338
339 # Returns the next key in the list created by a previous
340 # keylist_start operation.
341 def keylist_next
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
342 rkey = Array.new
343 err = GPGME::gpgme_op_keylist_next(self, rkey)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
344 GPGME::check_error(err)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
345 rkey[0]
bb638cc @ueno Rearrange the repository layout.
ueno authored
346 end
347
348 # End a pending key list operation.
349 def keylist_end
64da248 @ueno Fixed.
ueno authored
350 err = GPGME::gpgme_op_keylist_end(self)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
351 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
352 end
353
354 # Convenient method to iterate over keylist.
355 def each_keys(pattern = nil, secret_only = false, &block)
356 keylist_start(pattern, secret_only)
357 begin
358 loop do
359 yield keylist_next
360 end
361 rescue EOFError
362 # The last key in the list has already been returned.
363 rescue
364 keylist_end
365 end
366 end
367
368 # Get the key with the fingerprint.
369 def get_key(fpr, secret = false)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
370 rkey = Array.new
371 err = GPGME::gpgme_get_key(self, fpr, rkey, secret ? 1 : 0)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
372 GPGME::check_error(err)
e09f8cb @ueno Map GPG_ERR_* to exceptions.
ueno authored
373 rkey[0]
bb638cc @ueno Rearrange the repository layout.
ueno authored
374 end
375
376 # Generates a new key pair.
377 # If store is true, this method puts the key pair into the
378 # standard key ring.
379 def genkey(parms, store = false)
380 if store
381 pubkey, seckey = nil, nil
382 else
383 pubkey, seckey = GpgmeData.new, GpgmeData.new
384 end
64da248 @ueno Fixed.
ueno authored
385 err = GPGME::gpgme_op_genkey(self, parms, pubkey, seckey)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
386 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
387 [pubkey, seckey]
388 end
389
390 # Extracts the public keys of the recipients.
391 def export(recipients)
392 keydata = GpgmeData.new
64da248 @ueno Fixed.
ueno authored
393 err = GPGME::gpgme_op_export(self, recipients, keydata)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
394 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
395 keydata
396 end
397
398 # Add the keys in the data buffer to the key ring.
399 def import(keydata)
64da248 @ueno Fixed.
ueno authored
400 err = GPGME::gpgme_op_import(self, keydata)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
401 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
402 end
403
404 # Delete the key from the key ring.
405 # If allow_secret is false, only public keys are deleted,
406 # otherwise secret keys are deleted as well.
407 def delete(key, allow_secret = false)
64da248 @ueno Fixed.
ueno authored
408 err = GPGME::gpgme_op_delete(self, key, allow_secret ? 1 : 0)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
409 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
410 end
411
412 # Decrypt the ciphertext and return the plaintext.
413 def decrypt(cipher)
414 plain = GpgmeData.new
64da248 @ueno Fixed.
ueno authored
415 err = GPGME::gpgme_op_decrypt(self, cipher, plain)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
416 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
417 plain
418 end
419
420 # Verify that the signature in the data object is a valid signature.
421 def verify(sig, signed_text = nil, plain = nil)
422 plain = GpgmeData.new
64da248 @ueno Fixed.
ueno authored
423 err = GPGME::gpgme_op_verify(self, sig, signed_text, plain)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
424 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
425 plain
426 end
427
428 def verify_result
429 GPGME::gpgme_op_verify_result(self)
430 end
431
432 # Removes the list of signers from this object.
433 def clear_signers
64da248 @ueno Fixed.
ueno authored
434 GPGME::gpgme_signers_clear(self)
bb638cc @ueno Rearrange the repository layout.
ueno authored
435 end
436
437 # Add the key to the list of signers.
438 def add_signer(key)
64da248 @ueno Fixed.
ueno authored
439 err = GPGME::gpgme_signers_add(self, key)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
440 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
441 end
442
443 # Create a signature for the text in the data object.
444 def sign(plain, mode = GPGME::GPGME_SIG_MODE_NORMAL)
445 sig = GpgmeData.new
64da248 @ueno Fixed.
ueno authored
446 err = GPGME::gpgme_op_sign(self, plain, sig, mode)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
447 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
448 sig
449 end
450
451 # Encrypt the plaintext in the data object for the recipients and
452 # return the ciphertext.
453 def encrypt(recp, plain, flags = 0)
454 cipher = GpgmeData.new
64da248 @ueno Fixed.
ueno authored
455 err = GPGME::gpgme_op_encrypt(self, recp, flags, plain, cipher)
34e97a9 @ueno (gpgme_op_import_ext): Implemented in Ruby.
ueno authored
456 GPGME::check_error(err)
bb638cc @ueno Rearrange the repository layout.
ueno authored
457 cipher
458 end
459 end
460 Ctx = GpgmeCtx
461
462 # A public or secret key.
463 class GpgmeKey
464 private_class_method :new
465
466 attr_reader :keylist_mode, :protocol, :owner_trust
467 attr_reader :issuer_serial, :issuer_name, :chain_id
468 attr_reader :subkeys, :uids
469
470 def revoked?
471 @revoked == 1
472 end
473
474 def expired?
475 @expired == 1
476 end
477
478 def disabled?
479 @disabled == 1
480 end
481
482 def invalid?
483 @invalid == 1
484 end
485
486 def can_encrypt?
487 @can_encrypt == 1
488 end
489
490 def can_sign?
491 @can_sign == 1
492 end
493
494 def can_certify?
495 @can_certify == 1
496 end
497
498 def can_authenticate?
499 @can_authenticate == 1
500 end
501
502 def secret?
503 @secret == 1
504 end
505
506 # Return the value of the attribute of the key.
507 def [](what, idx = 0)
508 GPGME::gpgme_key_get_string_attr(self, what, idx)
509 end
510 end
511 Key = GpgmeKey
512
513 class GpgmeSubKey
514 private_class_method :new
515
516 attr_reader :pubkey_algo, :length, :keyid, :fpr
517
518 def revoked?
519 @revoked == 1
520 end
521
522 def expired?
523 @expired == 1
524 end
525
526 def disabled?
527 @disabled == 1
528 end
529
530 def invalid?
531 @invalid == 1
532 end
533
534 def can_encrypt?
535 @can_encrypt == 1
536 end
537
538 def can_sign?
539 @can_sign == 1
540 end
541
542 def can_certify?
543 @can_certify == 1
544 end
545
546 def can_authenticate?
547 @can_authenticate == 1
548 end
549
550 def secret?
551 @secret == 1
552 end
553
554 def timestamp
555 Time.new(@timestamp)
556 end
557
558 def expires
559 Time.new(@expires)
560 end
561 end
562 SubKey = GpgmeSubKey
563
564 class GpgmeUserId
565 private_class_method :new
566
567 attr_reader :validity, :uid, :name, :comment, :email, :signatures
568
569 def revoked?
570 @revoked == 1
571 end
572
573 def invalid?
574 @invalid == 1
575 end
576 end
577 UserId = GpgmeUserId
578
579 class GpgmeKeySig
580 private_class_method :new
581
582 attr_reader :pubkey_algo, :keyid
583
584 def revoked?
585 @revoked == 1
586 end
587
588 def expired?
589 @expired == 1
590 end
591
592 def invalid?
593 @invalid == 1
594 end
595
596 def exportable?
597 @exportable == 1
598 end
599
600 def timestamp
601 Time.at(@timestamp)
602 end
603
604 def expires
605 Time.at(@expires)
606 end
607 end
608 KeySig = GpgmeKeySig
609
610 class GpgmeVerifyResult
611 private_class_method :new
612
613 attr_reader :signatures
614 end
615 VerifyResult = GpgmeVerifyResult
616
617 class GpgmeSignature
618 private_class_method :new
619
620 attr_reader :summary, :fpr, :status, :notations
621
622 def timestamp
623 Time.at(@timestamp)
624 end
625
626 def exp_timestamp
627 Time.at(@exp_timestamp)
628 end
629 end
630 Signature = GpgmeSignature
4e646ff @ueno (GpgmeImportStatus): New class.
ueno authored
631
da57d44 @ueno (rb_s_gpgme_op_sign_result): New function.
ueno authored
632 class GpgmeDecryptResult
633 private_class_method :new
634
635 attr_reader :unsupported_algorithm, :wrong_key_usage
636 end
637 DecryptResult = GpgmeDecryptResult
638
639 class GpgmeSignResult
640 private_class_method :new
641
642 attr_reader :invalid_signers, :signatures
643 end
644 SignResult = GpgmeSignResult
645
646 class GpgmeEncryptResult
647 private_class_method :new
648
649 attr_reader :invalid_recipients
650 end
651 EncryptResult = GpgmeEncryptResult
652
653 class GpgmeInvalidKey
654 private_class_method :new
655
656 attr_reader :fpr, :reason
657 end
658 InvalidKey = GpgmeInvalidKey
659
660 class GpgmeNewSignature
661 private_class_method :new
662
663 attr_reader :type, :pubkey_algo, :hash_algo, :sig_class, :fpr
664
665 def timestamp
666 Time.at(@timestamp)
667 end
668 end
669 NewSignature = GpgmeNewSignature
670
4e646ff @ueno (GpgmeImportStatus): New class.
ueno authored
671 class GpgmeImportStatus
672 private_class_method :new
673
674 attr_reader :fpr, :result, :status
675 end
676 ImportStatus = GpgmeImportStatus
677
678 class GpgmeImportResult
679 private_class_method :new
680
681 attr_reader :considered, :no_user_id, :imported, :imported_rsa, :unchanged
682 attr_reader :new_user_ids, :new_sub_keys, :new_signatures, :new_revocations
683 attr_reader :secret_read, :secret_imported, :secret_unchanged
684 attr_reader :not_imported, :imports
685 end
da57d44 @ueno (rb_s_gpgme_op_sign_result): New function.
ueno authored
686 ImportResult = GpgmeImportStatus
687 end
4e646ff @ueno (GpgmeImportStatus): New class.
ueno authored
688
da57d44 @ueno (rb_s_gpgme_op_sign_result): New function.
ueno authored
689 module GPGME
4e646ff @ueno (GpgmeImportStatus): New class.
ueno authored
690 # Deprecated functions.
691 alias gpgme_trust_item_release gpgme_trust_item_unref
692
64da248 @ueno Fixed.
ueno authored
693 def gpgme_data_rewind(dh)
4e646ff @ueno (GpgmeImportStatus): New class.
ueno authored
694 begin
64da248 @ueno Fixed.
ueno authored
695 GPGME::gpgme_data_seek(dh, 0, IO::SEEK_SET)
4e646ff @ueno (GpgmeImportStatus): New class.
ueno authored
696 rescue SystemCallError => e
697 return e.errno
698 end
699 end
64da248 @ueno Fixed.
ueno authored
700 module_function :gpgme_data_rewind
4e646ff @ueno (GpgmeImportStatus): New class.
ueno authored
701
702 def gpgme_op_import_ext(ctx, keydata, nr)
703 err = GPGME::gpgme_op_import(ctx, keydata)
704 if GPGME::gpgme_err_code(err) == GPGME::GPG_ERR_NO_ERROR
705 result = GPGME::gpgme_op_import_result(ctx)
706 nr.push(result.considered)
707 end
708 end
64da248 @ueno Fixed.
ueno authored
709 module_function :gpgme_op_import_ext
bb638cc @ueno Rearrange the repository layout.
ueno authored
710 end
Something went wrong with that request. Please try again.