linzer 0.5.0 → 0.5.1

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: 026db131a5602b1f62b4f930086a0612b99f17a3aa6aa0eb649baa7bc8ba574b
4
- data.tar.gz: 8f29e81e3083257c4731c9e408f4a66a95125fdb4d0678fd8d16cc410637d694
3
+ metadata.gz: 1955734eb1a8115753448b579b0cbe84f7d1ad247677ae20dd49495841b4aef3
4
+ data.tar.gz: abf9b2fbc465f10210c77f3d29e10c7e15af26a5badba90516f0b96050e3a548
5
5
  SHA512:
6
- metadata.gz: 6edb3a943f2bcf408ed865fe8bec013c3b13e609ea791981474a84bb21936b2e5fa61d86e64f9e9917c0a3e440e6246d443761c81cd94c094898c78423137789
7
- data.tar.gz: 82074df18649f3f85af7c187762dbcf90b602c9748c9f6dba4695db42ee53ce24c5a546589f96011ab9d47564e1f9d2436a35616b54678e24f4222cd12f97837
6
+ metadata.gz: 5263ec042dd91dc5bc434f4bbccc8f17d0ec52c751b7b9adec613c87efa180175cc7e5b4f47da007e6e61298a2b153f9ca05250ba3d55786c2d5609725233903
7
+ data.tar.gz: 45ad9720b910f441bf36f9766ec10eaaab64fb7a36f420b947a5170d9cae0d18d540f380996eba2265b6faa0df0b9537fb1c8b2b2e58c94bab45abcaccb19112
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.1] - 2024-04-01
4
+
5
+ - Add support for additional derived components:
6
+ @target-uri, @scheme, @request-target, @query and @query-param.
7
+
3
8
  ## [0.5.0] - 2024-03-30
4
9
 
5
10
  - Build Linzer::Message instances from Rack request and response objects
data/README.md CHANGED
@@ -1,4 +1,11 @@
1
- # Linzer
1
+ # Linzer [![Latest Version][gem-badge]][gem-link] [![License: MIT][license-image]][license-link] [![CI Status][ci-image]][ci-link]
2
+
3
+ [gem-badge]: https://badge.fury.io/rb/linzer.svg
4
+ [gem-link]: https://rubygems.org/gems/linzer
5
+ [license-image]: https://img.shields.io/badge/license-MIT-blue.svg
6
+ [license-link]: https://github.com/nomadium/linzer/blob/master/LICENSE.txt
7
+ [ci-image]: https://github.com/nomadium/linzer/actions/workflows/main.yml/badge.svg?branch=master
8
+ [ci-link]: https://github.com/nomadium/linzer/actions/workflows/main.yml
2
9
 
3
10
  Linzer is a Ruby library for [HTTP Message Signatures (RFC 9421)](https://www.rfc-editor.org/rfc/rfc9421.html).
4
11
 
@@ -93,7 +100,10 @@ response = http.post("/some_uri", "data", headers.merge(signature.to_h))
93
100
  test_ed25519_key_pub = Base64.strict_encode64(key.material.verify_key.to_bytes)
94
101
  # => "EUra7KsJ8B/lSZJVhDaopMycmZ6T7KtJqKVNJTHKIw0="
95
102
 
96
- pubkey = Linzer.new_ed25519_public_key(test_ed25519_key_pub, "some-key-ed25519")
103
+ raw_pubkey = Base64.strict_decode64(test_ed25519_key_pub)
104
+ # => "\xB1rM\xFFR\x1F\xDDw\x00\x89\..."
105
+
106
+ pubkey = Linzer.new_ed25519_public_key(raw_pubkey, "some-key-ed25519")
97
107
  # => #<Linzer::Ed25519::Key:0x00000fe19b9384b0
98
108
 
99
109
  # if you have to, there is a helper method to build a request object on the server side
@@ -25,20 +25,33 @@ module Linzer
25
25
  !!self[f]
26
26
  end
27
27
 
28
+ DERIVED_COMPONENT = {
29
+ "@method" => :request_method,
30
+ "@authority" => :authority,
31
+ "@path" => :path_info,
32
+ "@status" => :status,
33
+ "@target-uri" => :url,
34
+ "@scheme" => :scheme,
35
+ "@request-target" => :fullpath,
36
+ "@query" => :query_string
37
+ }.freeze
38
+
28
39
  def [](field_name)
29
40
  if !field_name.start_with?("@")
30
41
  return @operation.env[Request.rack_header_name(field_name)] if request?
31
42
  return @operation.headers[field_name] # if response?
32
43
  end
33
44
 
45
+ method = DERIVED_COMPONENT[field_name]
46
+
34
47
  case field_name
35
- when "@method" then @operation.request_method
36
- when "@authority" then @operation.authority
37
- when "@path" then @operation.path_info
38
- when "@status" then @operation.status
39
- else # XXX: improve this and add support for all fields in the RFC
40
- raise Error.new "Unknown/unsupported field: \"#{field_name}\""
48
+ when "@query"
49
+ return "?#{@operation.public_send(method)}"
50
+ when /\A(?<field>(?<prefix>@query-param)(?<rest>;name=.+)\Z)/
51
+ return parse_query_param Regexp.last_match
41
52
  end
53
+
54
+ method ? @operation.public_send(method) : nil
42
55
  end
43
56
 
44
57
  class << self
@@ -48,5 +61,17 @@ module Linzer
48
61
  raise Error.new "Cannot parse \"#{field_name}\" field. Bailing out!"
49
62
  end
50
63
  end
64
+
65
+ private
66
+
67
+ def parse_query_param(match_data)
68
+ raw_item = '"%s"%s' % [match_data[:prefix], match_data[:rest]]
69
+ parsed_item = Starry.parse_item(raw_item)
70
+ fail unless parsed_item.value == "@query-param"
71
+ param_name = URI.decode_uri_component(parsed_item.parameters["name"])
72
+ URI.encode_uri_component(@operation.params.fetch(param_name))
73
+ rescue => _
74
+ nil
75
+ end
51
76
  end
52
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Linzer
4
- VERSION = "0.5.0"
4
+ VERSION = "0.5.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Landaeta
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-30 00:00:00.000000000 Z
11
+ date: 2024-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ed25519