pki_express 1.3.1 → 1.3.2

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -2
  3. data/.github/workflows/test.yml +21 -21
  4. data/.gitignore +27 -27
  5. data/CHANGELOG.md +19 -16
  6. data/Gemfile +8 -7
  7. data/README.md +24 -24
  8. data/Rakefile +6 -6
  9. data/lib/pki_express/auth_complete_result.rb +21 -21
  10. data/lib/pki_express/auth_start_result.rb +76 -76
  11. data/lib/pki_express/authentication.rb +284 -284
  12. data/lib/pki_express/base_signer.rb +54 -54
  13. data/lib/pki_express/cades_signature.rb +89 -89
  14. data/lib/pki_express/cades_signature_starter.rb +242 -242
  15. data/lib/pki_express/check_service_result.rb +15 -15
  16. data/lib/pki_express/command_error.rb +13 -13
  17. data/lib/pki_express/commands.rb +24 -24
  18. data/lib/pki_express/digest_algorithm.rb +118 -118
  19. data/lib/pki_express/digest_algorithm_and_value.rb +30 -30
  20. data/lib/pki_express/discovery_service_result.rb +25 -25
  21. data/lib/pki_express/enum.rb +9 -9
  22. data/lib/pki_express/error_codes.rb +46 -46
  23. data/lib/pki_express/installation_not_found_error.rb +8 -8
  24. data/lib/pki_express/name.rb +47 -47
  25. data/lib/pki_express/oids.rb +30 -30
  26. data/lib/pki_express/pades_certification_level.rb +7 -7
  27. data/lib/pki_express/pades_horizontal_align.rb +9 -9
  28. data/lib/pki_express/pades_measurement_units.rb +8 -8
  29. data/lib/pki_express/pades_page_optimization.rb +50 -50
  30. data/lib/pki_express/pades_page_orientation.rb +9 -9
  31. data/lib/pki_express/pades_paper_size.rb +21 -21
  32. data/lib/pki_express/pades_signature.rb +16 -16
  33. data/lib/pki_express/pades_signature_explorer.rb +30 -30
  34. data/lib/pki_express/pades_signature_starter.rb +251 -251
  35. data/lib/pki_express/pades_signer.rb +274 -274
  36. data/lib/pki_express/pades_signer_info.rb +9 -9
  37. data/lib/pki_express/pades_size.rb +17 -17
  38. data/lib/pki_express/pades_text_horizontal_align.rb +8 -8
  39. data/lib/pki_express/pades_vertical_align.rb +9 -9
  40. data/lib/pki_express/pades_visual_auto_positioning.rb +21 -21
  41. data/lib/pki_express/pades_visual_image.rb +51 -51
  42. data/lib/pki_express/pades_visual_manual_positioning.rb +16 -16
  43. data/lib/pki_express/pades_visual_positioning.rb +27 -27
  44. data/lib/pki_express/pades_visual_rectangle.rb +74 -74
  45. data/lib/pki_express/pades_visual_representation.rb +22 -22
  46. data/lib/pki_express/pades_visual_text.rb +35 -35
  47. data/lib/pki_express/pk_algorithms.rb +157 -157
  48. data/lib/pki_express/pk_certificate.rb +61 -61
  49. data/lib/pki_express/pki_brazil_certificate_fields.rb +57 -57
  50. data/lib/pki_express/pki_brazil_certificate_types.rb +19 -19
  51. data/lib/pki_express/pki_express_config.rb +39 -26
  52. data/lib/pki_express/pki_express_operator.rb +240 -240
  53. data/lib/pki_express/pki_italy_certificate_fields.rb +15 -15
  54. data/lib/pki_express/pki_italy_certificate_types.rb +11 -11
  55. data/lib/pki_express/signature_algorithm_and_value.rb +34 -34
  56. data/lib/pki_express/signature_explorer.rb +74 -74
  57. data/lib/pki_express/signature_finisher.rb +314 -314
  58. data/lib/pki_express/signature_policy_identifier.rb +20 -20
  59. data/lib/pki_express/signature_start_result.rb +12 -12
  60. data/lib/pki_express/signature_starter.rb +116 -116
  61. data/lib/pki_express/signer.rb +151 -151
  62. data/lib/pki_express/standard_signature_policies.rb +58 -58
  63. data/lib/pki_express/timestamp_authority.rb +50 -50
  64. data/lib/pki_express/trust_service_auth_parameters.rb +20 -20
  65. data/lib/pki_express/trust_service_info.rb +37 -37
  66. data/lib/pki_express/trust_service_manager.rb +258 -258
  67. data/lib/pki_express/trust_service_session_result.rb +29 -29
  68. data/lib/pki_express/trust_service_session_types.rb +7 -7
  69. data/lib/pki_express/tsa_authentication_type.rb +14 -14
  70. data/lib/pki_express/validation_error.rb +8 -8
  71. data/lib/pki_express/validation_item.rb +43 -43
  72. data/lib/pki_express/validation_item_types.rb +103 -103
  73. data/lib/pki_express/validation_results.rb +120 -120
  74. data/lib/pki_express/version.rb +3 -3
  75. data/lib/pki_express/version_manager.rb +20 -20
  76. data/lib/pki_express.rb +69 -69
  77. data/pki_express.gemspec +26 -26
  78. data/spec/pki_express/pki_express_config_spec.rb +73 -0
  79. data/spec/pki_express/pki_express_operator_spec.rb +30 -30
  80. metadata +4 -2
