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

1234567891011121314151617181920212223242526272829
  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. val serverSupported = serverMechanisms?.split(',') ?: return null
  13. return mechanisms
  14. .filter { it.priority < currentMechanism?.priority ?: Int.MAX_VALUE }
  15. .filter { serverMechanisms.isEmpty() || it.ircName in serverSupported }
  16. .maxBy { it.priority }
  17. }
  18. fun reset() {
  19. saslBuffer = ""
  20. currentMechanism = null
  21. }
  22. }