def self.from_message(message)
dh_modulus = message.get_arg(OPENID_NS, 'dh_modulus')
dh_gen = message.get_arg(OPENID_NS, 'dh_gen')
if ((!dh_modulus and dh_gen) or
(!dh_gen and dh_modulus))
if !dh_modulus
missing = 'modulus'
else
missing = 'generator'
end
raise ProtocolError.new(message,
sprintf('If non-default modulus or generator is ' +
'supplied, both must be supplied. Missing %s',
missing))
end
if dh_modulus or dh_gen
dh_modulus = CryptUtil.base64_to_num(dh_modulus)
dh_gen = CryptUtil.base64_to_num(dh_gen)
dh = DiffieHellman.new(dh_modulus, dh_gen)
else
dh = DiffieHellman.from_defaults()
end
consumer_pubkey = message.get_arg(OPENID_NS, 'dh_consumer_public')
if !consumer_pubkey
raise ProtocolError.new(message,
sprintf("Public key for DH-SHA1 session " +
"not found in message %s", message))
end
consumer_pubkey = CryptUtil.base64_to_num(consumer_pubkey)
return self.new(dh, consumer_pubkey)
end