Class: PkiExpress::PadesSigner

Inherits:
Signer show all
Defined in:
lib/pki_express/pades_signer.rb

Instance Attribute Summary collapse

Attributes inherited from Signer

#cert_password, #cert_thumb, #output_file_path, #trust_service_session

Attributes inherited from PkiExpressOperator

#culture, #offline, #signature_policy, #time_zone, #timestamp_authority, #trust_lacuna_test_root

Instance Method Summary collapse

Methods inherited from Signer

#pkcs12, #pkcs12=, #pkcs12_base64, #pkcs12_base64=, #pkcs12_path, #pkcs12_path=

Methods inherited from PkiExpressOperator

#add_file_reference, #add_trusted_root, finalize

Constructor Details

#initialize(config = PkiExpressConfig.new) ⇒ PadesSigner

Returns a new instance of PadesSigner.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/pki_express/pades_signer.rb', line 7

def initialize(config=PkiExpressConfig.new)
  super(config)
  @pdf_to_sign_path = nil
  @vr_json_path = nil
  @overwrite_original_file = false
  @version_manager = VersionManager.new
  @custom_signature_field_name = nil
  @certification_level = nil
  @reason = nil
  @suppress_default_visual_representation = false
end

Instance Attribute Details

#certification_levelObject

Returns the value of attribute certification_level.



5
6
7
# File 'lib/pki_express/pades_signer.rb', line 5

def certification_level
  @certification_level
end

#custom_signature_field_nameObject

Returns the value of attribute custom_signature_field_name.



5
6
7
# File 'lib/pki_express/pades_signer.rb', line 5

def custom_signature_field_name
  @custom_signature_field_name
end

#overwrite_original_fileObject

Returns the value of attribute overwrite_original_file.



4
5
6
# File 'lib/pki_express/pades_signer.rb', line 4

def overwrite_original_file
  @overwrite_original_file
end

#reasonObject

Returns the value of attribute reason.



5
6
7
# File 'lib/pki_express/pades_signer.rb', line 5

def reason
  @reason
end

#suppress_default_visual_representationObject

Returns the value of attribute suppress_default_visual_representation.



4
5
6
# File 'lib/pki_express/pades_signer.rb', line 4

def suppress_default_visual_representation
  @suppress_default_visual_representation
end

Instance Method Details

#pdf_to_signObject

region The “pdf_to_sign” accessors



108
109
110
# File 'lib/pki_express/pades_signer.rb', line 108

def pdf_to_sign
  _get_pdf_to_sign
end

#pdf_to_sign=(content_raw) ⇒ Object



121
122
123
# File 'lib/pki_express/pades_signer.rb', line 121

def pdf_to_sign=(content_raw)
  _set_pdf_to_sign(content_raw)
end

#pdf_to_sign_base64Object



138
139
140
# File 'lib/pki_express/pades_signer.rb', line 138

def pdf_to_sign_base64
  _get_pdf_to_sign_base64
end

#pdf_to_sign_base64=(content_base64) ⇒ Object



152
153
154
# File 'lib/pki_express/pades_signer.rb', line 152

def pdf_to_sign_base64=(content_base64)
  _set_pdf_to_sign_base64(content_base64)
end

#pdf_to_sign_pathObject



171
172
173
# File 'lib/pki_express/pades_signer.rb', line 171

def pdf_to_sign_path
  _get_pdf_to_sign_path
end

#pdf_to_sign_path=(path) ⇒ Object



180
181
182
# File 'lib/pki_express/pades_signer.rb', line 180

def pdf_to_sign_path=(path)
  _set_pdf_to_sign_path(path)
end

#sign(get_cert = false) ⇒ Object

endregion



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/pki_express/pades_signer.rb', line 197

def sign(get_cert=false)
  unless @pdf_to_sign_path
    raise 'The PDF to be signed was not set'
  end

  unless @overwrite_original_file || @output_file_path
    raise 'The output destination was not set'
  end

  args = [
    @pdf_to_sign_path,
  ]

  # Logic to overwrite original file or use the output file
  if @overwrite_original_file
    args.append('--overwrite')
  else
    args.append(@output_file_path)
  end

  # Verify and add common options between signers.
  verify_and_add_common_options(args)

  if @vr_json_path
    args.append('--visual-rep')
    args.append(@vr_json_path)
  end

  if @custom_signature_field_name
    args.append('--custom-signature-field-name')
    args.append(@custom_signature_field_name)
    # This option can only be used on versions greater than 1.15.0 of the
    # PKI Express.
    @version_manager.require_version('1.15')
  end

  if @certification_level
    args.append('--certification-level')
    args.append(@certification_level)
    # This option can only be used on versions greater than 1.16.0 of the
    # PKI Express.
    @version_manager.require_version('1.16')
  end

  if @suppress_default_visual_representation
    args.append('--suppress-default-visual-rep')
    # This option can only be used on versions greater than 1.13.1 of the
    # PKI Express.
    @version_manager.require_version('1.13.1')
  end

  if @reason
    args.append('--reason')
    args.append(@reason)
    # This option can only be used on versions greater than 1.13 of the
    # PKI Express.
    @version_manager.require_version('1.13')
  end

  if get_cert
    # This option can only be used on versions greater than 1.8.0 of the
    # PKI Express.
    @version_manager.require_version('1.8')

    # Invoke command.
    result = invoke(Commands::SIGN_PADES, args)

    # Parse output and return result.
    model = parse_output(result)
    return PKCertificate.new(model.fetch(:signer))
  else  
    # Invoke command with plain text output (to support PKI Express < 1.3)
    result = invoke_plain(Commands::SIGN_PADES, args)
  end

end

#visual_representationObject



75
76
77
# File 'lib/pki_express/pades_signer.rb', line 75

def visual_representation
  _get_visual_representation
end

#visual_representation=(vr) ⇒ Object



90
91
92
# File 'lib/pki_express/pades_signer.rb', line 90

def visual_representation=(vr)
  _set_visual_representation(vr)
end

#visual_representation_content_rawObject

region set_visual_representation



21
22
23
# File 'lib/pki_express/pades_signer.rb', line 21

def visual_representation_content_raw
  _get_visual_representation_content_raw
end

#visual_representation_content_raw=(content_raw) ⇒ Object



34
35
36
# File 'lib/pki_express/pades_signer.rb', line 34

def visual_representation_content_raw=(content_raw)
  _set_visual_representation_content_raw(content_raw)
end

#visual_representation_pathObject



51
52
53
# File 'lib/pki_express/pades_signer.rb', line 51

def visual_representation_path
  _get_visual_representation_path
end

#visual_representation_path=(path) ⇒ Object



60
61
62
# File 'lib/pki_express/pades_signer.rb', line 60

def visual_representation_path=(path)
  _set_visual_representation_path(path)
end