fast-client-cert 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: f27aad5b7fc3911cd283e690e6e669465347b1dcf3aedf3967ae5b484a5f139d
4
- data.tar.gz: 4f6647b97d200dd511d96be6f91547f8d94c23cf027538ac678e8dddf4a7b631
3
+ metadata.gz: 7a9616145c03677b955c1cf9105a07a323c0887f9f03808d1ce058bdeffb2ca9
4
+ data.tar.gz: 9aed1ac3ed3bc2f66c133a7f5ae7b3b3c1b21251602aba1c6d07e72368ffa0b0
5
5
  SHA512:
6
- metadata.gz: 690290ae8ae83bafec6c6bf07f9b94f5373ff04669f59e50e6894a67d6c8f620943006cd89573fae642a33febc14503586e5c78d49c498382816c7ee4f5964bd
7
- data.tar.gz: 571f536aa57d826a8c3f0230da47c6ebb75624b43b475d04eefb211ec5f641a38681f81d9ee82c4fd4423278d9b66d548783b43c40932aa106f25a40db326367
6
+ metadata.gz: 8f6ebba578f44e421fabd3cc38229579116661377ed6ed04f931a45426f09f7fce921ea83ede3a353be2cd1161de851184d731791708191111f49cb8819e2586
7
+ data.tar.gz: f819a009b1da634ead14359d3bd0e0f1b60db51b8d81dd2eaa731b966a6ae3aab6801195e6ea6771acc3685ab9e0aebe6ab9ad99bccf26bb94bf859d2b195cfe
data/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2 (2026-11-27)
4
+
5
+ - Fixed: the PEM block guard refuses a payload region of blank lines
6
+ alone — Error, "the PEM block carries no payload", instead of
7
+ emitting the empty Byte Sequence `::` — a DER-encoded X.509
8
+ certificate is never zero bytes (§2.1), the same refusal the empty
9
+ Byte Sequence gets at the shared Checks seam since 0.1.1.
10
+ - Fixed: the parse, construction and emit boundaries never send a
11
+ message into the value they are checking — the shared Checks seam
12
+ (`byte_sequence?`, and what a constraint error shows of the
13
+ offender: its class, or the placeholder "a classless object" —
14
+ never the value's own `inspect`), both constructions, and
15
+ `Chain#split`'s per_line guard read the value with the
16
+ never-dispatch forms (`case value when Klass`, `Module#===`), so a
17
+ classless value (a `BasicObject` descendant) at a boundary raises
18
+ the documented error class instead of escaping the error contract
19
+ as a raw `NoMethodError`.
20
+ - Fixed: requirement messages lead with the requirement — "the value
21
+ must be a Byte Sequence, received …", "a member must be a Byte
22
+ Sequence, received …", "per_line must be a positive Integer,
23
+ received …" — so no message reads as if the received value were
24
+ the required one.
25
+
3
26
  ## 0.1.1 (2026-11-27)
4
27
 
5
28
  - Fixed: the strict `parse!` positions member errors through the
data/README.md CHANGED
@@ -56,7 +56,7 @@ Fast::ClientCert::Cert.valid?("!!") # => false
56
56
  begin
57
57
  Fast::ClientCert::Cert.parse!("5")
58
58
  rescue Fast::ClientCert::ParseError => e
59
- e.message # => "Client-Cert: the value is a Byte Sequence (got Integer)"
59
+ e.message # => "Client-Cert: the value must be a Byte Sequence, received Integer"
60
60
  e.offset # => 0
61
61
  end
62
62
  ```
@@ -55,7 +55,7 @@ module Fast
55
55
  return from_item(item) if Checks.byte_sequence?(item.value)
56
56
 
57
57
  raise ParseError.new(
58
- "Client-Cert: the value is a Byte Sequence (got #{Checks.shown(item)})", value_offset(input)
58
+ "Client-Cert: the value must be a Byte Sequence, received #{Checks.shown(item)}", value_offset(input)
59
59
  )
60
60
  rescue SFV::ParseError => e
61
61
  raise ParseError.new(e.message, e.offset)
@@ -111,7 +111,7 @@ module Fast
111
111
  # SerializeError before anything is emitted.
112
112
  def initialize(der)
113
113
  unless Checks.byte_sequence?(der)
114
- raise SerializeError.new("Client-Cert: the value is a Byte Sequence (got #{Checks.shown(der)})", 0)
114
+ raise SerializeError.new("Client-Cert: the value must be a Byte Sequence, received #{Checks.shown(der)}", 0)
115
115
  end
116
116
 
117
117
  hold(SFV::Item.new(der.freeze, EMPTY_PARAMS))
@@ -73,7 +73,7 @@ module Fast
73
73
  member = members[index]
74
74
  unless member_ok?(member)
75
75
  raise ParseError.new(
76
- "a Client-Cert-Chain member is a Byte Sequence (got #{Checks.shown(member)})",
76
+ "a Client-Cert-Chain member must be a Byte Sequence, received #{Checks.shown(member)}",
77
77
  member_offset(input, index)
78
78
  )
79
79
  end
@@ -144,14 +144,19 @@ module Fast
144
144
  # Anything else raises SerializeError before anything is
145
145
  # emitted.
146
146
  def initialize(ders)
147
- unless ders.is_a?(Array)
148
- raise SerializeError.new("Client-Cert-Chain members are an Array (got #{ders.class})", 0)
147
+ case ders
148
+ when Array
149
+ nil
150
+ else
151
+ raise SerializeError.new("Client-Cert-Chain members must be an Array, received #{shape(ders)}", 0)
149
152
  end
150
153
 
151
154
  items = []
152
155
  ders.each do |der|
153
156
  unless Checks.byte_sequence?(der)
154
- raise SerializeError.new("a Client-Cert-Chain member is a Byte Sequence (got #{Checks.shown(der)})", 0)
157
+ raise SerializeError.new(
158
+ "a Client-Cert-Chain member must be a Byte Sequence, received #{Checks.shown(der)}", 0
159
+ )
155
160
  end
156
161
 
157
162
  items << Item.new(der.freeze, EMPTY_PARAMS)
@@ -202,9 +207,13 @@ module Fast
202
207
  # a caller bug — ArgumentError, never a field error. The empty
203
208
  # chain answers no lines.
204
209
  def split(per_line)
205
- unless per_line.is_a?(Integer) && per_line.positive?
206
- raise ArgumentError, "per_line is a positive Integer (got #{per_line.inspect})"
207
- end
210
+ valid = case per_line
211
+ when Integer
212
+ per_line.positive?
213
+ else
214
+ false
215
+ end
216
+ raise ArgumentError, "per_line must be a positive Integer, received #{shape(per_line)}" unless valid
208
217
 
209
218
  lines = []
210
219
  index = 0
@@ -236,6 +245,13 @@ module Fast
236
245
 
237
246
  private
238
247
 
248
+ # The class of a value an error message names, or a placeholder
249
+ # when the value has none (a BasicObject descendant) — the
250
+ # message never calls a method on the value it is rejecting.
251
+ def shape(value)
252
+ defined?(value.class) ? value.class : "a classless object"
253
+ end
254
+
239
255
  # The one place the held state is written, then frozen: the
240
256
  # members as parsed (or as built), and the DERs view derived
241
257
  # from them.
@@ -34,12 +34,13 @@ module Fast
34
34
  # payload line stripped of the whitespace around it, generous the
35
35
  # way textual encodings need. Blank lines may lead and follow the
36
36
  # block; CRLF line endings are tolerated. Armor-shape failures
37
- # raise Error: no BEGIN line, the END missing, no payload, or
37
+ # raise Error: no BEGIN line, the END missing, no payload (a
38
+ # payload region of blank lines alone carries no payload), or
38
39
  # content other than blank lines after the END (a second block —
39
40
  # one PEM block at a time; pass an Array of blocks to
40
41
  # pems_to_field for a chain). TypeError for a non-String.
41
42
  def pem_to_field(pem)
42
- raise TypeError, "a PEM block is a String (got #{pem.class})" unless pem.is_a?(String)
43
+ raise TypeError, "a PEM block must be a String, received #{pem.class}" unless pem.is_a?(String)
43
44
 
44
45
  lines = pem.split("\n", -1)
45
46
  first = 0
@@ -54,9 +55,11 @@ module Fast
54
55
  unless first_armor_line(lines, first, last) == last
55
56
  raise Error, "one PEM block at a time — pass an Array of blocks for a chain"
56
57
  end
57
- raise Error, "the PEM block carries no payload" unless last - first > 1
58
58
 
59
- ":#{lines[first + 1...last].map(&:strip).join}:"
59
+ base64 = lines[first + 1...last].map(&:strip).join
60
+ raise Error, "the PEM block carries no payload" if base64.empty?
61
+
62
+ ":#{base64}:"
60
63
  end
61
64
 
62
65
  # The inverse: ":<base64>:" → one RFC 7468 block — the base64
@@ -66,7 +69,7 @@ module Fast
66
69
  # interior, or Error is raised before anything is written.
67
70
  # TypeError for a non-String.
68
71
  def field_to_pem(field)
69
- raise TypeError, "a field value is a String (got #{field.class})" unless field.is_a?(String)
72
+ raise TypeError, "a field value must be a String, received #{field.class}" unless field.is_a?(String)
70
73
 
71
74
  base64 = base64_interior(field)
72
75
  block = "#{BEGIN_ARMOR}\n"
@@ -86,7 +89,7 @@ module Fast
86
89
  # ", " separator. The empty Array raises Error — nothing to
87
90
  # convert. TypeError for a non-Array.
88
91
  def pems_to_field(blocks)
89
- raise TypeError, "blocks are an Array of PEM Strings (got #{blocks.class})" unless blocks.is_a?(Array)
92
+ raise TypeError, "blocks must be an Array of PEM Strings, received #{blocks.class}" unless blocks.is_a?(Array)
90
93
  raise Error, "nothing to convert — the blocks Array is empty" if blocks.empty?
91
94
 
92
95
  blocks.map { |block| pem_to_field(block) }.join(", ")
@@ -104,7 +107,7 @@ module Fast
104
107
  # base Error carrying the region scan's own message. The empty
105
108
  # value answers no blocks. TypeError for a non-String.
106
109
  def field_to_pems(field)
107
- raise TypeError, "a field value is a String (got #{field.class})" unless field.is_a?(String)
110
+ raise TypeError, "a field value must be a String, received #{field.class}" unless field.is_a?(String)
108
111
  return [].freeze if field.empty?
109
112
 
110
113
  regions = SFV.regions_list(field)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fast
4
4
  module ClientCert
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -76,16 +76,29 @@ module Fast
76
76
  # boundary reads: both strict parses, both constructions, and
77
77
  # both fail-closed falls.
78
78
  def byte_sequence?(value)
79
- value.is_a?(String) && !value.is_a?(SFV::Token) && value.encoding == BINARY && !value.empty?
79
+ case value
80
+ when SFV::Token
81
+ false
82
+ when String
83
+ value.encoding == BINARY && !value.empty?
84
+ else
85
+ false
86
+ end
80
87
  end
81
88
 
82
89
  # What a constraint error shows of the offender: the value's
83
- # inspect when it is String-shaped, its class otherwise — an
84
- # Item unwrapped first (an inner list shows its own class,
85
- # Fast::SFV::InnerList).
90
+ # class — never a method call into the value, which a classless
91
+ # object (a BasicObject descendant) would refuse — or the
92
+ # placeholder when it has none. An Item is unwrapped first (an
93
+ # inner list shows its own class, Fast::SFV::InnerList).
86
94
  def shown(shape)
87
- value = shape.is_a?(SFV::Item) ? shape.value : shape
88
- value.is_a?(String) ? value.inspect : value.class
95
+ value = case shape
96
+ when SFV::Item
97
+ shape.value
98
+ else
99
+ shape
100
+ end
101
+ defined?(value.class) ? value.class : "a classless object"
89
102
  end
90
103
  end
91
104
  private_constant :Checks
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast-client-cert
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