def sign(response)
signed_response = response.copy
assoc_handle = response.request.assoc_handle
if assoc_handle
assoc = get_association(assoc_handle, false, false)
if !assoc or assoc.expires_in <= 0
signed_response.fields.set_arg(
OPENID_NS, 'invalidate_handle', assoc_handle)
assoc_type = assoc ? assoc.assoc_type : 'HMAC-SHA1'
if assoc and assoc.expires_in <= 0
invalidate(assoc_handle, false)
end
assoc = create_association(true, assoc_type)
end
else
assoc = create_association(true)
end
begin
signed_response.fields = assoc.sign_message(signed_response.fields)
rescue KVFormError => err
raise EncodingError, err
end
return signed_response
end