Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ext/gpgme/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@
end

have_func('gpgme_op_export_keys')
have_const('GPGME_ENCRYPT_ALWAYS_TRUST', 'gpgme.h')
have_const('GPGME_ENCRYPT_NO_ENCRYPT_TO', 'gpgme.h')
have_const('GPGME_ENCRYPT_PREPARE', 'gpgme.h')
have_const('GPGME_ENCRYPT_EXPECT_SIGN', 'gpgme.h')
have_const('GPGME_ENCRYPT_NO_COMPRESS', 'gpgme.h')
have_const('GPGME_ENCRYPT_SYMMETRIC', 'gpgme.h')
have_const('GPGME_ENCRYPT_THROW_KEYIDS', 'gpgme.h')
have_const('GPGME_ENCRYPT_WRAP', 'gpgme.h')
have_const('GPGME_ENCRYPT_WANT_ADDRESS', 'gpgme.h')
have_const('GPGME_ENCRYPT_ARCHIVE', 'gpgme.h')
have_const('GPGME_ENCRYPT_FILE', 'gpgme.h')
have_const('GPGME_ENCRYPT_ADD_RECP', 'gpgme.h')
have_const('GPGME_ENCRYPT_CHG_RECP', 'gpgme.h')

create_makefile ('gpgme_n')

Expand Down
51 changes: 49 additions & 2 deletions ext/gpgme/gpgme_n.c
Original file line number Diff line number Diff line change
Expand Up @@ -3644,11 +3644,58 @@ Init_gpgme_n (void)
/* The available flags for gpgme_op_encrypt. */
rb_define_const (mGPGME, "GPGME_ENCRYPT_ALWAYS_TRUST",
INT2FIX(GPGME_ENCRYPT_ALWAYS_TRUST));
/* This flag was added in 1.2.0. */
#ifdef GPGME_ENCRYPT_NO_ENCRYPT_TO
#ifdef HAVE_CONST_GPGME_ENCRYPT_NO_ENCRYPT_TO
rb_define_const (mGPGME, "GPGME_ENCRYPT_NO_ENCRYPT_TO",
INT2FIX(GPGME_ENCRYPT_NO_ENCRYPT_TO));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_PREPARE
rb_define_const (mGPGME, "GPGME_ENCRYPT_PREPARE",
INT2FIX(GPGME_ENCRYPT_PREPARE));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_EXPECT_SIGN
rb_define_const (mGPGME, "GPGME_ENCRYPT_EXPECT_SIGN",
INT2FIX(GPGME_ENCRYPT_EXPECT_SIGN));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_NO_COMPRESS
rb_define_const (mGPGME, "GPGME_ENCRYPT_NO_COMPRESS",
INT2FIX(GPGME_ENCRYPT_NO_COMPRESS));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_UNSIGNED_INTEGRITY_CHECK
rb_define_const (mGPGME, "GPGME_ENCRYPT_UNSIGNED_INTEGRITY_CHECK",
INT2FIX(GPGME_ENCRYPT_UNSIGNED_INTEGRITY_CHECK));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_SYMMETRIC
rb_define_const (mGPGME, "GPGME_ENCRYPT_SYMMETRIC",
INT2FIX(GPGME_ENCRYPT_SYMMETRIC));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_THROW_KEYIDS
rb_define_const (mGPGME, "GPGME_ENCRYPT_THROW_KEYIDS",
INT2FIX(GPGME_ENCRYPT_THROW_KEYIDS));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_WRAP
rb_define_const (mGPGME, "GPGME_ENCRYPT_WRAP",
INT2FIX(GPGME_ENCRYPT_WRAP));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_WANT_ADDRESS
rb_define_const (mGPGME, "GPGME_ENCRYPT_WANT_ADDRESS",
INT2FIX(GPGME_ENCRYPT_WANT_ADDRESS));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_ARCHIVE
rb_define_const (mGPGME, "GPGME_ENCRYPT_ARCHIVE",
INT2FIX(GPGME_ENCRYPT_ARCHIVE));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_FILE
rb_define_const (mGPGME, "GPGME_ENCRYPT_FILE",
INT2FIX(GPGME_ENCRYPT_FILE));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_ADD_RECP
rb_define_const (mGPGME, "GPGME_ENCRYPT_ADD_RECP",
INT2FIX(GPGME_ENCRYPT_ADD_RECP));
#endif
#ifdef HAVE_CONST_GPGME_ENCRYPT_CHG_RECP
rb_define_const (mGPGME, "GPGME_ENCRYPT_CHG_RECP",
INT2FIX(GPGME_ENCRYPT_CHG_RECP));
#endif

