Class: OpenID::AssociationNegotiator

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allowed_types) ⇒ AssociationNegotiator

Returns a new instance of AssociationNegotiator.



204
205
206
# File 'lib/openid/association.rb', line 204

def initialize(allowed_types)
  self.allowed_types=(allowed_types)
end

Instance Attribute Details

#allowed_typesObject

Returns the value of attribute allowed_types.



184
185
186
# File 'lib/openid/association.rb', line 184

def allowed_types
  @allowed_types
end

Class Method Details

.check_session_type(assoc_type, session_type) ⇒ Object



197
198
199
200
201
202
# File 'lib/openid/association.rb', line 197

def self.check_session_type(assoc_type, session_type)
  if !get_session_types(assoc_type).include?(session_type)
    raise ProtocolError, "Session type #{session_type.inspect} not "\
                         "valid for association type #{assoc_type.inspect}"
  end
end

.get_session_types(assoc_type) ⇒ Object



186
187
188
189
190
191
192
193
194
195
# File 'lib/openid/association.rb', line 186

def self.get_session_types(assoc_type)
  case assoc_type
  when 'HMAC-SHA1'
    ['DH-SHA1', 'no-encryption']
  when 'HMAC-SHA256'
    ['DH-SHA256', 'no-encryption']
  else
    raise ProtocolError, "Unknown association type #{assoc_type.inspect}"
  end
end

Instance Method Details

#add_allowed_type(assoc_type, session_type = nil) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
# File 'lib/openid/association.rb', line 219

def add_allowed_type(assoc_type, session_type=nil)
  if session_type.nil?
    session_types = self.class.get_session_types(assoc_type)
  else
    self.class.check_session_type(assoc_type, session_type)
    session_types = [session_type]
  end
  for session_type in session_types do
    @allowed_types << [assoc_type, session_type]
  end
end

#allowed?(assoc_type, session_type) ⇒ Boolean

Returns:

  • (Boolean)


231
232
233
# File 'lib/openid/association.rb', line 231

def allowed?(assoc_type, session_type)
  @allowed_types.include?([assoc_type, session_type])
end

#copyObject



208
209
210
# File 'lib/openid/association.rb', line 208

def copy
  Marshal.load(Marshal.dump(self))
end

#get_allowed_typeObject



235
236
237
# File 'lib/openid/association.rb', line 235

def get_allowed_type
  @allowed_types.empty? ? nil : @allowed_types[0]
end