as2 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0225c8faac2c9bb92938878b8f2f2f919c50589d368fe4480d5ad96541d3e0ca
4
- data.tar.gz: 897d1831f060e7ee248e2a0a6031d5b76d47b5f099d3d46ef93a000a78712873
3
+ metadata.gz: 2cc88a7c3befd19715a142f886fcac0429911b1b2c6d4df8e5c6f6797c6469c2
4
+ data.tar.gz: ba6943a989242be148d7e39c896f61747b8455888883b60ff179d6bf53e25309
5
5
  SHA512:
6
- metadata.gz: 0c2a13a733a35bf8a284077258a52ed3e1da95d4c70b23053b220ff89050178be6a4478f859aba6c341866295dc1abf501ddae322f83ddcc38a297adea4c6559
7
- data.tar.gz: af1bfdcad847e185db4cb1b0be09b2c49e8b6d8d8cf77c2abe8357fcaae1e8f5018688088eb8161e30fcf3c820b5fc6c0c5e3ade286123f2a51087697f105089
6
+ metadata.gz: 14dc1ecb69d8678db913d9ee2425ae35f3e2e1b9a927a3a573e36e9a704dd4a7ab994d7c98182bf0053f40520040f0001fbc8b1390c82ebd57aa7e5c3495e99c
7
+ data.tar.gz: e43327ebbeac9bd46a2ccc4e3cd13f6354de46a3507fe01b134ecf33feef6643555c63e2ad2310debf8b3a23ec88c985d869087bf4cce29a2c54d8d06cfa753a
data/as2.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Simple AS2 server and client implementation}
13
13
  spec.description = %q{Simple AS2 server and client implementation. Follows the AS2 implementation from http://as2.mendelson-e-c.com}
14
- spec.homepage = "https://github.com/andjosh/as2"
14
+ spec.homepage = "https://github.com/alexdean/as2"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
data/lib/as2/message.rb CHANGED
@@ -2,6 +2,28 @@ module As2
2
2
  class Message
3
3
  attr_reader :verification_error
4
4
 
5
+ # given multiple parts of a message, choose the one most likely to be the actual content we care about
6
+ #
7
+ # @param [Array<Mail::Part>]
8
+ # @return [Mail::Part, nil]
9
+ def self.choose_attachment(mail_parts)
10
+ return nil if mail_parts.nil?
11
+
12
+ # if there are multiple content parts, try to prefer the EDI content.
13
+ candidates = mail_parts
14
+ .select { |part| part.content_type.to_s['pkcs7-signature'].nil? } # skip signature
15
+ .sort_by { |part| part.content_type.to_s.match(/^application\/edi/i) ? 0 : 1 }
16
+ candidates[0]
17
+ end
18
+
19
+ # @param [Mail::Part] attachment
20
+ # @param [String] mic_algorithm
21
+ # @return [String] message integrity check string
22
+ def self.mic(attachment, mic_algorithm)
23
+ digest = As2::DigestSelector.for_code(mic_algorithm)
24
+ digest.base64digest(attachment.raw_source.lstrip)
25
+ end
26
+
5
27
  def initialize(message, private_key, public_certificate)
6
28
  # TODO: might need to use OpenSSL::PKCS7.read_smime rather than .new sometimes
7
29
  @pkcs7 = OpenSSL::PKCS7.new(message)
@@ -80,8 +102,7 @@ module As2
80
102
  end
81
103
 
82
104
  def mic
83
- digest = As2::DigestSelector.for_code(mic_algorithm)
84
- digest.base64digest(attachment.raw_source.strip)
105
+ self.class.mic(attachment, mic_algorithm)
85
106
  end
86
107
 
87
108
  def mic_algorithm
@@ -90,13 +111,11 @@ module As2
90
111
 
91
112
  # Return the attached file, use .filename and .body on the return value
92
113
  def attachment
93
- if mail.has_attachments?
94
- # TODO: match 'application/edi*', test with 'application/edi-x12'
95
- # test also with "application/edi-consent; name=this_is_a_filename.txt"
96
- mail.parts.find{ |a| a.content_type.match(/^application\/edi/) }
97
- else
98
- mail
99
- end
114
+ self.class.choose_attachment(parts)
115
+ end
116
+
117
+ def parts
118
+ mail&.parts
100
119
  end
101
120
 
102
121
  private
data/lib/as2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module As2
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: as2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - OfficeLuv
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-08-10 00:00:00.000000000 Z
12
+ date: 2022-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mail
@@ -168,7 +168,7 @@ files:
168
168
  - lib/as2/mime_generator.rb
169
169
  - lib/as2/server.rb
170
170
  - lib/as2/version.rb
171
- homepage: https://github.com/andjosh/as2
171
+ homepage: https://github.com/alexdean/as2
172
172
  licenses:
173
173
  - MIT
174
174
  metadata: