You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SaslState.kt 814B

12345678910111213141516171819202122232425
  1. package com.dmdirc.ktirc.model
  2. import com.dmdirc.ktirc.sasl.SaslMechanism
  3. internal class SaslState(private val mechanisms: Collection<SaslMechanism>) {
  4. var saslBuffer: String = ""
  5. var currentMechanism: SaslMechanism? = null
  6. set(value) {
  7. mechanismState = null
  8. field = value
  9. }
  10. var mechanismState: Any? = null
  11. fun getPreferredSaslMechanism(serverMechanisms: String?): SaslMechanism? {
  12. serverMechanisms ?: return null
  13. val serverSupported = serverMechanisms.split(',')
  14. return mechanisms
  15. .filter { it.priority < currentMechanism?.priority ?: Int.MAX_VALUE }
  16. .filter { serverMechanisms.isEmpty() || it.ircName in serverSupported }
  17. .maxBy { it.priority }
  18. }
  19. }