linzer 0.8.0.beta1 → 0.8.0.beta2

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.
@@ -150,11 +150,11 @@ module Linzer
150
150
  def to_h
151
151
  return @headers if @headers
152
152
 
153
- items = @parsed_items || serialized_components.map { |c| Starry.parse_item(c) }
153
+ items = @parsed_items || serialized_components.map { |c| HTTP::StructuredField.parse_item(c) }
154
154
  {
155
- "signature" => Starry.serialize({label => value}),
156
- "signature-input" => Starry.serialize({
157
- label => Starry::InnerList.new(items, parameters)
155
+ "signature" => HTTP::StructuredField.serialize({label => value}),
156
+ "signature-input" => HTTP::StructuredField.serialize({
157
+ label => HTTP::StructuredField::InnerList.new(items, parameters)
158
158
  })
159
159
  }
160
160
  end
@@ -168,7 +168,7 @@ module Linzer
168
168
  # Clone items that have parameters since the adapter's retrieve
169
169
  # method may mutate parameters (e.g., deleting "req").
170
170
  unless item.parameters.empty?
171
- item = Starry::Item.new(item.value, item.parameters.dup)
171
+ item = HTTP::StructuredField::Item.new(item.value, item.parameters.dup)
172
172
  end
173
173
  Message::Field::FastIdentifier.new(serialized, item)
174
174
  end
@@ -234,9 +234,14 @@ module Linzer
234
234
  def build(headers, options = {})
235
235
  basic_validate headers
236
236
  headers.transform_keys!(&:downcase)
237
+ headers.transform_values! { |v| v.encode(Encoding::ASCII) }
237
238
  validate headers
238
239
 
239
- input = parse_structured_field(headers, "signature-input")
240
+ input = HTTP::StructuredField.parse_dictionary(
241
+ headers["signature-input"],
242
+ field_name: "signature-input"
243
+ )
244
+
240
245
  reject_multiple_signatures if input.size > 1 && options[:label].nil?
241
246
  label = options[:label] || input.keys.first
242
247
 
@@ -316,51 +321,36 @@ module Linzer
316
321
  end
317
322
 
318
323
  # Label not found via fast path — fall back to Starry
319
- signature = parse_structured_dictionary(
320
- value.encode(Encoding::US_ASCII), "signature"
324
+ signature = HTTP::StructuredField.parse_dictionary(
325
+ value.encode(Encoding::US_ASCII),
326
+ field_name: "signature"
321
327
  )
322
328
  fail_with_signature_not_found label unless signature.key?(label)
323
329
  signature[label].value.force_encoding(Encoding::ASCII_8BIT)
324
330
  rescue ArgumentError
325
331
  # Base64 decode failed — fall back to Starry
326
- signature = parse_structured_dictionary(
327
- value.encode(Encoding::US_ASCII), "signature"
328
- )
332
+ signature = HTTP::StructuredField.parse_dictionary(
333
+ value.encode(Encoding::US_ASCII),
334
+ field_name: "signature")
329
335
  fail_with_signature_not_found label unless signature.key?(label)
330
336
  signature[label].value.force_encoding(Encoding::ASCII_8BIT)
331
337
  end
332
338
 
333
- # Serializes parsed Starry items to their string representations
334
- # without going through the generic Starry.serialize_item path.
339
+ # Serializes parsed structured field items to their RFC 8941
340
+ # string representations.
335
341
  #
336
- # For simple items (no parameters): builds '"value"' directly.
337
- # For items with parameters: falls back to Starry.serialize_item.
342
+ # Serialization is delegated to `Starry.serialize_item` to ensure
343
+ # consistent RFC-compliant formatting of structured field items and
344
+ # parameters.
345
+ #
346
+ # @param items [Array<Starry::Item>]
347
+ # Parsed structured field items.
348
+ #
349
+ # @return [Array<String>]
350
+ # The serialized structured field item representations.
338
351
  #
339
- # @param items [Array<Starry::Item>] parsed items from signature-input
340
- # @return [Array<String>] serialized component identifiers
341
352
  def serialize_parsed_items(items)
342
- items.map do |item|
343
- if item.parameters.empty?
344
- "\"#{item.value}\""
345
- else
346
- Starry.serialize_item(item)
347
- end
348
- end
349
- end
350
-
351
- def parse_structured_dictionary(str, field_name = nil)
352
- Starry.parse_dictionary(str)
353
- rescue Starry::ParseError => _
354
- raise Error.new "Cannot parse \"#{field_name}\" field. Bailing out!"
355
- end
356
-
357
- # Parses a structured field value as a dictionary.
358
- # @see https://datatracker.ietf.org/doc/html/rfc8941 RFC 8941
359
- def parse_structured_field(hsh, field_name)
360
- # Serialized Structured Field values for HTTP are ASCII strings.
361
- # See: RFC 8941 (https://datatracker.ietf.org/doc/html/rfc8941)
362
- value = hsh[field_name].encode(Encoding::US_ASCII)
363
- parse_structured_dictionary(value, field_name)
353
+ items.map { |item| HTTP::StructuredField.serialize_item(item) }
364
354
  end
365
355
  end
366
356
  end
@@ -3,5 +3,5 @@
3
3
  module Linzer
4
4
  # Current version of the Linzer gem.
5
5
  # @return [String]
6
- VERSION = "0.8.0.beta1"
6
+ VERSION = "0.8.0.beta2"
7
7
  end
data/lib/linzer.rb CHANGED
@@ -6,12 +6,17 @@ require "uri"
6
6
  require "net/http"
7
7
 
8
8
  require_relative "linzer/version"
9
+ require_relative "linzer/http"
10
+ require_relative "linzer/http/structured_field"
9
11
  require_relative "linzer/common"
12
+ require_relative "linzer/signature/context"
13
+ require_relative "linzer/signature/profile"
10
14
  require_relative "linzer/helper"
11
15
  require_relative "linzer/options"
12
16
  require_relative "linzer/message"
13
17
  require_relative "linzer/message/adapter"
14
18
  require_relative "linzer/message/wrapper"
19
+ require_relative "linzer/message/overlay"
15
20
  require_relative "linzer/message/field"
16
21
  require_relative "linzer/message/field/parser"
17
22
  require_relative "linzer/signature"
@@ -24,8 +29,6 @@ require_relative "linzer/ecdsa"
24
29
  require_relative "linzer/key/helper"
25
30
  require_relative "linzer/signer"
26
31
  require_relative "linzer/verifier"
27
- require_relative "linzer/http"
28
- require_relative "linzer/http/structured_field"
29
32
 
30
33
  # Linzer is a Ruby library for HTTP Message Signatures as defined in RFC 9421.
31
34
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.beta1
4
+ version: 0.8.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Landaeta
@@ -160,12 +160,18 @@ files:
160
160
  - lib/linzer/message/adapter/rack/response.rb
161
161
  - lib/linzer/message/field.rb
162
162
  - lib/linzer/message/field/parser.rb
163
+ - lib/linzer/message/overlay.rb
163
164
  - lib/linzer/message/wrapper.rb
164
165
  - lib/linzer/options.rb
165
166
  - lib/linzer/rack.rb
166
167
  - lib/linzer/rsa.rb
167
168
  - lib/linzer/rsa_pss.rb
168
169
  - lib/linzer/signature.rb
170
+ - lib/linzer/signature/context.rb
171
+ - lib/linzer/signature/profile.rb
172
+ - lib/linzer/signature/profile/base.rb
173
+ - lib/linzer/signature/profile/example.rb
174
+ - lib/linzer/signature/profile/web_bot_auth.rb
169
175
  - lib/linzer/signer.rb
170
176
  - lib/linzer/verifier.rb
171
177
  - lib/linzer/version.rb