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

123456789101112131415161718192021222324252627282930313233
  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: Collection<String>): SaslMechanism? {
  15. return mechanisms
  16. .filter { it.priority < currentMechanism?.priority ?: Int.MAX_VALUE }
  17. .filter { serverMechanisms.isEmpty() || it.ircName in serverMechanisms }
  18. .maxBy { it.priority }
  19. }
  20. fun reset() {
  21. saslBuffer = ""
  22. currentMechanism = null
  23. }
  24. }