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



1185
1186
1187
# File 'lib/openid/server.rb', line 1185

def initialize(signatory)
  @signatory = signatory
end

Instance Attribute Details

#signatoryObject

Returns the value of attribute signatory.



1182
1183
1184
# File 'lib/openid/server.rb', line 1182

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.



1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
# File 'lib/openid/server.rb', line 1196

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()
    if !@signatory
      raise ArgumentError.new(
        sprintf("Must have a store to sign this request: %s",
                response), response)
    end

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

    response = @signatory.sign(response)
  end

  return super(response)
end