@@ -1,158 +1,158 @@
1
- module PkiExpress
2
- class SignatureAlgorithms < Enum
3
- MD5_WITH_RSA = 'MD5WithRSA'
4
- SHA1_WITH_RSA = 'SHA1WithRSA'
5
- SHA256_WITH_RSA = 'SHA256WithRSA'
6
- SHA384_WITH_RSA = 'SHA384WithRSA'
7
- SHA512_WITH_RSA = 'SHA512WithRSA'
8
- end
9
-
10
- class PKAlgorithms < Enum
11
- RSA = 'RSA'
12
- end
13
-
14
- class SignatureAlgorithm
15
- attr_accessor :name, :oid, :xml_uri, :digest_algorithm, :pk_algorithm
16
-
17
- def initialize(name, oid, xml_uri, digest_algorithm, pk_algorithm)
18
- @name = name
19
- @oid = oid
20
- @xml_uri = xml_uri
21
- @digest_algorithm = digest_algorithm
22
- @pk_algorithm = pk_algorithm
23
- end
24
-
25
- def md5_with_rsa
26
- unless @md5_with_rsa
27
- @md5_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.md5)
28
- end
29
- end
30
-
31
- def sha1_with_rsa
32
- unless @sha1_with_rsa
33
- @sha1_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.sha1)
34
- end
35
- end
36
-
37
- def sha256_with_rsa
38
- unless @sha256_with_rsa
39
- @sha256_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.sha256)
40
- end
41
- end
42
-
43
- def sha384_with_rsa
44
- unless @sha384_with_rsa
45
- @sha384_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.sha384)
46
- end
47
- end
48
-
49
- def sha512_with_rsa
50
- unless @sha512_with_rsa
51
- @sha512_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.sha512)
52
- end
53
- end
54
-
55
- def self.algorithms
56
- return [md5_with_rsa, sha1_with_rsa, sha256_with_rsa, sha384_with_rsa, sha512_with_rsa]
57
- end
58
-
59
- def self.safe_algorithms
60
- return [sha1_with_rsa, sha256_with_rsa, sha384_with_rsa, sha512_with_rsa]
61
- end
62
- private_class_method :algorithms, :safe_algorithms, :new
63
-
64
- class << SignatureAlgorithm
65
- def get_instance_by_name(name)
66
- algorithms
67
- unless @algorithms.select{|v| v.name == name}.empty?
68
- return @algorithms.select{|v| v.name == name}.first
69
- end
70
- raise 'Unrecognized signature algorithm name: ' + name
71
- end
72
-
73
- def get_instance_by_oid(oid)
74
- algorithms
75
- unless @algorithms.select{|v| v.oid == oid}.empty?
76
- return @algorithms.select{|v| v.oid == oid}.first
77
- end
78
- raise 'Unrecognized signature algorithm oid: ' + oid
79
- end
80
-
81
- def get_instance_by_xml_uri(xml_uri)
82
- algorithms
83
- unless @algorithms.select{|v| v.xml_uri == xml_uri}.empty?
84
- return @algorithms.select{|v| v.xml_uri == xml_uri}.first
85
- end
86
- raise 'Unrecognized signature algorithm XML URI: ' + xml_uri
87
- end
88
-
89
- def get_instance_by_api_model(api_model)
90
- algorithms
91
- unless @algorithms.select{|v| v.api_model.downcase == api_model.downcase}.empty?
92
- return @algorithms.select{|v| v.api_model.downcase == api_model.downcase}.first
93
- end
94
- raise 'Unrecognized signature algorithm: ' + api_model
95
- end
96
- end
97
- end
98
-
99
- class RSASignatureAlgorithm < SignatureAlgorithm
100
- def initialize(digest_algorithm)
101
- case digest_algorithm
102
- when DigestAlgorithm.md5
103
- xml_uri = xml_uri = 'http://www.w3.org/2001/04/xmldsig-more#rsa-md5'
104
- oid = Oids::MD5_WITH_RSA
105
- when DigestAlgorithm.sha1
106
- xml_uri = 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'
107
- oid = Oids::SHA1_WITH_RSA
108
- when DigestAlgorithm.sha256
109
- xml_uri = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'
110
- oid = Oids::SHA256_WITH_RSA
111
- when DigestAlgorithm.sha384
112
- xml_uri = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384'
113
- oid = Oids::SHA384_WITH_RSA
114
- when DigestAlgorithm.sha512
115
- xml_uri = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512'
116
- oid = Oids::SHA512_WITH_RSA
117
- else
118
- raise 'Unsupported digest algorithms: ' + digest_algorithm.oid
119
- end
120
-
121
- super(
122
- digest_algorithm.name + " with RSA",
123
- oid,
124
- xml_uri,
125
- digest_algorithm,
126
- PKAlgorithms::RSA)
127
- end
128
- end
129
-
130
- class PKAlgorithm
131
- attr_accessor :name, :oid
132
-
133
- def initialize(name, oid)
134
- @name = name
135
- @oid = oid
136
- end
137
-
138
- def rsa
139
- RSAPKAlgorithm.new
140
- end
141
-
142
- def self.algorithms
143
- return [rsa]
144
- end
145
- private_class_method :new, :algorithms
146
- end
147
-
148
- class RSAPKAlgorithm < PKAlgorithm
149
- def initialize
150
- super(PKAlgorithms::RSA, Oids::RSA)
151
- end
152
- class << RSAPKAlgorithm
153
- def get_signature_algorithm(digest_algorithm)
154
- RSASignatureAlgorithm.new(digest_algorithm)
155
- end
156
- end
157
- end
1
+ module PkiExpress
2
+ class SignatureAlgorithms < Enum
3
+ MD5_WITH_RSA = 'MD5WithRSA'
4
+ SHA1_WITH_RSA = 'SHA1WithRSA'
5
+ SHA256_WITH_RSA = 'SHA256WithRSA'
6
+ SHA384_WITH_RSA = 'SHA384WithRSA'
7
+ SHA512_WITH_RSA = 'SHA512WithRSA'
8
+ end
9
+
10
+ class PKAlgorithms < Enum
11
+ RSA = 'RSA'
12
+ end
13
+
14
+ class SignatureAlgorithm
15
+ attr_accessor :name, :oid, :xml_uri, :digest_algorithm, :pk_algorithm
16
+
17
+ def initialize(name, oid, xml_uri, digest_algorithm, pk_algorithm)
18
+ @name = name
19
+ @oid = oid
20
+ @xml_uri = xml_uri
21
+ @digest_algorithm = digest_algorithm
22
+ @pk_algorithm = pk_algorithm
23
+ end
24
+
25
+ def md5_with_rsa
26
+ unless @md5_with_rsa
27
+ @md5_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.md5)
28
+ end
29
+ end
30
+
31
+ def sha1_with_rsa
32
+ unless @sha1_with_rsa
33
+ @sha1_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.sha1)
34
+ end
35
+ end
36
+
37
+ def sha256_with_rsa
38
+ unless @sha256_with_rsa
39
+ @sha256_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.sha256)
40
+ end
41
+ end
42
+
43
+ def sha384_with_rsa
44
+ unless @sha384_with_rsa
45
+ @sha384_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.sha384)
46
+ end
47
+ end
48
+
49
+ def sha512_with_rsa
50
+ unless @sha512_with_rsa
51
+ @sha512_with_rsa = RSASignatureAlgorithm.new(DigestAlgorithm.sha512)
52
+ end
53
+ end
54
+
55
+ def self.algorithms
56
+ return [md5_with_rsa, sha1_with_rsa, sha256_with_rsa, sha384_with_rsa, sha512_with_rsa]
57
+ end
58
+
59
+ def self.safe_algorithms
60
+ return [sha1_with_rsa, sha256_with_rsa, sha384_with_rsa, sha512_with_rsa]
61
+ end
62
+ private_class_method :algorithms, :safe_algorithms, :new
63
+
64
+ class << SignatureAlgorithm
65
+ def get_instance_by_name(name)
66
+ algorithms
67
+ unless @algorithms.select{|v| v.name == name}.empty?
68
+ return @algorithms.select{|v| v.name == name}.first
69
+ end
70
+ raise 'Unrecognized signature algorithm name: ' + name
71
+ end
72
+
73
+ def get_instance_by_oid(oid)
74
+ algorithms
75
+ unless @algorithms.select{|v| v.oid == oid}.empty?
76
+ return @algorithms.select{|v| v.oid == oid}.first
77
+ end
78
+ raise 'Unrecognized signature algorithm oid: ' + oid
79
+ end
80
+
81
+ def get_instance_by_xml_uri(xml_uri)
82
+ algorithms
83
+ unless @algorithms.select{|v| v.xml_uri == xml_uri}.empty?
84
+ return @algorithms.select{|v| v.xml_uri == xml_uri}.first
85
+ end
86
+ raise 'Unrecognized signature algorithm XML URI: ' + xml_uri
87
+ end
88
+
89
+ def get_instance_by_api_model(api_model)
90
+ algorithms
91
+ unless @algorithms.select{|v| v.api_model.downcase == api_model.downcase}.empty?
92
+ return @algorithms.select{|v| v.api_model.downcase == api_model.downcase}.first
93
+ end
94
+ raise 'Unrecognized signature algorithm: ' + api_model
95
+ end
96
+ end
97
+ end
98
+
99
+ class RSASignatureAlgorithm < SignatureAlgorithm
100
+ def initialize(digest_algorithm)
101
+ case digest_algorithm
102
+ when DigestAlgorithm.md5
103
+ xml_uri = xml_uri = 'http://www.w3.org/2001/04/xmldsig-more#rsa-md5'
104
+ oid = Oids::MD5_WITH_RSA
105
+ when DigestAlgorithm.sha1
106
+ xml_uri = 'http://www.w3.org/2000/09/xmldsig#rsa-sha1'
107
+ oid = Oids::SHA1_WITH_RSA
108
+ when DigestAlgorithm.sha256
109
+ xml_uri = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'
110
+ oid = Oids::SHA256_WITH_RSA
111
+ when DigestAlgorithm.sha384
112
+ xml_uri = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha384'
113
+ oid = Oids::SHA384_WITH_RSA
114
+ when DigestAlgorithm.sha512
115
+ xml_uri = 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512'
116
+ oid = Oids::SHA512_WITH_RSA
117
+ else
118
+ raise 'Unsupported digest algorithms: ' + digest_algorithm.oid
119
+ end
120
+
121
+ super(
122
+ digest_algorithm.name + " with RSA",
123
+ oid,
124
+ xml_uri,
125
+ digest_algorithm,
126
+ PKAlgorithms::RSA)
127
+ end
128
+ end
129
+
130
+ class PKAlgorithm
131
+ attr_accessor :name, :oid
132
+
133
+ def initialize(name, oid)
134
+ @name = name
135
+ @oid = oid
136
+ end
137
+
138
+ def rsa
139
+ RSAPKAlgorithm.new
140
+ end
141
+
142
+ def self.algorithms
143
+ return [rsa]
144
+ end
145
+ private_class_method :new, :algorithms
146
+ end
147
+
148
+ class RSAPKAlgorithm < PKAlgorithm
149
+ def initialize
150
+ super(PKAlgorithms::RSA, Oids::RSA)
151
+ end
152
+ class << RSAPKAlgorithm
153
+ def get_signature_algorithm(digest_algorithm)
154
+ RSASignatureAlgorithm.new(digest_algorithm)
155
+ end
156
+ end
157
+ end
158
158
  end
