Module: Linzer::Helper
- Included in:
- Linzer
- Defined in:
- lib/linzer/helper.rb
Instance Method Summary collapse
- #sign!(request_or_response, **args) ⇒ Object
- #verify!(request_or_response, key: nil, no_older_than: 900) ⇒ Object
Instance Method Details
#sign!(request_or_response, **args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/linzer/helper.rb', line 5 def sign!(request_or_response, **args) = Message.new(request_or_response) = {} label = args[:label] [:label] = label if label .merge!(args.fetch(:params, {})) key = args.fetch(:key) signature = Linzer::Signer.sign(key, , args.fetch(:components), ) .attach!(signature) end |
#verify!(request_or_response, key: nil, no_older_than: 900) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/linzer/helper.rb', line 18 def verify!(request_or_response, key: nil, no_older_than: 900) = Message.new(request_or_response) signature_headers = {} %w[signature-input signature].each do |name| value = .header(name) signature_headers[name] = value if value end signature = Signature.build(signature_headers) keyid = signature.parameters["keyid"] raise Linzer::Error, "key not found" if !key && !keyid verify_key = block_given? ? (yield keyid) : key Linzer.verify(verify_key, , signature, no_older_than: no_older_than) end |