Revision d9a90899
Added by Marc Dequènes over 14 years ago
- ID d9a90899035f78c7804e9a6cff7c8c7d707ce5b5
lib/tmail_gpg.rb | ||
---|---|---|
#
|
||
#++
|
||
|
||
class String
|
||
def is_7bit?
|
||
each_byte{|c| return false if c >= 128 }
|
||
true
|
||
end
|
||
end
|
||
|
||
# Attempt to handle PGP/GPG features in a RFC3156-compliant way
|
||
#
|
||
# notes: These methods have been designed to be able to sign, crypt,
|
||
... | ... | |
sig_data = GPGME::Data.new
|
||
# adds a final CRLF to respect OpenPGP convention (see note in chapter 5 of RFC3156)
|
||
prepared_data = self.to_rfc3156 + "\r\n"
|
||
raise 'TMail ERROR: data to sign MUST be in 7bit format, using Quotes-Printable or Base64 encoding !' unless prepared_data.is_7bit?
|
||
gpg.sign(GPGME::Data.new(prepared_data), sig_data, GPGME::SIG_MODE_DETACH)
|
||
hash_algo = GPGME.gpgme_op_sign_result(gpg).signatures.first.hash_algo
|
||
micalg = "pgp-" + GPGME.gpgme_hash_algo_name(hash_algo).downcase
|
Also available in: Unified diff
[fix] raise an error when trying to sign a not properly encoded content