/* Random number generation mode flags added in 2.0.0 */
#if defined(GPGME_VERSION_NUMBER) && GPGME_VERSION_NUMBER >= 0x020000
Expand Down
18 changes: 18 additions & 0 deletions lib/gpgme/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@ module GPGME
if defined?(GPGME_ENCRYPT_NO_ENCRYPT_TO)
ENCRYPT_NO_ENCRYPT_TO = GPGME_ENCRYPT_NO_ENCRYPT_TO
end
if defined?(GPGME_ENCRYPT_PREPARE)
ENCRYPT_PREPARE = GPGME_ENCRYPT_PREPARE
end
if defined?(GPGME_ENCRYPT_EXPECT_SIGN)
ENCRYPT_EXPECT_SIGN = GPGME_ENCRYPT_EXPECT_SIGN
end
if defined?(GPGME_ENCRYPT_NO_COMPRESS)
ENCRYPT_NO_COMPRESS = GPGME_ENCRYPT_NO_COMPRESS
end
if defined?(GPGME_ENCRYPT_UNSIGNED_INTEGRITY_CHECK)
ENCRYPT_UNSIGNED_INTEGRITY_CHECK = GPGME_ENCRYPT_UNSIGNED_INTEGRITY_CHECK
end
if defined?(GPGME_ENCRYPT_SYMMETRIC)
ENCRYPT_SYMMETRIC = GPGME_ENCRYPT_SYMMETRIC
end
if defined?(GPGME_ENCRYPT_THROW_KEYIDS)
ENCRYPT_THROW_KEYIDS = GPGME_ENCRYPT_THROW_KEYIDS
end
IMPORT_NEW = GPGME_IMPORT_NEW
IMPORT_SECRET = GPGME_IMPORT_SECRET
IMPORT_SIG = GPGME_IMPORT_SIG
Expand Down
65 changes: 65 additions & 0 deletions test/encryption_flags_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- encoding: utf-8 -*-
require 'test_helper'

describe 'GPGME Encryption Flags' do
it 'should expose ENCRYPT_ALWAYS_TRUST' do
assert_equal 1, GPGME::ENCRYPT_ALWAYS_TRUST
end

it 'should expose ENCRYPT_NO_ENCRYPT_TO if available' do
if defined?(GPGME::ENCRYPT_NO_ENCRYPT_TO)
assert GPGME::ENCRYPT_NO_ENCRYPT_TO.is_a?(Integer)
end
end

it 'should expose ENCRYPT_PREPARE if available' do
if defined?(GPGME::ENCRYPT_PREPARE)
assert GPGME::ENCRYPT_PREPARE.is_a?(Integer)
end
end

it 'should expose ENCRYPT_EXPECT_SIGN if available' do
if defined?(GPGME::ENCRYPT_EXPECT_SIGN)
assert GPGME::ENCRYPT_EXPECT_SIGN.is_a?(Integer)
end
end

it 'should expose ENCRYPT_NO_COMPRESS if available' do
if defined?(GPGME::ENCRYPT_NO_COMPRESS)
assert GPGME::ENCRYPT_NO_COMPRESS.is_a?(Integer)
end
end

it 'should expose ENCRYPT_UNSIGNED_INTEGRITY_CHECK if available' do
if defined?(GPGME::ENCRYPT_UNSIGNED_INTEGRITY_CHECK)
assert GPGME::ENCRYPT_UNSIGNED_INTEGRITY_CHECK.is_a?(Integer)
end
end

it 'should expose ENCRYPT_SYMMETRIC if available' do
if defined?(GPGME::ENCRYPT_SYMMETRIC)
assert GPGME::ENCRYPT_SYMMETRIC.is_a?(Integer)
end
end

it 'should expose ENCRYPT_THROW_KEYIDS if available' do
if defined?(GPGME::ENCRYPT_THROW_KEYIDS)
assert GPGME::ENCRYPT_THROW_KEYIDS.is_a?(Integer)
end
end

it 'should use different flag values for different flags' do
flags = []
flags << GPGME::ENCRYPT_ALWAYS_TRUST
flags << GPGME::ENCRYPT_NO_ENCRYPT_TO if defined?(GPGME::ENCRYPT_NO_ENCRYPT_TO)
flags << GPGME::ENCRYPT_PREPARE if defined?(GPGME::ENCRYPT_PREPARE)
flags << GPGME::ENCRYPT_EXPECT_SIGN if defined?(GPGME::ENCRYPT_EXPECT_SIGN)
flags << GPGME::ENCRYPT_NO_COMPRESS if defined?(GPGME::ENCRYPT_NO_COMPRESS)
flags << GPGME::ENCRYPT_UNSIGNED_INTEGRITY_CHECK if defined?(GPGME::ENCRYPT_UNSIGNED_INTEGRITY_CHECK)
flags << GPGME::ENCRYPT_SYMMETRIC if defined?(GPGME::ENCRYPT_SYMMETRIC)
flags << GPGME::ENCRYPT_THROW_KEYIDS if defined?(GPGME::ENCRYPT_THROW_KEYIDS)

# All flags should be unique
assert_equal flags.length, flags.uniq.length
end
end