@@ -1,62 +1,62 @@
1
- module PkiExpress
2
-
3
- class PKCertificate
4
-
5
- attr_accessor :subject_name, :email_address, :issuer_name, :serial_number,
6
- :validity_start, :validity_end, :pki_brazil, :pki_italy,
7
- :issuer, :binary_thumbprint_sha256, :thumbprint
8
-
9
- def initialize(model)
10
- @subject_name = nil
11
- @email_address = nil
12
- @issuer_name = nil
13
- @serial_number = nil
14
- @validity_start = nil
15
- @validity_end = nil
16
- @pki_brazil = nil
17
- @pki_italy = nil
18
- @issuer = nil
19
- @binary_thumbprint_sha256 = nil
20
- @thumbprint = nil
21
-
22
- unless model.nil?
23
- @email_address = model.fetch(:emailAddress)
24
- @serial_number = model.fetch(:serialNumber)
25
- @validity_start = model.fetch(:validityStart)
26
- @validity_end = model.fetch(:validityEnd)
27
- @thumbprint = model.fetch(:thumbprint)
28
-
29
- subject_name = model.fetch(:subjectName)
30
- if subject_name
31
- @subject_name = Name.new(subject_name)
32
- end
33
-
34
- issuer_name = model.fetch(:issuerName)
35
- if issuer_name
36
- @issuer_name = Name.new(issuer_name)
37
- end
38
-
39
- pki_brazil = model.fetch(:pkiBrazil)
40
- if pki_brazil
41
- @pki_brazil = PkiBrazilCertificateFields.new(pki_brazil)
42
- end
43
-
44
- pki_italy = model.fetch(:pkiItaly)
45
- if pki_italy
46
- @pki_italy = PkiItalyCertificateFields.new(pki_italy)
47
- end
48
-
49
- issuer = model.fetch(:issuer)
50
- if issuer
51
- @issuer = PKCertificate.new(issuer)
52
- end
53
-
54
- binary_thumbprint_sha256 = model.fetch(:binaryThumbprintSHA256)
55
- if binary_thumbprint_sha256
56
- @binary_thumbprint_sha256 = Base64.decode64(binary_thumbprint_sha256)
57
- end
58
- end
59
- end
60
- end
61
-
1
+ module PkiExpress
2
+
3
+ class PKCertificate
4
+
5
+ attr_accessor :subject_name, :email_address, :issuer_name, :serial_number,
6
+ :validity_start, :validity_end, :pki_brazil, :pki_italy,
7
+ :issuer, :binary_thumbprint_sha256, :thumbprint
8
+
9
+ def initialize(model)
10
+ @subject_name = nil
11
+ @email_address = nil
12
+ @issuer_name = nil
13
+ @serial_number = nil
14
+ @validity_start = nil
15
+ @validity_end = nil
16
+ @pki_brazil = nil
17
+ @pki_italy = nil
18
+ @issuer = nil
19
+ @binary_thumbprint_sha256 = nil
20
+ @thumbprint = nil
21
+
22
+ unless model.nil?
23
+ @email_address = model.fetch(:emailAddress)
24
+ @serial_number = model.fetch(:serialNumber)
25
+ @validity_start = model.fetch(:validityStart)
26
+ @validity_end = model.fetch(:validityEnd)
27
+ @thumbprint = model.fetch(:thumbprint)
28
+
29
+ subject_name = model.fetch(:subjectName)
30
+ if subject_name
31
+ @subject_name = Name.new(subject_name)
32
+ end
33
+
34
+ issuer_name = model.fetch(:issuerName)
35
+ if issuer_name
36
+ @issuer_name = Name.new(issuer_name)
37
+ end
38
+
39
+ pki_brazil = model.fetch(:pkiBrazil)
40
+ if pki_brazil
41
+ @pki_brazil = PkiBrazilCertificateFields.new(pki_brazil)
42
+ end
43
+
44
+ pki_italy = model.fetch(:pkiItaly)
45
+ if pki_italy
46
+ @pki_italy = PkiItalyCertificateFields.new(pki_italy)
47
+ end
48
+
49
+ issuer = model.fetch(:issuer)
50
+ if issuer
51
+ @issuer = PKCertificate.new(issuer)
52
+ end
53
+
54
+ binary_thumbprint_sha256 = model.fetch(:binaryThumbprintSHA256)
55
+ if binary_thumbprint_sha256
56
+ @binary_thumbprint_sha256 = Base64.decode64(binary_thumbprint_sha256)
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
62
  end
