import type Connection from './connection';
import SASLMechanism from './sasl';
import scram from './scram';

class SASLSHA1 extends SASLMechanism {
    constructor(mechname = 'SCRAM-SHA-1', isClientFirst = true, priority = 60) {
        super(mechname, isClientFirst, priority);
    }

    test(connection: Connection): boolean {
        return connection.authcid !== null && scram.supported();
    }

    async onChallenge(connection: Connection, challenge?: string): Promise<string | false> {
        return await scram.scramResponse(connection, challenge, 'SHA-1', 160);
    }

    clientChallenge(connection: Connection, test_cnonce?: string): string {
        return scram.clientChallenge(connection, test_cnonce);
    }
}

export default SASLSHA1;
