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 +4 -4
- data/CHANGELOG.md +17 -0
- data/lib/fast/digest/fields.rb +60 -21
- data/lib/fast/digest/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 296372695a413ae755dae16a386d286b242c73d594dde02faefa2349e29a13af
|
|
4
|
+
data.tar.gz: '0428aa8369ee0b623a3bf04e6e0457b7d7d55421d25bc6836cc6c41e96b6bf94'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/lib/fast/digest/fields.rb
CHANGED
|
@@ -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}
|
|
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
|
-
|
|
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)}
|
|
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
|
|
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
|
-
|
|
307
|
+
case key
|
|
308
|
+
when String
|
|
309
|
+
size = key.bytesize
|
|
310
|
+
return false if size.zero? || !KEY_FIRST[key.getbyte(0)]
|
|
296
311
|
|
|
297
|
-
|
|
298
|
-
|
|
312
|
+
index = 1
|
|
313
|
+
while index < size
|
|
314
|
+
return false unless KEY_BODY[key.getbyte(index)]
|
|
299
315
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
data/lib/fast/digest/version.rb
CHANGED