fast-digest 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: fddcfc33cf91f6457a2e5c21c8a0bde3ab8782c9d291463ea2f26c55e778b12a
4
- data.tar.gz: 9797c3395f626e36c37e007224ed679d6c40f53e8bcabb49f9933eeebd336ebd
3
+ metadata.gz: 296372695a413ae755dae16a386d286b242c73d594dde02faefa2349e29a13af
4
+ data.tar.gz: '0428aa8369ee0b623a3bf04e6e0457b7d7d55421d25bc6836cc6c41e96b6bf94'
5
5
  SHA512:
6
- metadata.gz: dd23f679ff168f6eca58333b0b9ab0d9d74e0a46a381508f83b73036e81a03d818d46bebc3cc40ac14c88b1f3a349838e55852b134f9c0a5ff7dc4cb9a38200e
7
- data.tar.gz: 1eae3f9e55177263dd30634ea7b9460777286e710657f253d7509b29590c60272851acc9f94001f064101f6cb71785d695187af4b391a308b11e959669bc2e20
6
+ metadata.gz: c5a79b9939804150d7381a2cd6ce6f572e98b85aa16cba0560413651ea0b70f454fbf23b424a3217efb791aaac2129516e4f55d726abd48ce9cbe39e6269a744
7
+ data.tar.gz: 8866c2d440693ccea958077046eab4858b55d6631378ccb6e0723cb915996f046031d9e39e48016bd9cf7112c0d5cc95758c85ceeb1a36fbd0eb773f3fc4d935
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2 (2026-11-27)
4
+
5
+ - Fixed: the construction and parse boundaries never send a message
6
+ into the value they are checking — a field's members Hash, each
7
+ member's key (the Algorithm Key grammar) and value, and the strict
8
+ `parse!`'s first-offender report read the value with the
9
+ never-dispatch forms (`case value when Klass`, `Module#===`), so a
10
+ classless value (a `BasicObject` descendant) at a boundary raises
11
+ the documented `SerializeError` — or the parse-side `ParseError` —
12
+ instead of escaping the error contract as a raw `NoMethodError`.
13
+ The message names the value's class — or the placeholder "a
14
+ classless object" — never the value's own `inspect` or another
15
+ method it answers.
16
+ - Fixed: requirement messages lead with the requirement — "members
17
+ must be a Hash, received …", "<key>: <rule>, received …" — so no
18
+ message reads as if the received value were the required one.
19
+
3
20
  ## 0.1.1 (2026-11-27)
4
21
 
5
22
  - Fixed: the strict `parse!` positions member errors through the
@@ -145,7 +145,7 @@ module Fast
145
145
  offsets[key] = member.value_start if violations.key?(key)
146
146
  end
147
147
  key = violations.keys.min_by { |offender| offsets.fetch(offender) }
148
- raise ParseError.new("#{key}: #{value_rule} (got #{shown(violations.fetch(key))})", offsets.fetch(key))
148
+ raise ParseError.new("#{key}: #{value_rule}, received #{shown(violations.fetch(key))}", offsets.fetch(key))
149
149
  end
150
150
 
151
151
  # What a semantic error shows of the offending member: the bare
@@ -185,7 +185,12 @@ module Fast
185
185
  # raises SerializeError before a member is built. The empty Hash
186
186
  # builds the empty value: a sender omits the field.
187
187
  def initialize(members = {})
188
- raise SerializeError.new("members are a Hash (got #{members.class})", 0) unless members.is_a?(Hash)
188
+ case members
189
+ when Hash
190
+ nil
191
+ else
192
+ raise SerializeError.new("members must be a Hash, received #{shape(members)}", 0)
193
+ end
189
194
 
190
195
  held = {}
191
196
  members.each do |key, value|
@@ -277,7 +282,14 @@ module Fast
277
282
  check_key(key)
278
283
  return if self.class.send(:value_ok?, value)
279
284
 
280
- raise SerializeError.new("#{key}: #{self.class.send(:value_rule)} (got #{value.inspect})", 0)
285
+ raise SerializeError.new("#{key}: #{self.class.send(:value_rule)}, received #{shape(value)}", 0)
286
+ end
287
+
288
+ # The class of a value an error message names, or a placeholder
289
+ # when the value has none (a BasicObject descendant) — the
290
+ # message never calls a method on the value it is rejecting.
291
+ def shape(value)
292
+ defined?(value.class) ? value.class : "a classless object"
281
293
  end
282
294
 
283
295
  # The Algorithm Key grammar, RFC 9651 §4.2.3.3 read from the value
@@ -286,24 +298,27 @@ module Fast
286
298
  def check_key(key)
287
299
  return if valid_key?(key)
288
300
 
289
- raise SerializeError.new("#{key.inspect} is not a Structured Fields key", 0)
301
+ raise SerializeError.new("#{shape(key)} is not a Structured Fields key", 0)
290
302
  end
291
303
 
292
304
  # The walk behind check_key — manual and allocation-free, the
293
305
  # shape the substrate's own key parse uses.
294
306
  def valid_key?(key)
295
- return false unless key.is_a?(String)
307
+ case key
308
+ when String
309
+ size = key.bytesize
310
+ return false if size.zero? || !KEY_FIRST[key.getbyte(0)]
296
311
 
297
- size = key.bytesize
298
- return false if size.zero? || !KEY_FIRST[key.getbyte(0)]
312
+ index = 1
313
+ while index < size
314
+ return false unless KEY_BODY[key.getbyte(index)]
299
315
 
300
- index = 1
301
- while index < size
302
- return false unless KEY_BODY[key.getbyte(index)]
303
-
304
- index += 1
316
+ index += 1
317
+ end
318
+ true
319
+ else
320
+ false
305
321
  end
306
- true
307
322
  end
308
323
  end
309
324
  private_constant :Field
@@ -323,13 +338,20 @@ module Fast
323
338
  # ASCII-8BIT and not a Token (the class is the token's tag), the
324
339
  # exact shape Fast::SFV emits as ":base64:".
325
340
  def self.value_ok?(value)
326
- value.is_a?(String) && !value.is_a?(Token) && value.encoding == BINARY
341
+ case value
342
+ when Token
343
+ false
344
+ when String
345
+ value.encoding == BINARY
346
+ else
347
+ false
348
+ end
327
349
  end
328
350
 
329
351
  # The wording a ParseError or SerializeError carries for a member
330
352
  # that breaks the constraint.
331
353
  def self.value_rule
332
- "a Content-Digest value is a Byte Sequence: a String tagged Encoding::ASCII_8BIT"
354
+ "a Content-Digest value must be a Byte Sequence: a String tagged Encoding::ASCII_8BIT"
333
355
  end
334
356
  private_class_method :value_ok?, :value_rule
335
357
 
@@ -357,13 +379,20 @@ module Fast
357
379
  # ASCII-8BIT and not a Token, the exact shape Fast::SFV emits as
358
380
  # ":base64:".
359
381
  def self.value_ok?(value)
360
- value.is_a?(String) && !value.is_a?(Token) && value.encoding == BINARY
382
+ case value
383
+ when Token
384
+ false
385
+ when String
386
+ value.encoding == BINARY
387
+ else
388
+ false
389
+ end
361
390
  end
362
391
 
363
392
  # The wording a ParseError or SerializeError carries for a member
364
393
  # that breaks the constraint.
365
394
  def self.value_rule
366
- "a Repr-Digest value is a Byte Sequence: a String tagged Encoding::ASCII_8BIT"
395
+ "a Repr-Digest value must be a Byte Sequence: a String tagged Encoding::ASCII_8BIT"
367
396
  end
368
397
  private_class_method :value_ok?, :value_rule
369
398
 
@@ -389,13 +418,18 @@ module Fast
389
418
  class WantContentDigest < Field
390
419
  # §4's member constraint: an Integer 0..10.
391
420
  def self.value_ok?(value)
392
- value.is_a?(Integer) && value.between?(0, 10)
421
+ case value
422
+ when Integer
423
+ value.between?(0, 10)
424
+ else
425
+ false
426
+ end
393
427
  end
394
428
 
395
429
  # The wording a ParseError or SerializeError carries for a member
396
430
  # that breaks the constraint.
397
431
  def self.value_rule
398
- "a Want-Content-Digest value is an Integer 0..10"
432
+ "a Want-Content-Digest value must be an Integer 0..10"
399
433
  end
400
434
  private_class_method :value_ok?, :value_rule
401
435
  end
@@ -408,13 +442,18 @@ module Fast
408
442
  class WantReprDigest < Field
409
443
  # §4's member constraint: an Integer 0..10.
410
444
  def self.value_ok?(value)
411
- value.is_a?(Integer) && value.between?(0, 10)
445
+ case value
446
+ when Integer
447
+ value.between?(0, 10)
448
+ else
449
+ false
450
+ end
412
451
  end
413
452
 
414
453
  # The wording a ParseError or SerializeError carries for a member
415
454
  # that breaks the constraint.
416
455
  def self.value_rule
417
- "a Want-Repr-Digest value is an Integer 0..10"
456
+ "a Want-Repr-Digest value must be an Integer 0..10"
418
457
  end
419
458
  private_class_method :value_ok?, :value_rule
420
459
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fast
4
4
  module Digest
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: fast-digest
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
  - Eric Jacobs