@@ -1,58 +1,58 @@
1
- module PkiExpress
2
-
3
- class PkiBrazilCertificateFields
4
-
5
- attr_accessor :rg_emissor_uf, :cnpj, :rg_numero, :oab_numero, :company_name,
6
- :rg_emissor, :certificate_type, :cpf, :responsavel,
7
- :date_of_birth, :oab_uf
8
-
9
- def initialize(model)
10
- @certificate_type = nil
11
- @cpf = nil
12
- @cnpj = nil
13
- @responsavel = nil
14
- @date_of_birth = nil
15
- @company_name = nil
16
- @rg_numero = nil
17
- @rg_emissor = nil
18
- @rg_emissor_uf = nil
19
- @oab_numero = nil
20
- @oab_uf = nil
21
-
22
- unless model.nil?
23
- @certificate_type = model.fetch(:certificateType)
24
- @cpf = model.fetch(:cpf)
25
- @cnpj = model.fetch(:cnpj)
26
- @responsavel = model.fetch(:responsavel)
27
- @date_of_birth = model.fetch(:dateOfBirth)
28
- @company_name = model.fetch(:companyName)
29
- @rg_numero = model.fetch(:rgNumero)
30
- @rg_emissor = model.fetch(:rgEmissor)
31
- @rg_emissor_uf = model.fetch(:rgEmissorUF)
32
- @oab_numero = model.fetch(:oabNumero)
33
- @oab_uf = model.fetch(:oabUF)
34
- end
35
- end
36
-
37
- def cpf_formatted
38
- unless @cpf
39
- return nil
40
- end
41
- unless /^\d{11}$/.match(@cpf)
42
- return @cpf
43
- end
44
- "#{@cpf[0..2]}.#{@cpf[3..5]}.#{@cpf[6..8]}-#{@cpf[9..-1]}"
45
- end
46
-
47
- def cnpj_formatted
48
- unless @cnpj
49
- return nil
50
- end
51
- unless /^\d{14}$/.match(@cnpj)
52
- return @cnpj
53
- end
54
- "#{@cnpj[0..1]}.#{@cnpj[2..4]}.#{@cnpj[5..7]}/#{@cnpj[8..11]}-#{@cnpj[12..-1]}"
55
- end
56
- end
57
-
1
+ module PkiExpress
2
+
3
+ class PkiBrazilCertificateFields
4
+
5
+ attr_accessor :rg_emissor_uf, :cnpj, :rg_numero, :oab_numero, :company_name,
6
+ :rg_emissor, :certificate_type, :cpf, :responsavel,
7
+ :date_of_birth, :oab_uf
8
+
9
+ def initialize(model)
10
+ @certificate_type = nil
11
+ @cpf = nil
12
+ @cnpj = nil
13
+ @responsavel = nil
14
+ @date_of_birth = nil
15
+ @company_name = nil
16
+ @rg_numero = nil
17
+ @rg_emissor = nil
18
+ @rg_emissor_uf = nil
19
+ @oab_numero = nil
20
+ @oab_uf = nil
21
+
22
+ unless model.nil?
23
+ @certificate_type = model.fetch(:certificateType)
24
+ @cpf = model.fetch(:cpf)
25
+ @cnpj = model.fetch(:cnpj)
26
+ @responsavel = model.fetch(:responsavel)
27
+ @date_of_birth = model.fetch(:dateOfBirth)
28
+ @company_name = model.fetch(:companyName)
29
+ @rg_numero = model.fetch(:rgNumero)
30
+ @rg_emissor = model.fetch(:rgEmissor)
31
+ @rg_emissor_uf = model.fetch(:rgEmissorUF)
32
+ @oab_numero = model.fetch(:oabNumero)
33
+ @oab_uf = model.fetch(:oabUF)
34
+ end
35
+ end
36
+
37
+ def cpf_formatted
38
+ unless @cpf
39
+ return nil
40
+ end
41
+ unless /^\d{11}$/.match(@cpf)
42
+ return @cpf
43
+ end
44
+ "#{@cpf[0..2]}.#{@cpf[3..5]}.#{@cpf[6..8]}-#{@cpf[9..-1]}"
45
+ end
46
+
47
+ def cnpj_formatted
48
+ unless @cnpj
49
+ return nil
50
+ end
51
+ unless /^\d{14}$/.match(@cnpj)
52
+ return @cnpj
53
+ end
54
+ "#{@cnpj[0..1]}.#{@cnpj[2..4]}.#{@cnpj[5..7]}/#{@cnpj[8..11]}-#{@cnpj[12..-1]}"
55
+ end
56
+ end
57
+
58
58
  end
