protocol-zmtp 0.1.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 041cc13ea6667319835f40ea09fae02b68cc34f988d986548691e29d48fee7ba
4
- data.tar.gz: 2d396b42d33c473c0f45a0752da9ab8c292d5541464ea1cb2c667a3508297fc6
3
+ metadata.gz: dafca992ff161d0cdb81664bfc85fd7f9194517222dcb5d11426a35c6a5f1c38
4
+ data.tar.gz: 9176b6c3090ef6ccaab8c37bb95d00f781a91c38a57606f08215ccaaf835726c
5
5
  SHA512:
6
- metadata.gz: 2d71dd3c5f2ad463b72c6160d8a70691a60baefe469503d59f9a2d8a80294554afaa4fdcc0a9a3ea1db19f5dcca9fda3df599ca14b6b8f9866ab90c07069294d
7
- data.tar.gz: 9b5b1a1d7966fc893e08c840a2ec929eacc32f874fe5f42e8b2064fbde6be1d2b01eebfde4a4ec78ea086884ddb5363dcd5c21e0c719186a65bee475bf19d3b0
6
+ metadata.gz: 0aeecc4dd2454e4953ca64a5211aae337cc05846a348434f90cecd258495aefcac9489dc264df65dcbe9e7d0c266436ecdca355c80a8e4423a4b6c052d904f91
7
+ data.tar.gz: f725b19d48b976315b64e2c1f44663f0454db080a737de074f84a77122e623e8673afb7d662627972d680b6b9af7c209aab90c4c95a1a2654706b5daefe89dd9
@@ -73,7 +73,7 @@ module Protocol
73
73
  # @return [Frame]
74
74
  # @raise [Error] on invalid frame
75
75
  # @raise [EOFError] if the connection is closed
76
- def self.read_from(io)
76
+ def self.read_from(io, max_message_size: nil)
77
77
  flags = io.read_exactly(1).getbyte(0)
78
78
 
79
79
  more = (flags & FLAGS_MORE) != 0
@@ -86,6 +86,10 @@ module Protocol
86
86
  io.read_exactly(1).getbyte(0)
87
87
  end
88
88
 
89
+ if max_message_size && size > max_message_size
90
+ raise Error, "frame size #{size} exceeds max_message_size #{max_message_size}"
91
+ end
92
+
89
93
  body = size > 0 ? io.read_exactly(size) : "".b
90
94
 
91
95
  new(body, more: more, command: command)
@@ -160,18 +160,18 @@ module Protocol
160
160
  # @raise [EOFError] if connection is closed
161
161
  def read_frame
162
162
  loop do
163
- frame = Codec::Frame.read_from(@io)
163
+ begin
164
+ frame = Codec::Frame.read_from(@io, max_message_size: @max_message_size)
165
+ rescue Error
166
+ close
167
+ raise
168
+ end
164
169
  touch_heartbeat
165
170
 
166
171
  if @mechanism.encrypted? && frame.body.bytesize > 8 && frame.body.byteslice(0, 8) == "\x07MESSAGE".b
167
172
  frame = @mechanism.decrypt(frame)
168
173
  end
169
174
 
170
- if @max_message_size && !frame.command? && frame.body.bytesize > @max_message_size
171
- close
172
- raise Error, "frame size #{frame.body.bytesize} exceeds max_message_size #{@max_message_size}"
173
- end
174
-
175
175
  if frame.command?
176
176
  cmd = Codec::Command.from_body(frame.body)
177
177
  case cmd.name
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Protocol
4
4
  module ZMTP
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-zmtp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger