cipherstash-pg 1.0.0.beta.1-x86_64-linux → 1.0.0.beta.3-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.appveyor.yml +42 -0
- data/.gems +6 -0
- data/.gemtest +0 -0
- data/.github/workflows/binary-gems.yml +117 -0
- data/.github/workflows/source-gem.yml +137 -0
- data/.gitignore +19 -0
- data/.hgsigs +34 -0
- data/.hgtags +41 -0
- data/.irbrc +23 -0
- data/.pryrc +23 -0
- data/.tm_properties +21 -0
- data/.travis.yml +49 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +45 -0
- data/{History.rdoc → History.md} +168 -153
- data/README.ja.md +266 -0
- data/README.md +272 -0
- data/Rakefile +65 -104
- data/Rakefile.cross +298 -0
- data/certs/larskanis-2023.pem +24 -0
- data/cipherstash-pg.gemspec +0 -0
- data/lib/2.7/pg_ext.so +0 -0
- data/lib/3.0/pg_ext.so +0 -0
- data/lib/3.1/pg_ext.so +0 -0
- data/lib/3.2/pg_ext.so +0 -0
- data/lib/cipherstash-pg/basic_type_map_based_on_result.rb +11 -0
- data/lib/cipherstash-pg/basic_type_map_for_queries.rb +113 -0
- data/lib/cipherstash-pg/basic_type_map_for_results.rb +30 -0
- data/lib/cipherstash-pg/basic_type_registry.rb +206 -0
- data/lib/cipherstash-pg/binary_decoder.rb +21 -0
- data/lib/cipherstash-pg/coder.rb +82 -0
- data/lib/cipherstash-pg/connection.rb +467 -0
- data/lib/cipherstash-pg/constants.rb +3 -0
- data/lib/cipherstash-pg/exceptions.rb +19 -0
- data/lib/cipherstash-pg/result.rb +22 -0
- data/lib/cipherstash-pg/text_decoder.rb +43 -0
- data/lib/cipherstash-pg/text_encoder.rb +67 -0
- data/lib/cipherstash-pg/tuple.rb +24 -0
- data/lib/cipherstash-pg/type_map_by_column.rb +11 -0
- data/lib/cipherstash-pg/version.rb +3 -0
- data/lib/cipherstash-pg.rb +56 -11
- data/lib/libpq.so.5 +0 -0
- data/misc/openssl-pg-segfault.rb +15 -25
- data/misc/postgres/Rakefile +13 -20
- data/misc/postgres/lib/postgres.rb +10 -14
- data/misc/ruby-pg/Rakefile +13 -20
- data/misc/ruby-pg/lib/ruby/pg.rb +10 -14
- data/rakelib/task_extension.rb +17 -31
- data/sample/array_insert.rb +7 -20
- data/sample/async_api.rb +54 -96
- data/sample/async_copyto.rb +20 -35
- data/sample/async_mixed.rb +22 -50
- data/sample/check_conn.rb +8 -20
- data/sample/copydata.rb +18 -68
- data/sample/copyfrom.rb +26 -78
- data/sample/copyto.rb +10 -16
- data/sample/cursor.rb +9 -19
- data/sample/disk_usage_report.rb +89 -174
- data/sample/issue-119.rb +45 -93
- data/sample/losample.rb +48 -66
- data/sample/minimal-testcase.rb +6 -17
- data/sample/notify_wait.rb +21 -67
- data/sample/pg_statistics.rb +100 -281
- data/sample/replication_monitor.rb +119 -218
- data/sample/test_binary_values.rb +14 -30
- data/sample/wal_shipper.rb +199 -431
- data/sample/warehouse_partitions.rb +157 -307
- data/translation/.po4a-version +7 -0
- data/translation/po/all.pot +875 -0
- data/translation/po/ja.po +868 -0
- data/translation/po4a.cfg +9 -0
- metadata +50 -30
- data/README.ja.rdoc +0 -13
- data/README.rdoc +0 -233
- data/lib/pg/basic_type_map_based_on_result.rb +0 -47
- data/lib/pg/basic_type_map_for_queries.rb +0 -193
- data/lib/pg/basic_type_map_for_results.rb +0 -81
- data/lib/pg/basic_type_registry.rb +0 -301
- data/lib/pg/binary_decoder.rb +0 -23
- data/lib/pg/coder.rb +0 -104
- data/lib/pg/connection.rb +0 -878
- data/lib/pg/constants.rb +0 -12
- data/lib/pg/exceptions.rb +0 -18
- data/lib/pg/result.rb +0 -43
- data/lib/pg/text_decoder.rb +0 -46
- data/lib/pg/text_encoder.rb +0 -59
- data/lib/pg/tuple.rb +0 -30
- data/lib/pg/type_map_by_column.rb +0 -16
- data/lib/pg/version.rb +0 -4
- data/lib/pg.rb +0 -55
- data/vendor/database-extensions/install.sql +0 -317
- data/vendor/database-extensions/uninstall.sql +0 -20
data/Rakefile
CHANGED
@@ -1,115 +1,76 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
TESTDIR
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
CLEAN.include( TESTDIR.to_s )
|
27
|
-
CLEAN.include( PKGDIR.to_s, TMPDIR.to_s )
|
28
|
-
CLEAN.include "lib/*/libpq.dll"
|
29
|
-
CLEAN.include "lib/pg_ext.*"
|
30
|
-
CLEAN.include "lib/pg/postgresql_lib_path.rb"
|
31
|
-
|
32
|
-
# load 'Rakefile.cross'
|
33
|
-
|
1
|
+
require("rbconfig")
|
2
|
+
require("pathname")
|
3
|
+
require("tmpdir")
|
4
|
+
require("rake/extensiontask")
|
5
|
+
require("rake/clean")
|
6
|
+
require("rspec/core/rake_task")
|
7
|
+
require("bundler")
|
8
|
+
require("bundler/gem_helper")
|
9
|
+
BASEDIR = Pathname("(string)").dirname
|
10
|
+
SPECDIR = (BASEDIR + "spec")
|
11
|
+
LIBDIR = (BASEDIR + "lib")
|
12
|
+
EXTDIR = (BASEDIR + "ext")
|
13
|
+
PKGDIR = (BASEDIR + "pkg")
|
14
|
+
TMPDIR = (BASEDIR + "tmp")
|
15
|
+
TESTDIR = (BASEDIR + "tmp_test_*")
|
16
|
+
DLEXT = RbConfig::CONFIG["DLEXT"]
|
17
|
+
EXT = (LIBDIR + "pg_ext.#{DLEXT}")
|
18
|
+
GEMSPEC = "cipherstash-pg.gemspec"
|
19
|
+
CLEAN.include(TESTDIR.to_s)
|
20
|
+
CLEAN.include(PKGDIR.to_s, TMPDIR.to_s)
|
21
|
+
CLEAN.include("lib/*/libpq.dll")
|
22
|
+
CLEAN.include("lib/pg_ext.*")
|
23
|
+
CLEAN.include("lib/pg/postgresql_lib_path.rb")
|
24
|
+
load("Rakefile.cross")
|
34
25
|
Bundler::GemHelper.install_tasks
|
35
26
|
$gem_spec = Bundler.load_gemspec(GEMSPEC)
|
36
|
-
|
37
|
-
|
38
|
-
task :maint do
|
39
|
-
ENV['MAINTAINER_MODE'] = 'yes'
|
40
|
-
end
|
41
|
-
|
42
|
-
# Rake-compiler task
|
27
|
+
desc("Turn on warnings and debugging in the build.")
|
28
|
+
task(:maint) { ENV["MAINTAINER_MODE"] = "yes" }
|
43
29
|
Rake::ExtensionTask.new do |ext|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
# "--with-pg-lib=#{lib.static_postgresql_libdir}",
|
58
|
-
# # libpq-fe.h resides in src/interfaces/libpq/ before make install
|
59
|
-
# "--with-opt-include=#{lib.static_postgresql_libdir}",
|
60
|
-
# ]
|
61
|
-
# }
|
62
|
-
# end
|
63
|
-
|
64
|
-
# Add libpq.dll to windows binary gemspec
|
65
|
-
# ext.cross_compiling do |spec|
|
66
|
-
# spec.files << "lib/#{spec.platform}/libpq.dll"
|
67
|
-
# end
|
30
|
+
ext.name = "pg_ext"
|
31
|
+
ext.gem_spec = $gem_spec
|
32
|
+
ext.ext_dir = "ext"
|
33
|
+
ext.lib_dir = "lib"
|
34
|
+
ext.source_pattern = "*.{c,h}"
|
35
|
+
ext.cross_compile = true
|
36
|
+
ext.cross_platform = CrossLibraries.map(&:for_platform)
|
37
|
+
ext.cross_config_options += CrossLibraries.map do |lib|
|
38
|
+
{ lib.for_platform => (["--enable-windows-cross", "--with-pg-include=#{lib.static_postgresql_incdir}", "--with-pg-lib=#{lib.static_postgresql_libdir}", "--with-opt-include=#{lib.static_postgresql_libdir}"]) }
|
39
|
+
end
|
40
|
+
ext.cross_compiling do |spec|
|
41
|
+
(spec.files << "lib/#{spec.platform}/libpq.dll")
|
42
|
+
end
|
68
43
|
end
|
69
|
-
|
70
44
|
RSpec::Core::RakeTask.new(:spec).rspec_opts = "--profile -cfdoc"
|
71
|
-
task
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
rdoc.rdoc_files = $gem_spec.extra_rdoc_files
|
79
|
-
rdoc.generator = :fivefish
|
80
|
-
rdoc.rdoc_dir = 'doc'
|
45
|
+
task(:test => :spec)
|
46
|
+
require("rdoc/task")
|
47
|
+
RDoc::Task.new("docs") do |rdoc|
|
48
|
+
rdoc.options = $gem_spec.rdoc_options
|
49
|
+
rdoc.rdoc_files = $gem_spec.extra_rdoc_files
|
50
|
+
rdoc.generator = :fivefish
|
51
|
+
rdoc.rdoc_dir = "doc"
|
81
52
|
end
|
82
|
-
|
83
|
-
|
84
|
-
task
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
require_relative 'spec/helpers'
|
89
|
-
PG::TestingHelpers.stop_existing_postmasters()
|
53
|
+
desc("Build the source gem #{$gem_spec.full_name}.gem into the pkg directory")
|
54
|
+
task(:gem => :build)
|
55
|
+
task(:clobber) do
|
56
|
+
puts("Stop any Postmaster instances that remain after testing.")
|
57
|
+
require_relative("spec/helpers")
|
58
|
+
CipherStashPG::TestingHelpers.stop_existing_postmasters
|
90
59
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
sh "wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}"
|
98
|
-
|
99
|
-
ruby 'ext/errorcodes.rb', 'ext/errorcodes.txt', 'ext/errorcodes.def'
|
60
|
+
desc("Update list of server error codes")
|
61
|
+
task(:update_error_codes) do
|
62
|
+
URL_ERRORCODES_TXT = "http://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/utils/errcodes.txt;hb=refs/tags/REL_15_0"
|
63
|
+
ERRORCODES_TXT = "ext/errorcodes.txt"
|
64
|
+
sh("wget #{URL_ERRORCODES_TXT.inspect} -O #{ERRORCODES_TXT.inspect} || curl #{URL_ERRORCODES_TXT.inspect} -o #{ERRORCODES_TXT.inspect}")
|
65
|
+
ruby("ext/errorcodes.rb", "ext/errorcodes.txt", "ext/errorcodes.def")
|
100
66
|
end
|
101
|
-
|
102
|
-
|
103
|
-
# trigger compilation of changed errorcodes.def
|
104
|
-
touch 'ext/pg_errors.c'
|
67
|
+
file("ext/pg_errors.c" => (["ext/errorcodes.def"])) do
|
68
|
+
touch("ext/pg_errors.c")
|
105
69
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
sh "LANG=C po4a --version > .po4a-version"
|
112
|
-
|
113
|
-
sh "po4a po4a.cfg"
|
70
|
+
desc("Translate readme")
|
71
|
+
task(:translate) do
|
72
|
+
cd("translation") do
|
73
|
+
sh("LANG=C po4a --version > .po4a-version")
|
74
|
+
sh("po4a po4a.cfg")
|
114
75
|
end
|
115
76
|
end
|
data/Rakefile.cross
ADDED
@@ -0,0 +1,298 @@
|
|
1
|
+
# -*- rake -*-
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'rbconfig'
|
6
|
+
require 'rake/clean'
|
7
|
+
require 'rake/extensiontask'
|
8
|
+
require 'rake/extensioncompiler'
|
9
|
+
require 'ostruct'
|
10
|
+
require_relative 'rakelib/task_extension'
|
11
|
+
|
12
|
+
MISCDIR = BASEDIR + 'misc'
|
13
|
+
|
14
|
+
NUM_CPUS = if File.exist?('/proc/cpuinfo')
|
15
|
+
File.read('/proc/cpuinfo').scan('processor').length
|
16
|
+
elsif RUBY_PLATFORM.include?( 'darwin' )
|
17
|
+
`system_profiler SPHardwareDataType | grep 'Cores' | awk '{print $5}'`.chomp
|
18
|
+
else
|
19
|
+
1
|
20
|
+
end
|
21
|
+
|
22
|
+
class CrossLibrary < OpenStruct
|
23
|
+
include Rake::DSL
|
24
|
+
prepend TaskExtension
|
25
|
+
|
26
|
+
def initialize(for_platform, openssl_config, toolchain)
|
27
|
+
super()
|
28
|
+
|
29
|
+
self.for_platform = for_platform
|
30
|
+
self.openssl_config = openssl_config
|
31
|
+
self.host_platform = toolchain
|
32
|
+
|
33
|
+
# Cross-compilation constants
|
34
|
+
self.openssl_version = ENV['OPENSSL_VERSION'] || '3.0.8'
|
35
|
+
self.postgresql_version = ENV['POSTGRESQL_VERSION'] || '15.2'
|
36
|
+
|
37
|
+
# Check if symlinks work in the current working directory.
|
38
|
+
# This fails, if rake-compiler-dock is running on a Windows box.
|
39
|
+
begin
|
40
|
+
FileUtils.rm_f '.test_symlink'
|
41
|
+
FileUtils.ln_s '/', '.test_symlink'
|
42
|
+
rescue NotImplementedError, SystemCallError
|
43
|
+
# Symlinks don't work -> use home directory instead
|
44
|
+
self.compile_home = Pathname( "~/.ruby-pg-build" ).expand_path
|
45
|
+
else
|
46
|
+
self.compile_home = Pathname( "./build" ).expand_path
|
47
|
+
end
|
48
|
+
self.static_sourcesdir = compile_home + 'sources'
|
49
|
+
self.static_builddir = compile_home + 'builds' + for_platform
|
50
|
+
CLOBBER.include( static_sourcesdir )
|
51
|
+
CLEAN.include( static_builddir )
|
52
|
+
|
53
|
+
# Static OpenSSL build vars
|
54
|
+
self.static_openssl_builddir = static_builddir + "openssl-#{openssl_version}"
|
55
|
+
|
56
|
+
self.openssl_source_uri =
|
57
|
+
URI( "http://www.openssl.org/source/openssl-#{openssl_version}.tar.gz" )
|
58
|
+
self.openssl_tarball = static_sourcesdir + File.basename( openssl_source_uri.path )
|
59
|
+
self.openssl_makefile = static_openssl_builddir + 'Makefile'
|
60
|
+
|
61
|
+
self.libssl = static_openssl_builddir + 'libssl.a'
|
62
|
+
self.libcrypto = static_openssl_builddir + 'libcrypto.a'
|
63
|
+
|
64
|
+
self.openssl_patches = Rake::FileList[ (MISCDIR + "openssl-#{openssl_version}.*.patch").to_s ]
|
65
|
+
|
66
|
+
# Static PostgreSQL build vars
|
67
|
+
self.static_postgresql_builddir = static_builddir + "postgresql-#{postgresql_version}"
|
68
|
+
self.postgresql_source_uri = begin
|
69
|
+
uristring = "http://ftp.postgresql.org/pub/source/v%s/postgresql-%s.tar.bz2" %
|
70
|
+
[ postgresql_version, postgresql_version ]
|
71
|
+
URI( uristring )
|
72
|
+
end
|
73
|
+
self.postgresql_tarball = static_sourcesdir + File.basename( postgresql_source_uri.path )
|
74
|
+
|
75
|
+
self.static_postgresql_srcdir = static_postgresql_builddir + 'src'
|
76
|
+
self.static_postgresql_libdir = static_postgresql_srcdir + 'interfaces/libpq'
|
77
|
+
self.static_postgresql_incdir = static_postgresql_srcdir + 'include'
|
78
|
+
|
79
|
+
self.postgresql_global_makefile = static_postgresql_srcdir + 'Makefile.global'
|
80
|
+
self.postgresql_shlib_makefile = static_postgresql_srcdir + 'Makefile.shlib'
|
81
|
+
self.postgresql_shlib_mf_orig = static_postgresql_srcdir + 'Makefile.shlib.orig'
|
82
|
+
self.postgresql_lib = static_postgresql_libdir + 'libpq.dll'
|
83
|
+
self.postgresql_patches = Rake::FileList[ (MISCDIR + "postgresql-#{postgresql_version}.*.patch").to_s ]
|
84
|
+
|
85
|
+
# clean intermediate files and folders
|
86
|
+
CLEAN.include( static_builddir.to_s )
|
87
|
+
|
88
|
+
#####################################################################
|
89
|
+
### C R O S S - C O M P I L A T I O N - T A S K S
|
90
|
+
#####################################################################
|
91
|
+
|
92
|
+
|
93
|
+
directory static_sourcesdir.to_s
|
94
|
+
|
95
|
+
#
|
96
|
+
# Static OpenSSL build tasks
|
97
|
+
#
|
98
|
+
directory static_openssl_builddir.to_s
|
99
|
+
|
100
|
+
# openssl source file should be stored there
|
101
|
+
file openssl_tarball => static_sourcesdir do |t|
|
102
|
+
download( openssl_source_uri, t.name )
|
103
|
+
end
|
104
|
+
|
105
|
+
# Extract the openssl builds
|
106
|
+
file static_openssl_builddir => openssl_tarball do |t|
|
107
|
+
puts "extracting %s to %s" % [ openssl_tarball, static_openssl_builddir.parent ]
|
108
|
+
static_openssl_builddir.mkpath
|
109
|
+
run 'tar', '-xzf', openssl_tarball.to_s, '-C', static_openssl_builddir.parent.to_s
|
110
|
+
openssl_makefile.unlink if openssl_makefile.exist?
|
111
|
+
|
112
|
+
openssl_patches.each do |patchfile|
|
113
|
+
puts " applying patch #{patchfile}..."
|
114
|
+
run 'patch', '-Np1', '-d', static_openssl_builddir.to_s,
|
115
|
+
'-i', File.expand_path( patchfile, BASEDIR )
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
self.cmd_prelude = [
|
120
|
+
"env",
|
121
|
+
"CROSS_COMPILE=#{host_platform}-",
|
122
|
+
"CFLAGS=-DDSO_WIN32",
|
123
|
+
]
|
124
|
+
|
125
|
+
|
126
|
+
# generate the makefile in a clean build location
|
127
|
+
file openssl_makefile => static_openssl_builddir do |t|
|
128
|
+
chdir( static_openssl_builddir ) do
|
129
|
+
cmd = cmd_prelude.dup
|
130
|
+
cmd << "./Configure" << "-static" << openssl_config
|
131
|
+
|
132
|
+
run( *cmd )
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
desc "compile static openssl libraries"
|
137
|
+
task "openssl_libs:#{for_platform}" => [ libssl, libcrypto ]
|
138
|
+
|
139
|
+
task "compile_static_openssl:#{for_platform}" => openssl_makefile do |t|
|
140
|
+
chdir( static_openssl_builddir ) do
|
141
|
+
cmd = cmd_prelude.dup
|
142
|
+
cmd << 'make' << "-j#{NUM_CPUS}" << 'build_libs'
|
143
|
+
|
144
|
+
run( *cmd )
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
desc "compile static #{libssl}"
|
149
|
+
file libssl => "compile_static_openssl:#{for_platform}"
|
150
|
+
|
151
|
+
desc "compile static #{libcrypto}"
|
152
|
+
file libcrypto => "compile_static_openssl:#{for_platform}"
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
#
|
157
|
+
# Static PostgreSQL build tasks
|
158
|
+
#
|
159
|
+
directory static_postgresql_builddir.to_s
|
160
|
+
|
161
|
+
|
162
|
+
# postgresql source file should be stored there
|
163
|
+
file postgresql_tarball => static_sourcesdir do |t|
|
164
|
+
download( postgresql_source_uri, t.name )
|
165
|
+
end
|
166
|
+
|
167
|
+
# Extract the postgresql sources
|
168
|
+
file static_postgresql_builddir => postgresql_tarball do |t|
|
169
|
+
puts "extracting %s to %s" % [ postgresql_tarball, static_postgresql_builddir.parent ]
|
170
|
+
static_postgresql_builddir.mkpath
|
171
|
+
run 'tar', '-xjf', postgresql_tarball.to_s, '-C', static_postgresql_builddir.parent.to_s
|
172
|
+
|
173
|
+
postgresql_patches.each do |patchfile|
|
174
|
+
puts " applying patch #{patchfile}..."
|
175
|
+
run 'patch', '-Np1', '-d', static_postgresql_builddir.to_s,
|
176
|
+
'-i', File.expand_path( patchfile, BASEDIR )
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# generate the makefile in a clean build location
|
181
|
+
file postgresql_global_makefile => [ static_postgresql_builddir, "openssl_libs:#{for_platform}" ] do |t|
|
182
|
+
options = [
|
183
|
+
"--target=#{host_platform}",
|
184
|
+
"--host=#{host_platform}",
|
185
|
+
'--with-openssl',
|
186
|
+
'--without-zlib',
|
187
|
+
]
|
188
|
+
|
189
|
+
chdir( static_postgresql_builddir ) do
|
190
|
+
configure_path = static_postgresql_builddir + 'configure'
|
191
|
+
cmd = [ configure_path.to_s, *options ]
|
192
|
+
cmd << "CFLAGS=-L#{static_openssl_builddir}"
|
193
|
+
cmd << "LDFLAGS=-L#{static_openssl_builddir}"
|
194
|
+
cmd << "LDFLAGS_SL=-L#{static_openssl_builddir}"
|
195
|
+
cmd << "LIBS=-lwsock32 -lgdi32 -lws2_32 -lcrypt32"
|
196
|
+
cmd << "CPPFLAGS=-I#{static_openssl_builddir}/include"
|
197
|
+
|
198
|
+
run( *cmd )
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
# make libpq.dll
|
204
|
+
task postgresql_lib => [ postgresql_global_makefile ] do |t|
|
205
|
+
# Work around missing dependency to libcommon in PostgreSQL-9.4.0
|
206
|
+
chdir( static_postgresql_srcdir + "common" ) do
|
207
|
+
sh 'make', "-j#{NUM_CPUS}"
|
208
|
+
end
|
209
|
+
chdir( static_postgresql_srcdir + "port" ) do
|
210
|
+
sh 'make', "-j#{NUM_CPUS}"
|
211
|
+
end
|
212
|
+
|
213
|
+
chdir( postgresql_lib.dirname ) do
|
214
|
+
sh 'make',
|
215
|
+
"-j#{NUM_CPUS}",
|
216
|
+
postgresql_lib.basename.to_s,
|
217
|
+
'SHLIB_LINK=-lssl -lcrypto -lcrypt32 -lgdi32 -lsecur32 -lwsock32 -lws2_32'
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
#desc 'compile libpg.a'
|
223
|
+
task "native:#{for_platform}" => postgresql_lib
|
224
|
+
|
225
|
+
# copy libpq.dll to lib dir
|
226
|
+
dest_libpq = "lib/#{for_platform}/#{postgresql_lib.basename}"
|
227
|
+
directory File.dirname(dest_libpq)
|
228
|
+
file dest_libpq => [postgresql_lib, File.dirname(dest_libpq)] do
|
229
|
+
cp postgresql_lib, dest_libpq
|
230
|
+
end
|
231
|
+
|
232
|
+
stage_libpq = "tmp/#{for_platform}/stage/#{dest_libpq}"
|
233
|
+
directory File.dirname(stage_libpq)
|
234
|
+
file stage_libpq => [postgresql_lib, File.dirname(stage_libpq)] do |t|
|
235
|
+
cp postgresql_lib, stage_libpq
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
def download(url, save_to)
|
240
|
+
part = save_to+".part"
|
241
|
+
sh "wget #{url.to_s.inspect} -O #{part.inspect} || curl #{url.to_s.inspect} -o #{part.inspect}"
|
242
|
+
FileUtils.mv part, save_to
|
243
|
+
end
|
244
|
+
|
245
|
+
def run(*args)
|
246
|
+
sh(*args)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
CrossLibraries = [
|
251
|
+
['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'],
|
252
|
+
['x86-mingw32', 'mingw', 'i686-w64-mingw32'],
|
253
|
+
['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
|
254
|
+
].map do |platform, openssl_config, toolchain|
|
255
|
+
CrossLibrary.new platform, openssl_config, toolchain
|
256
|
+
end
|
257
|
+
|
258
|
+
desc 'cross compile pg for win32'
|
259
|
+
task :cross => [ :mingw32 ]
|
260
|
+
|
261
|
+
task :mingw32 do
|
262
|
+
# Use Rake::ExtensionCompiler helpers to find the proper host
|
263
|
+
unless Rake::ExtensionCompiler.mingw_host then
|
264
|
+
warn "You need to install mingw32 cross compile functionality to be able to continue."
|
265
|
+
warn "Please refer to your distribution/package manager documentation about installation."
|
266
|
+
fail
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
task 'gem:windows:prepare' do
|
271
|
+
require 'io/console'
|
272
|
+
require 'rake_compiler_dock'
|
273
|
+
|
274
|
+
# Copy gem signing key and certs to be accessible from the docker container
|
275
|
+
mkdir_p 'build/gem'
|
276
|
+
sh "cp ~/.gem/gem-*.pem build/gem/ || true"
|
277
|
+
sh "bundle package"
|
278
|
+
begin
|
279
|
+
OpenSSL::PKey.read(File.read(File.expand_path("~/.gem/gem-private_key.pem")), ENV["GEM_PRIVATE_KEY_PASSPHRASE"] || "")
|
280
|
+
rescue OpenSSL::PKey::PKeyError
|
281
|
+
ENV["GEM_PRIVATE_KEY_PASSPHRASE"] = STDIN.getpass("Enter passphrase of gem signature key: ")
|
282
|
+
retry
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
CrossLibraries.each do |xlib|
|
287
|
+
platform = xlib.for_platform
|
288
|
+
desc "Build fat binary gem for platform #{platform}"
|
289
|
+
task "gem:windows:#{platform}" => ['gem:windows:prepare', xlib.openssl_tarball, xlib.postgresql_tarball] do
|
290
|
+
RakeCompilerDock.sh <<-EOT, platform: platform
|
291
|
+
(cp build/gem/gem-*.pem ~/.gem/ || true) &&
|
292
|
+
bundle install --local &&
|
293
|
+
rake native:#{platform} pkg/#{$gem_spec.full_name}-#{platform}.gem MAKE="make -j`nproc`" RUBY_CC_VERSION=3.2.0:3.1.0:3.0.0:2.7.0:2.6.0:2.5.0
|
294
|
+
EOT
|
295
|
+
end
|
296
|
+
desc "Build the windows binary gems"
|
297
|
+
multitask 'gem:windows' => "gem:windows:#{platform}"
|
298
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
2
|
+
MIIEBDCCAmygAwIBAgIBAjANBgkqhkiG9w0BAQsFADAoMSYwJAYDVQQDDB1sYXJz
|
3
|
+
L0RDPWdyZWl6LXJlaW5zZG9yZi9EQz1kZTAeFw0yMzAyMTUxNzQxMTVaFw0yNDAy
|
4
|
+
MTUxNzQxMTVaMCgxJjAkBgNVBAMMHWxhcnMvREM9Z3JlaXotcmVpbnNkb3JmL0RD
|
5
|
+
PWRlMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAwum6Y1KznfpzXOT/
|
6
|
+
mZgJTBbxZuuZF49Fq3K0WA67YBzNlDv95qzSp7V/7Ek3NCcnT7G+2kSuhNo1FhdN
|
7
|
+
eSDO/moYebZNAcu3iqLsuzuULXPLuoU0GsMnVMqV9DZPh7cQHE5EBZ7hlzDBK7k/
|
8
|
+
8nBMvR0mHo77kIkapHc26UzVq/G0nKLfDsIHXVylto3PjzOumjG6GhmFN4r3cP6e
|
9
|
+
SDfl1FSeRYVpt4kmQULz/zdSaOH3AjAq7PM2Z91iGwQvoUXMANH2v89OWjQO/NHe
|
10
|
+
JMNDFsmHK/6Ji4Kk48Z3TyscHQnipAID5GhS1oD21/WePdj7GhmbF5gBzkV5uepd
|
11
|
+
eJQPgWGwrQW/Z2oPjRuJrRofzWfrMWqbOahj9uth6WSxhNexUtbjk6P8emmXOJi5
|
12
|
+
chQPnWX+N3Gj+jjYxqTFdwT7Mj3pv1VHa+aNUbqSPpvJeDyxRIuo9hvzDaBHb/Cg
|
13
|
+
9qRVcm8a96n4t7y2lrX1oookY6bkBaxWOMtWlqIprq8JZXM9AgMBAAGjOTA3MAkG
|
14
|
+
A1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBQ4h1tIyvdUWtMI739xMzTR
|
15
|
+
7EfMFzANBgkqhkiG9w0BAQsFAAOCAYEAQAcuTARfiiVUVx5KURICfdTM2Kd7LhOn
|
16
|
+
qt3Vs4ANGvT226LEp3RnQ+kWGQYMRb3cw3LY2TNQRPlnZxE994mgjBscN4fbjXqO
|
17
|
+
T0JbVpeszRZa5k1goggbnWT7CO7yU7WcHh13DaSubY7HUpAJn2xz9w2stxQfN/EE
|
18
|
+
VMlnDJ1P7mUHAvpK8X9j9h7Xlc1niViT18MYwux8mboVTryrLr+clATUkkM3yBF0
|
19
|
+
RV+c34ReW5eXO9Tr6aKTxh/pFC9ggDT6jOxuJgSvG8HWJzVf4NDvMavIas4KYjiI
|
20
|
+
BU6CpWaG5NxicqL3BERi52U43HV08br+LNVpb7Rekgve/PJuSFnAR015bhSRXe5U
|
21
|
+
vBioD1qW2ZW9tXg8Ww2IfDaO5a1So5Xby51rhNlyo6ATj2NkuLWZUKPKHhAz0TKm
|
22
|
+
Dzx/gFSOrRoCt2mXNgrmcAfr386AfaMvCh7cXqdxZwmVo7ILZCYXck0pajvubsDd
|
23
|
+
NUIIFkVXvd1odFyK9LF1RFAtxn/iAmpx
|
24
|
+
-----END CERTIFICATE-----
|
data/cipherstash-pg.gemspec
CHANGED
Binary file
|
data/lib/2.7/pg_ext.so
CHANGED
Binary file
|
data/lib/3.0/pg_ext.so
CHANGED
Binary file
|
data/lib/3.1/pg_ext.so
CHANGED
Binary file
|
data/lib/3.2/pg_ext.so
CHANGED
Binary file
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require("cipherstash-pg") unless defined? CipherStashPG
|
2
|
+
class CipherStashPG::BasicTypeMapBasedOnResult < CipherStashPG::TypeMapByOid
|
3
|
+
include(CipherStashPG::BasicTypeRegistry::Checker)
|
4
|
+
|
5
|
+
def initialize(connection_or_coder_maps, registry: nil)
|
6
|
+
@coder_maps = build_coder_maps(connection_or_coder_maps, :registry => registry)
|
7
|
+
@coder_maps.each_format(:encoder).flat_map { |f| f.coders }.each do |coder|
|
8
|
+
add_coder(coder)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require("cipherstash-pg") unless defined? CipherStashPG
|
2
|
+
class CipherStashPG::BasicTypeMapForQueries < CipherStashPG::TypeMapByClass
|
3
|
+
class BinaryData < String
|
4
|
+
end
|
5
|
+
|
6
|
+
class UndefinedEncoder < RuntimeError
|
7
|
+
end
|
8
|
+
|
9
|
+
include(CipherStashPG::BasicTypeRegistry::Checker)
|
10
|
+
|
11
|
+
def initialize(connection_or_coder_maps, registry: nil, if_undefined: nil)
|
12
|
+
@coder_maps = build_coder_maps(connection_or_coder_maps, :registry => registry)
|
13
|
+
@array_encoders_by_klass = array_encoders_by_klass
|
14
|
+
@encode_array_as = :array
|
15
|
+
@if_undefined = (if_undefined or proc do |oid_name, format|
|
16
|
+
raise(UndefinedEncoder, "no encoder defined for type #{oid_name.inspect} format #{format}")
|
17
|
+
end)
|
18
|
+
init_encoders
|
19
|
+
end
|
20
|
+
|
21
|
+
def encode_array_as=(pg_type)
|
22
|
+
case pg_type
|
23
|
+
when :array then
|
24
|
+
# do nothing
|
25
|
+
when :json then
|
26
|
+
# do nothing
|
27
|
+
when :record then
|
28
|
+
# do nothing
|
29
|
+
when /\A_/ then
|
30
|
+
# do nothing
|
31
|
+
else
|
32
|
+
raise(ArgumentError, "invalid pg_type #{pg_type.inspect}")
|
33
|
+
end
|
34
|
+
@encode_array_as = pg_type
|
35
|
+
init_encoders
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_reader(:encode_array_as)
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def init_encoders
|
43
|
+
coders.each { |kl, c| self[kl] = nil }
|
44
|
+
populate_encoder_list
|
45
|
+
@textarray_encoder = coder_by_name(0, :encoder, "_text")
|
46
|
+
end
|
47
|
+
|
48
|
+
def coder_by_name(format, direction, name)
|
49
|
+
check_format_and_direction(format, direction)
|
50
|
+
@coder_maps.map_for(format, direction).coder_by_name(name)
|
51
|
+
end
|
52
|
+
|
53
|
+
def undefined(name, format)
|
54
|
+
@if_undefined.call(name, format)
|
55
|
+
end
|
56
|
+
|
57
|
+
def populate_encoder_list
|
58
|
+
DEFAULT_TYPE_MAP.each do |klass, selector|
|
59
|
+
if Array.===(selector) then
|
60
|
+
format, name, oid_name = selector
|
61
|
+
coder = coder_by_name(format, :encoder, name).dup
|
62
|
+
if coder then
|
63
|
+
if oid_name then
|
64
|
+
oid_coder = coder_by_name(format, :encoder, oid_name)
|
65
|
+
oid_coder ? (coder.oid = oid_coder.oid) : (undefined(oid_name, format))
|
66
|
+
else
|
67
|
+
coder.oid = 0
|
68
|
+
end
|
69
|
+
self[klass] = coder
|
70
|
+
else
|
71
|
+
undefined(name, format)
|
72
|
+
end
|
73
|
+
else
|
74
|
+
case @encode_array_as
|
75
|
+
when :array then
|
76
|
+
self[klass] = selector
|
77
|
+
when :json then
|
78
|
+
self[klass] = CipherStashPG::TextEncoder::JSON.new
|
79
|
+
when :record then
|
80
|
+
self[klass] = CipherStashPG::TextEncoder::Record.new(:type_map => (self))
|
81
|
+
when /\A_/ then
|
82
|
+
coder = coder_by_name(0, :encoder, @encode_array_as)
|
83
|
+
coder ? (self[klass] = coder) : (undefined(@encode_array_as, format))
|
84
|
+
else
|
85
|
+
raise(ArgumentError, "invalid pg_type #{@encode_array_as.inspect}")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def array_encoders_by_klass
|
92
|
+
DEFAULT_ARRAY_TYPE_MAP.inject({}) do |h, (klass, (format, name))|
|
93
|
+
h[klass] = coder_by_name(format, :encoder, name)
|
94
|
+
h
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def get_array_type(value)
|
99
|
+
elem = value
|
100
|
+
while elem.kind_of?(Array) do
|
101
|
+
elem = elem.first
|
102
|
+
end
|
103
|
+
(@array_encoders_by_klass[elem.class] or (elem.class.ancestors.lazy.map do |ancestor|
|
104
|
+
@array_encoders_by_klass[ancestor]
|
105
|
+
end.find do |a|
|
106
|
+
a
|
107
|
+
end or @textarray_encoder))
|
108
|
+
end
|
109
|
+
|
110
|
+
DEFAULT_TYPE_MAP = { TrueClass => ([1, "bool", "bool"]), FalseClass => ([1, "bool", "bool"]), Integer => ([0, "int8"]), Float => ([0, "float8"]), BigDecimal => ([0, "numeric"]), Time => ([0, "timestamptz"]), IPAddr => ([0, "inet"]), Hash => ([0, "json"]), Array => :get_array_type, BinaryData => ([1, "bytea"]) }
|
111
|
+
|
112
|
+
DEFAULT_ARRAY_TYPE_MAP = { TrueClass => ([0, "_bool"]), FalseClass => ([0, "_bool"]), Integer => ([0, "_int8"]), String => ([0, "_text"]), Float => ([0, "_float8"]), BigDecimal => ([0, "_numeric"]), Time => ([0, "_timestamptz"]), IPAddr => ([0, "_inet"]) }
|
113
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require("cipherstash-pg") unless defined? CipherStashPG
|
2
|
+
class CipherStashPG::BasicTypeMapForResults < CipherStashPG::TypeMapByOid
|
3
|
+
include(CipherStashPG::BasicTypeRegistry::Checker)
|
4
|
+
|
5
|
+
class WarningTypeMap < CipherStashPG::TypeMapInRuby
|
6
|
+
def initialize(typenames)
|
7
|
+
@already_warned = Hash.new { |h, k| h[k] = {} }
|
8
|
+
@typenames_by_oid = typenames
|
9
|
+
end
|
10
|
+
|
11
|
+
def typecast_result_value(result, _tuple, field)
|
12
|
+
format = result.fformat(field)
|
13
|
+
oid = result.ftype(field)
|
14
|
+
unless @already_warned[format][oid] then
|
15
|
+
warn("Warning: no type cast defined for type #{@typenames_by_oid[oid].inspect} format #{format} with oid #{oid}. Please cast this type explicitly to TEXT to be safe for future changes.")
|
16
|
+
@already_warned[format][oid] = true
|
17
|
+
end
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(connection_or_coder_maps, registry: nil)
|
23
|
+
@coder_maps = build_coder_maps(connection_or_coder_maps, :registry => registry)
|
24
|
+
@coder_maps.each_format(:decoder).flat_map { |f| f.coders }.each do |coder|
|
25
|
+
add_coder(coder)
|
26
|
+
end
|
27
|
+
typenames = @coder_maps.typenames_by_oid
|
28
|
+
self.default_type_map = WarningTypeMap.new(typenames)
|
29
|
+
end
|
30
|
+
end
|