1 ///SASL support module 2 module virc.ircv3.sasl; 3 4 /++ 5 + Interface for SASL authentication mechanisms. 6 +/ 7 interface SASLMechanism { 8 /// 9 string name() @safe pure @nogc nothrow; 10 /// 11 bool empty() @safe nothrow; 12 /// 13 string front() @safe nothrow; 14 /// 15 void popFront() @safe nothrow; 16 /// 17 void put(string) @safe nothrow; 18 } 19 20 /++ 21 + EXTERNAL SASL mechanism support. For authentication based on other network 22 + layers, such as TLS or IPSec. 23 +/ 24 class SASLExternal : SASLMechanism { 25 private bool popped; 26 override string name() @safe pure @nogc nothrow { return "EXTERNAL"; } 27 override bool empty() @safe pure @nogc nothrow { return popped; } 28 override string front() @safe pure @nogc nothrow { assert(!popped); return ""; } 29 override void popFront() @safe pure @nogc nothrow { assert(!popped); popped = true; } 30 override void put(string) @safe pure @nogc nothrow {} 31 } 32 /++ 33 + PLAIN SASL mechanism support. For authentication with plaintext username(s) 34 + and password combination. 35 +/ 36 class SASLPlain : SASLMechanism { 37 private bool popped; 38 override string name() @safe pure @nogc nothrow { return "PLAIN"; } 39 override bool empty() @safe pure @nogc nothrow { return popped; } 40 override string front() @safe pure @nogc nothrow { assert(!popped); return authStr; } 41 override void popFront() @safe pure @nogc nothrow { popped = true; } 42 override void put(string) @safe pure @nogc nothrow {} 43 private string authStr; 44 /++ 45 + 46 +/ 47 this(const string authorizationIdentity, const string authenticationIdentity, const string password) @safe in { 48 import std.algorithm : filter; 49 import std.array : empty; 50 assert(authenticationIdentity != ""); 51 assert(authenticationIdentity.filter!(x => x == '\0').empty); 52 assert(authorizationIdentity != ""); 53 assert(authorizationIdentity.filter!(x => x == '\0').empty); 54 assert(password.filter!(x => x == '\0').empty); 55 } do { 56 authStr = authorizationIdentity~"\0"~authenticationIdentity~"\0"~password; 57 } 58 }