Class: OpenID::Server::SigningEncoder

Inherits:
Encoder
  • Object
show all
Defined in:
lib/openid/server.rb

Overview

I encode responses in to WebResponses, signing them when required.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(signatory) ⇒ SigningEncoder

Create a SigningEncoder given a Signatory



1214
1215
1216
# File 'lib/openid/server.rb', line 1214

def initialize(signatory)
  @signatory = signatory
end

Instance Attribute Details

#signatoryObject

Returns the value of attribute signatory.



1211
1212
1213
# File 'lib/openid/server.rb', line 1211

def signatory
  @signatory
end

Instance Method Details

#encode(response) ⇒ Object

Encode a response to a WebResponse, signing it first if appropriate.

Raises EncodingError when I can’t figure out how to encode this message.

Raises AlreadySigned when this response is already signed.



1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
# File 'lib/openid/server.rb', line 1225

def encode(response)
  # the is_a? is a bit of a kludge... it means there isn't
  # really an adapter to make the interfaces quite match.
  if !response.is_a?(Exception) and response.needs_signing
    unless @signatory
      raise ArgumentError.new(
        format(
          "Must have a store to sign this request: %s",
          response,
        ),
        response,
      )
    end

    raise AlreadySigned.new(response) if response.fields.has_key?(OPENID_NS, "sig")

    response = @signatory.sign(response)
  end

  super
end