@@ -1,19 +1,19 @@
1
- module PkiExpress
2
- class PkiBrazilCertificateTypes < Enum
3
- UNKNOWN = 'Unknown'
4
- A1 = 'A1'
5
- A2 = 'A2'
6
- A3 = 'A3'
7
- A4 = 'A4'
8
- S1 = 'S1'
9
- S2 = 'S2'
10
- S3 = 'S3'
11
- S4 = 'S4'
12
- T3 = 'T3'
13
- T4 = 'T4'
14
-
15
- VALUES = [
16
- UNKNOWN, A1, A2, A3, A4, S1, S2, S3, S4, T3, T4
17
- ]
18
- end
19
- end
1
+ module PkiExpress
2
+ class PkiBrazilCertificateTypes < Enum
3
+ UNKNOWN = 'Unknown'
4
+ A1 = 'A1'
5
+ A2 = 'A2'
6
+ A3 = 'A3'
7
+ A4 = 'A4'
8
+ S1 = 'S1'
9
+ S2 = 'S2'
10
+ S3 = 'S3'
11
+ S4 = 'S4'
12
+ T3 = 'T3'
13
+ T4 = 'T4'
14
+
15
+ VALUES = [
16
+ UNKNOWN, A1, A2, A3, A4, S1, S2, S3, S4, T3, T4
17
+ ]
18
+ end
19
+ end
@@ -1,26 +1,39 @@
1
- module PkiExpress
2
-
3
- class PkiExpressConfig
4
- attr_accessor :pki_express_home, :temp_folder, :transfer_data_folder
5
- @@single_temp_folder = nil
6
-
7
- def initialize(pki_express_home = nil, temp_folder = nil, transfer_data_folder = nil)
8
- if not temp_folder.nil? and Pathname.new(temp_folder).exist?
9
- @temp_folder = temp_folder
10
- else
11
- if @@single_temp_folder.nil?
12
- @@single_temp_folder = Dir.mktmpdir('pkie')
13
- end
14
- @temp_folder = @@single_temp_folder
15
- end
16
-
17
- if not transfer_data_folder.nil? and Pathname.new(transfer_data_folder).exist?
18
- @transfer_data_folder = transfer_data_folder
19
- else
20
- @transfer_data_folder = @temp_folder
21
- end
22
-
23
- @pki_express_home = pki_express_home
24
- end
25
- end
26
- end
1
+ require 'pathname'
2
+
3
+ module PkiExpress
4
+
5
+ class PkiExpressConfig
6
+ attr_accessor :pki_express_home, :temp_folder, :transfer_data_folder
7
+ @@single_temp_folder = nil
8
+
9
+ def initialize(pki_express_home = nil, temp_folder = nil, transfer_data_folder = nil)
10
+ if not temp_folder.nil?
11
+ if Pathname.new(temp_folder).exist?
12
+ @temp_folder = temp_folder
13
+ else
14
+ raise ArgumentError.new "the provided temp_folder is not valid"
15
+ end
16
+ else
17
+ if @@single_temp_folder.nil?
18
+ @@single_temp_folder = Dir.mktmpdir('pkie')
19
+ end
20
+ @temp_folder = @@single_temp_folder
21
+ end
22
+
23
+ if not transfer_data_folder.nil?
24
+ if Pathname.new(transfer_data_folder).exist?
25
+ @transfer_data_folder = transfer_data_folder
26
+ else
27
+ raise ArgumentError.new "the provided transfer_data_folder is not valid"
28
+ end
29
+ else
30
+ @transfer_data_folder = @temp_folder
31
+ end
32
+
33
+ if not pki_express_home.nil? and not File.directory?(pki_express_home)
34
+ raise ArgumentError.new "the provided pki_express_home is not valid"
35
+ end
36
+ @pki_express_home = pki_express_home
37
+ end
38
+ end
39
+ end