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 1020B

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