liberic 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +126 -0
- data/README.md +283 -146
- data/examples/est_2020.rb +40 -0
- data/lib/liberic/boot.rb +85 -10
- data/lib/liberic/certificate.rb +95 -16
- data/lib/liberic/config.rb +89 -20
- data/lib/liberic/core.rb +24 -0
- data/{rakelib/eric.rake → lib/liberic/eric_installer.rb} +38 -17
- data/lib/liberic/helpers/invocation.rb +46 -9
- data/lib/liberic/process.rb +233 -41
- data/lib/liberic/sdk/api.rb +28 -0
- data/lib/liberic/sdk/types.rb +49 -1
- data/lib/liberic/sdk.rb +12 -1
- data/lib/liberic/tasks.rb +27 -0
- data/lib/liberic/version.rb +1 -1
- data/lib/liberic.rb +5 -20
- metadata +29 -35
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/release.yml +0 -39
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/.tool-versions +0 -1
- data/CODE_OF_CONDUCT.md +0 -13
- data/ERIC_SDK_UPGRADE_PROMPT.md +0 -16
- data/Gemfile +0 -6
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -7
- data/examples/steuersatz.xml +0 -89
- data/examples/submit_ekst.rb +0 -13
- data/liberic.gemspec +0 -38
data/lib/liberic/process.rb
CHANGED
|
@@ -13,94 +13,286 @@ module Liberic
|
|
|
13
13
|
class ExecutionError < StandardError
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
# Raised by +execute!+ when ERiC returns a code other than +ERIC_OK+.
|
|
17
|
+
# +result+ is the +Result+ of the call, including the result buffers.
|
|
18
|
+
class ProcessingError < ExecutionError
|
|
19
|
+
attr_reader :result
|
|
20
|
+
|
|
21
|
+
def initialize(result)
|
|
22
|
+
@result = result
|
|
23
|
+
super("#{result.error} (#{result.code})")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def code
|
|
27
|
+
result.code
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def error
|
|
31
|
+
result.error
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# The result of +execute+.
|
|
36
|
+
#
|
|
37
|
+
# For backwards compatibility this is a Hash with the keys +:result+ (the
|
|
38
|
+
# content of ERiC's result buffer, an XML string or empty) and
|
|
39
|
+
# +:server_result+ (the server's response, if anything was sent). In
|
|
40
|
+
# addition it carries ERiC's return code:
|
|
41
|
+
#
|
|
42
|
+
# result = filing.execute
|
|
43
|
+
# result.ok? # => false
|
|
44
|
+
# result.code # => 610001002
|
|
45
|
+
# result.error # => "ERIC_GLOBAL_PRUEF_FEHLER" (nil if ok)
|
|
46
|
+
# result[:result] # => "<EricBearbeiteVorgang ...><Fehler..."
|
|
47
|
+
#
|
|
48
|
+
# An empty +:result+ does not mean success: always check +ok?+.
|
|
49
|
+
class Result < Hash
|
|
50
|
+
# ERiC's return code.
|
|
51
|
+
attr_reader :code
|
|
52
|
+
|
|
53
|
+
# The PDFs created with <tt>pdf: :memory</tt>, as a Hash from ERiC's
|
|
54
|
+
# name of each PDF (the Nutzdatenticket of the data block, or
|
|
55
|
+
# "Uebertragungsprotokoll") to its content (a binary String). Empty
|
|
56
|
+
# otherwise.
|
|
57
|
+
attr_reader :pdfs
|
|
58
|
+
|
|
59
|
+
def initialize(code:, result:, server_result:, pdfs: {})
|
|
60
|
+
super()
|
|
61
|
+
@code = code
|
|
62
|
+
@pdfs = pdfs
|
|
63
|
+
self[:result] = result
|
|
64
|
+
self[:server_result] = server_result
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# +true+ if ERiC found no errors: the return code is +ERIC_OK+, or
|
|
68
|
+
# +ERIC_GLOBAL_HINWEISE+, which ERiC returns only for the action
|
|
69
|
+
# +:validate_with_hints+ when it found hints but no errors.
|
|
70
|
+
def ok?
|
|
71
|
+
code == SDK::Fehlercodes::ERIC_OK || hints?
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# +true+ if ERiC returned +ERIC_GLOBAL_HINWEISE+: the data has no errors,
|
|
75
|
+
# and the +<Hinweis>+ elements in +:result+ list hints.
|
|
76
|
+
def hints?
|
|
77
|
+
code == SDK::Fehlercodes::ERIC_GLOBAL_HINWEISE
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# The name of the return code, e.g. "ERIC_GLOBAL_PRUEF_FEHLER", or +nil+
|
|
81
|
+
# if the call succeeded.
|
|
82
|
+
def error
|
|
83
|
+
Helpers::Invocation.error_name(code) unless ok?
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def result
|
|
87
|
+
self[:result]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def server_result
|
|
91
|
+
self[:server_result]
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def inspect
|
|
95
|
+
"#<#{self.class.name} code=#{code} error=#{error.inspect} #{super}>"
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# The +EricTransferHandle+ that bundles the calls of a Datenabholung
|
|
100
|
+
# (request, retrieval and optional acknowledgement). Create one per
|
|
101
|
+
# Datenabholung and pass it to every call with +:transfer_handle+:
|
|
102
|
+
#
|
|
103
|
+
# handle = Liberic::Process::TransferHandle.new
|
|
104
|
+
# request = Liberic::Process.new(request_xml, type).execute(action: :submit, encryption: params, transfer_handle: handle)
|
|
105
|
+
# retrieval = Liberic::Process.new(retrieval_xml, type).execute(action: :submit, encryption: params, transfer_handle: handle)
|
|
106
|
+
#
|
|
107
|
+
# ERiC requires NULL for all other use cases, which +execute+ passes
|
|
108
|
+
# without +:transfer_handle+.
|
|
109
|
+
class TransferHandle
|
|
110
|
+
def initialize
|
|
111
|
+
@pointer = FFI::MemoryPointer.new(:uint32, 1) # zero-filled, as ERiC requires
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# The handle's current value, set by ERiC.
|
|
115
|
+
def value
|
|
116
|
+
@pointer.get_uint32(0)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def to_ptr
|
|
120
|
+
@pointer
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
16
124
|
def initialize(xml, type)
|
|
17
125
|
@xml = xml
|
|
18
126
|
@type = type
|
|
19
127
|
end
|
|
20
128
|
|
|
129
|
+
# Checks the XML against ERiC's schema (+EricCheckXML()+).
|
|
130
|
+
#
|
|
131
|
+
# Returns the (usually empty) content of the result buffer. Raises
|
|
132
|
+
# +Helpers::Invocation::Error+ if the check fails; its +buffer+ contains
|
|
133
|
+
# ERiC's error text, one line per error, for example
|
|
134
|
+
# <tt>EC(1000): Fehler: EDS-XML in Zeile 39 in Spalte 40: ...</tt>.
|
|
21
135
|
def check
|
|
22
136
|
Helpers::Invocation.with_result_buffer do |handle|
|
|
23
137
|
SDK::API.check_xml(@xml, @type, handle)
|
|
24
138
|
end
|
|
25
139
|
end
|
|
26
140
|
|
|
27
|
-
# Executes the actual call to +EricBearbeiteVorgang()+
|
|
141
|
+
# Executes the actual call to +EricBearbeiteVorgang()+ and returns a +Result+.
|
|
142
|
+
#
|
|
143
|
+
# The call does not raise if ERiC returns an error code; check +Result#ok?+
|
|
144
|
+
# or use +execute!+.
|
|
28
145
|
#
|
|
29
146
|
# Taken an optional hash with an +:action+ parameter, which can be one of the following:
|
|
30
147
|
#
|
|
31
148
|
# * +:validate+ validate the tax filing and return errors (local processing only)
|
|
32
|
-
# * +:
|
|
33
|
-
#
|
|
149
|
+
# * +:validate_with_hints+ validate the tax filing and return errors and hints (+<Hinweis>+ elements,
|
|
150
|
+
# see +Result#hints?+) in one call (local processing only)
|
|
151
|
+
# * +:print+ validate the tax filing and create a preview PDF (local processing only)
|
|
152
|
+
# * +:print_and_submit+ validate the tax filing, submit it to ELSTER (server) and create
|
|
153
|
+
# the PDF of the submitted filing (+ERIC_VALIDIERE+, +ERIC_SENDE+ and +ERIC_DRUCKE+)
|
|
154
|
+
# * +:submit+ validate and submit the tax filing without creating a PDF
|
|
155
|
+
# * +:print_and_submit_auth+ deprecated alias of +:print_and_submit+
|
|
156
|
+
#
|
|
157
|
+
# Whether a submission is authenticated depends on +:encryption+, not on the action.
|
|
34
158
|
#
|
|
35
159
|
# Options for controlling the PDF output (printing)
|
|
36
160
|
#
|
|
37
|
-
# * +:filename+ (
|
|
38
|
-
# * +:
|
|
39
|
-
#
|
|
161
|
+
# * +:filename+ (path of the PDF file to create)
|
|
162
|
+
# * +:pdf+ (set to +:memory+ to receive the PDFs in +Result#pdfs+ instead of a file;
|
|
163
|
+
# do not pass +:filename+ then)
|
|
164
|
+
# * +:draft+ (+true+ prints the text "*** ENTWURF ***" on every page. Defaults to +true+
|
|
165
|
+
# for +:print+, which ERiC 43 allows only as a preview, and to +false+ for
|
|
166
|
+
# +:print_and_submit+, which ERiC rejects with +draft: true+ before sending)
|
|
167
|
+
# * +:footer+ (set a string that will be printed on ever page footer, at most 30 characters;
|
|
168
|
+
# see the README for the characters ERiC accepts)
|
|
40
169
|
# * +:duplex+ (set to +true+ to generate pages for duplex printing (alternating margin left and right)
|
|
41
170
|
#
|
|
42
171
|
# Other options
|
|
43
172
|
# * +:encryption+ An instance of +SDK::Types::VerschluesselungsParameter+ (Leave this empty when requesting BescheidRueckuebermittlung with CEZ (locally generated certificate))
|
|
44
|
-
#
|
|
173
|
+
# See +Certificate#encryption_params+.
|
|
174
|
+
# * +:transfer_handle+ A +TransferHandle+, only for the calls of a Datenabholung.
|
|
45
175
|
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
176
|
+
# ERiC 43 has no default directory for PDFs. An action that prints needs
|
|
177
|
+
# +:filename+ or <tt>pdf: :memory</tt>; without either, it returns
|
|
178
|
+
# +ERIC_GLOBAL_NULL_PARAMETER+, for +:print_and_submit+ before sending
|
|
179
|
+
# (measured with ERiC 43.5.4.0). A relative +:filename+ is resolved
|
|
180
|
+
# against the current working directory.
|
|
48
181
|
#
|
|
49
|
-
#
|
|
182
|
+
# Some parameter combinations result in errors, for example +draft: false+
|
|
183
|
+
# with +:print+ (ERiC prints locally only as a preview) or +draft: true+
|
|
184
|
+
# with +:print_and_submit+. They are reported through +Result#code+.
|
|
50
185
|
#
|
|
51
186
|
# Example:
|
|
52
187
|
#
|
|
53
|
-
# filing = Liberic::Process.new(xml_tax_filing, '
|
|
54
|
-
# filing.execute(action: :print)
|
|
188
|
+
# filing = Liberic::Process.new(xml_tax_filing, 'ESt_2020')
|
|
189
|
+
# result = filing.execute(action: :print, filename: '/tmp/est_2020.pdf')
|
|
190
|
+
# raise result.error unless result.ok?
|
|
191
|
+
#
|
|
192
|
+
# result = filing.execute(action: :print, pdf: :memory)
|
|
193
|
+
# result.pdfs # => {"<Nutzdatenticket>" => "%PDF-1.4..."}
|
|
55
194
|
#
|
|
56
|
-
# Will generate a PDF in the current directory if not specified otherwise.
|
|
57
195
|
# *WARNING* method signature and parameters are WIP and subject to change
|
|
58
196
|
def execute(options = {})
|
|
59
197
|
action = options[:action] ||= :validate
|
|
60
198
|
eric_action = ACTIONS[action] || (raise ExecutionError.new("Invalid action: #{action}. Valid actions are #{ACTIONS.keys.join(', ')}"))
|
|
61
|
-
|
|
62
|
-
|
|
199
|
+
if action == :print_and_submit_auth
|
|
200
|
+
warn('Liberic::Process action :print_and_submit_auth is deprecated; use :print_and_submit',
|
|
201
|
+
category: :deprecated, uplevel: 1)
|
|
202
|
+
end
|
|
203
|
+
pdfs = {}
|
|
204
|
+
print_params = create_print_params(options, pdfs)
|
|
63
205
|
server_buffer = SDK::API.rueckgabepuffer_erzeugen
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
206
|
+
begin
|
|
207
|
+
code, result = Helpers::Invocation.call_with_result_buffer do |local_buffer|
|
|
208
|
+
SDK::API.bearbeite_vorgang(@xml, @type,
|
|
209
|
+
eric_action,
|
|
210
|
+
(PRINTS.include?(action) ? print_params : nil),
|
|
211
|
+
options[:encryption],
|
|
212
|
+
options[:transfer_handle],
|
|
213
|
+
local_buffer,
|
|
214
|
+
server_buffer)
|
|
215
|
+
end
|
|
216
|
+
raise @pdf_callback_error if @pdf_callback_error
|
|
217
|
+
Result.new(code: code, result: result, server_result: SDK::API.rueckgabepuffer_inhalt(server_buffer), pdfs: pdfs)
|
|
218
|
+
ensure
|
|
219
|
+
@pdf_callback_error = nil
|
|
220
|
+
SDK::API.rueckgabepuffer_freigeben(server_buffer)
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Like +execute+, but raises +ProcessingError+ unless +Result#ok?+.
|
|
225
|
+
# The exception carries the +Result+ (code, name and buffer contents).
|
|
226
|
+
def execute!(options = {})
|
|
227
|
+
result = execute(options)
|
|
228
|
+
raise ProcessingError.new(result) unless result.ok?
|
|
229
|
+
result
|
|
80
230
|
end
|
|
81
231
|
|
|
82
232
|
private
|
|
83
233
|
|
|
234
|
+
flags = SDK::Types::BearbeitungFlag
|
|
235
|
+
# Sending and printing needs ERIC_DRUCKE together with ERIC_SENDE
|
|
236
|
+
# (ERiC-Entwicklerhandbuch, Tabelle 6-2, EBV-4 and EBV-6). With
|
|
237
|
+
# ERIC_SENDE alone, ERiC 43.5.4.0 sends but ignores the print parameters.
|
|
238
|
+
# The flags are the same for authenticated and unauthenticated sending;
|
|
239
|
+
# +:encryption+ decides.
|
|
240
|
+
SEND_AND_PRINT = flags[:validiere] | flags[:sende] | flags[:drucke]
|
|
241
|
+
|
|
84
242
|
ACTIONS = {
|
|
85
243
|
validate: :validiere,
|
|
244
|
+
# ERIC_PRUEFE_HINWEISE alone skips validation, so it is always combined
|
|
245
|
+
# with ERIC_VALIDIERE.
|
|
246
|
+
validate_with_hints: flags[:validiere] | flags[:pruefe_hinweise],
|
|
86
247
|
print: :drucke,
|
|
87
|
-
print_and_submit:
|
|
248
|
+
print_and_submit: SEND_AND_PRINT,
|
|
88
249
|
submit: :sende,
|
|
89
|
-
|
|
90
|
-
|
|
250
|
+
# Deprecated alias of :print_and_submit.
|
|
251
|
+
print_and_submit_auth: SEND_AND_PRINT
|
|
252
|
+
}.freeze
|
|
91
253
|
|
|
92
|
-
|
|
254
|
+
# Actions that pass the print parameters to ERiC.
|
|
255
|
+
PRINTS = %i[print print_and_submit print_and_submit_auth].freeze
|
|
256
|
+
|
|
257
|
+
# Actions that send and print. ERiC prints the final document then and
|
|
258
|
+
# rejects a preview (vorschau=1) with ERIC_GLOBAL_UNGUELTIGER_PARAMETER
|
|
259
|
+
# before sending, so +:draft+ defaults to +false+ for them.
|
|
260
|
+
SENDS_AND_PRINTS = %i[print_and_submit print_and_submit_auth].freeze
|
|
261
|
+
|
|
262
|
+
# The returned struct holds references to the native copies of
|
|
263
|
+
# +:filename+ and +:footer+ and to the PDF callback, so they stay
|
|
264
|
+
# allocated while it is in use. With <tt>pdf: :memory</tt> the callback
|
|
265
|
+
# adds the PDFs to +pdfs+.
|
|
266
|
+
def create_print_params(options, pdfs)
|
|
93
267
|
params = SDK::Types::DruckParameter.new
|
|
94
268
|
params[:version] = 4
|
|
95
269
|
params[:duplexDruck] = options[:duplex] ? 1 : 0
|
|
96
|
-
params[:vorschau] = options.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
270
|
+
params[:vorschau] = options.fetch(:draft, !SENDS_AND_PRINTS.include?(options[:action])) ? 1 : 0
|
|
271
|
+
params.set_string(:pdfName, options[:filename]) if options[:filename]
|
|
272
|
+
# ERiC expects the footer in UTF-8.
|
|
273
|
+
params.set_string(:fussText, options[:footer].to_s.encode(Encoding::UTF_8)) if options[:footer]
|
|
274
|
+
case options[:pdf]
|
|
275
|
+
when nil, :file
|
|
276
|
+
when :memory
|
|
277
|
+
raise ExecutionError.new('Pass either :filename or pdf: :memory, not both') if options[:filename]
|
|
278
|
+
params.set_pdf_callback(pdf_callback(pdfs))
|
|
279
|
+
else
|
|
280
|
+
raise ExecutionError.new("Invalid pdf option: #{options[:pdf].inspect}. Valid values are :file, :memory")
|
|
102
281
|
end
|
|
103
282
|
params
|
|
104
283
|
end
|
|
284
|
+
|
|
285
|
+
# ERiC cannot unwind a Ruby exception raised in the callback. It is kept
|
|
286
|
+
# and raised by +execute+ after ERiC returns; ERiC aborts printing with
|
|
287
|
+
# ERIC_PRINT_PDFCALLBACK.
|
|
288
|
+
def pdf_callback(pdfs)
|
|
289
|
+
SDK::API.generate_pdf_callback do |name, data|
|
|
290
|
+
pdfs[name] = data
|
|
291
|
+
0
|
|
292
|
+
rescue Exception => error # rubocop:disable Lint/RescueException
|
|
293
|
+
@pdf_callback_error = error
|
|
294
|
+
1
|
|
295
|
+
end
|
|
296
|
+
end
|
|
105
297
|
end
|
|
106
298
|
end
|
data/lib/liberic/sdk/api.rb
CHANGED
|
@@ -196,6 +196,15 @@ module Liberic
|
|
|
196
196
|
# const byteChar* steuernummer);
|
|
197
197
|
attach_eric_function :pruefe_steuernummer, [:string], :int
|
|
198
198
|
|
|
199
|
+
# ERICAPI_IMPORT int STDCALL EricZertifikatOeffnenAusBytes(
|
|
200
|
+
# EricZertifikatHandle* hToken,
|
|
201
|
+
# const byteChar *pkcs12Container,
|
|
202
|
+
# uint32_t containerGroesse,
|
|
203
|
+
# const byteChar *pkcs12Passwort);
|
|
204
|
+
# The container is binary data and the password is wiped after the call
|
|
205
|
+
# (see Certificate.from_bytes), so both are passed as pointers.
|
|
206
|
+
attach_eric_function :zertifikat_oeffnen_aus_bytes, [:pointer, :pointer, :uint32, :pointer], :int
|
|
207
|
+
|
|
199
208
|
# TODO
|
|
200
209
|
# ERICAPI_IMPORT int STDCALL EricPruefeZertifikatPin(
|
|
201
210
|
# const byteChar *pathToKeystore,
|
|
@@ -231,6 +240,25 @@ module Liberic
|
|
|
231
240
|
end
|
|
232
241
|
end
|
|
233
242
|
|
|
243
|
+
# typedef int(STDCALL *EricPdfCallback)(
|
|
244
|
+
# const char *pdfBezeichner,
|
|
245
|
+
# const BYTE *pdfDaten,
|
|
246
|
+
# uint32_t pdfGroesse,
|
|
247
|
+
# void *benutzerDaten);
|
|
248
|
+
#
|
|
249
|
+
# Returns an FFI::Function for eric_druck_parameter_t.pdfCallback. The
|
|
250
|
+
# block receives the PDF's name (the Nutzdatenticket, or
|
|
251
|
+
# "Uebertragungsprotokoll") and its content as a binary String. The
|
|
252
|
+
# block's value is returned to ERiC: 0 for success; anything else makes
|
|
253
|
+
# ERiC abort printing with ERIC_PRINT_PDFCALLBACK. Keep a reference to
|
|
254
|
+
# the function while ERiC may call it (DruckParameter#set_pdf_callback
|
|
255
|
+
# does). Exceptions must not leave the block: ERiC cannot unwind them.
|
|
256
|
+
def self.generate_pdf_callback(&block)
|
|
257
|
+
FFI::Function.new(:int, [:string, :pointer, :uint32, :pointer]) do |name, data, size, _user_data|
|
|
258
|
+
block.call(name, data.read_bytes(size))
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
234
262
|
# ERICAPI_IMPORT EricRueckgabepufferHandle STDCALL EricRueckgabepufferErzeugen(
|
|
235
263
|
# void);
|
|
236
264
|
attach_eric_function :rueckgabepuffer_erzeugen, [], :pointer
|
data/lib/liberic/sdk/types.rb
CHANGED
|
@@ -3,7 +3,33 @@ module Liberic
|
|
|
3
3
|
module Types
|
|
4
4
|
extend FFI::Library
|
|
5
5
|
|
|
6
|
+
# Helpers for structs with +const char*+ members.
|
|
7
|
+
#
|
|
8
|
+
# A struct only stores the address of a string. The memory behind that
|
|
9
|
+
# address must stay allocated as long as ERiC may read it, so the
|
|
10
|
+
# +FFI::MemoryPointer+ is kept in the struct object itself.
|
|
11
|
+
module StringMembers
|
|
12
|
+
# Copies +value+ into native memory and stores its address in +member+.
|
|
13
|
+
# +nil+ stores a NULL pointer.
|
|
14
|
+
def set_string(member, value)
|
|
15
|
+
@string_pointers ||= {}
|
|
16
|
+
pointer = value.nil? ? nil : FFI::MemoryPointer.from_string(value.to_s)
|
|
17
|
+
@string_pointers[member] = pointer
|
|
18
|
+
self[member] = pointer || FFI::Pointer::NULL
|
|
19
|
+
pointer
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Overwrites the native copy of +member+ with zero bytes.
|
|
23
|
+
def wipe_string(member)
|
|
24
|
+
pointer = @string_pointers && @string_pointers[member]
|
|
25
|
+
pointer&.clear
|
|
26
|
+
self
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
6
30
|
class DruckParameter < FFI::Struct
|
|
31
|
+
include StringMembers
|
|
32
|
+
|
|
7
33
|
layout :version, :uint, # Set version to 4
|
|
8
34
|
:vorschau, :uint,
|
|
9
35
|
:duplexDruck, :uint,
|
|
@@ -11,12 +37,31 @@ module Liberic
|
|
|
11
37
|
:fussText, :pointer,
|
|
12
38
|
:pdfCallback, :pointer,
|
|
13
39
|
:pdfCallbackBenutzerdaten, :pointer
|
|
40
|
+
|
|
41
|
+
# Stores +function+ (an +FFI::Function+ matching ERiC's
|
|
42
|
+
# +EricPdfCallback+, see +SDK::API.generate_pdf_callback+) as
|
|
43
|
+
# +pdfCallback+ and keeps a reference to it, so the garbage collector
|
|
44
|
+
# cannot free it while ERiC may call it. +nil+ stores a NULL pointer,
|
|
45
|
+
# and ERiC writes PDFs to +pdfName+.
|
|
46
|
+
def set_pdf_callback(function)
|
|
47
|
+
@pdf_callback = function
|
|
48
|
+
self[:pdfCallback] = function || FFI::Pointer::NULL
|
|
49
|
+
function
|
|
50
|
+
end
|
|
14
51
|
end
|
|
15
52
|
|
|
16
53
|
class VerschluesselungsParameter < FFI::Struct
|
|
54
|
+
include StringMembers
|
|
55
|
+
|
|
17
56
|
layout :version, :uint, # Set version to 3
|
|
18
57
|
:zertifikatHandle, :uint,
|
|
19
58
|
:pin, :pointer
|
|
59
|
+
|
|
60
|
+
# Overwrites the native copy of the PIN with zero bytes. The struct
|
|
61
|
+
# cannot be used for signing afterwards.
|
|
62
|
+
def wipe_pin!
|
|
63
|
+
wipe_string(:pin)
|
|
64
|
+
end
|
|
20
65
|
end
|
|
21
66
|
|
|
22
67
|
class ZertifikatParameter < FFI::Struct
|
|
@@ -37,7 +82,10 @@ module Liberic
|
|
|
37
82
|
:drucke, (1 << 5),
|
|
38
83
|
:pruefe_hinweise, (1 << 7),
|
|
39
84
|
:validiere_ohne_freigabedatum, (1 << 8),
|
|
40
|
-
|
|
85
|
+
# Not an ERiC flag: validiere | sende | drucke, kept for compatibility.
|
|
86
|
+
# ERiC uses these flags for sending and printing with and without
|
|
87
|
+
# authentication (Process action :print_and_submit).
|
|
88
|
+
:sende_auth, ('00100110'.to_i(2))
|
|
41
89
|
)
|
|
42
90
|
|
|
43
91
|
ERIC_LOG_ERROR = 4
|
data/lib/liberic/sdk.rb
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
require 'liberic/sdk/configuration'
|
|
2
2
|
require 'liberic/sdk/fehlercodes'
|
|
3
3
|
require 'liberic/sdk/types'
|
|
4
|
-
require 'liberic/sdk/api'
|
|
5
4
|
require 'liberic/sdk/def'
|
|
5
|
+
|
|
6
|
+
module Liberic
|
|
7
|
+
module SDK
|
|
8
|
+
# Liberic::SDK::API loads the ERiC library and is defined by Liberic.boot!
|
|
9
|
+
# (which <tt>require 'liberic'</tt> calls).
|
|
10
|
+
def self.const_missing(name)
|
|
11
|
+
return super unless name == :API
|
|
12
|
+
|
|
13
|
+
raise Liberic::InitializationError.new('ERiC is not loaded yet; call Liberic.boot! first')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require "rake"
|
|
2
|
+
require "liberic/eric_installer"
|
|
3
|
+
|
|
4
|
+
# Rake tasks for applications that use Liberic. Load them in a Rakefile with
|
|
5
|
+
#
|
|
6
|
+
# require "liberic/tasks"
|
|
7
|
+
#
|
|
8
|
+
# and install the ERiC SDK with
|
|
9
|
+
#
|
|
10
|
+
# bundle exec rake eric:install # into ./.eric
|
|
11
|
+
# bundle exec rake "eric:install[/opt/myapp]" # into /opt/myapp/.eric
|
|
12
|
+
# ERIC_INSTALL_ROOT=/opt/myapp bundle exec rake eric:install
|
|
13
|
+
# ERIC_VERSION=43.5.4.0 bundle exec rake eric:install
|
|
14
|
+
#
|
|
15
|
+
# The task argument takes precedence over ERIC_INSTALL_ROOT; without either,
|
|
16
|
+
# the SDK is installed below the current directory (Rake's working directory
|
|
17
|
+
# is the directory of the Rakefile).
|
|
18
|
+
namespace :eric do
|
|
19
|
+
desc "Download and install the ERiC Linux x86-64 SDK and documentation (into ROOT/.eric, default: current directory)"
|
|
20
|
+
task :install, [:root] do |_task, args|
|
|
21
|
+
root = args[:root] || ENV["ERIC_INSTALL_ROOT"] || Dir.pwd
|
|
22
|
+
version = ENV.fetch("ERIC_VERSION", Liberic::EricInstaller::DEFAULT_VERSION)
|
|
23
|
+
Liberic::EricInstaller.new(version: version, root: root).install
|
|
24
|
+
rescue Liberic::EricInstaller::InstallError => error
|
|
25
|
+
abort "eric:install failed: #{error.message}"
|
|
26
|
+
end
|
|
27
|
+
end
|
data/lib/liberic/version.rb
CHANGED
data/lib/liberic.rb
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'nokogiri'
|
|
3
|
-
require 'logger'
|
|
4
|
-
require 'liberic/version'
|
|
5
|
-
require 'liberic/boot'
|
|
6
|
-
require 'liberic/certificate'
|
|
7
|
-
require 'liberic/helpers'
|
|
8
|
-
require 'liberic/response'
|
|
9
|
-
require 'liberic/sdk'
|
|
10
|
-
require 'liberic/process'
|
|
11
|
-
require 'liberic/config'
|
|
1
|
+
require 'liberic/core'
|
|
12
2
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def config
|
|
19
|
-
@config ||= Config.new
|
|
20
|
-
end
|
|
21
|
-
end
|
|
3
|
+
# Requiring 'liberic' loads and initializes ERiC immediately, using ERIC_HOME
|
|
4
|
+
# (or ERIC_HOME_40). Require 'liberic/core' and call Liberic.boot! to choose
|
|
5
|
+
# the time and the ERiC options yourself.
|
|
6
|
+
Liberic.boot! unless Liberic.booted?
|