def respond.of

bend-kit-postgres@0.3.0.0 · scram.bend:199

import bend-kit-postgres@0.3.0.0/scram.bend as Scram
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes

199# c=biws is base64 of the gs2 header "n,,". AuthMessage joins the three bare messages.
200def respond.of(r: Result<&1, &1, U32 & String, Parsed>, +bare: String, +sf: String, +pass: String) -> IO(Result<&1, &1, U32 & String, Final & String>):
201  match r:
202    case Fail{e}:
203      IO.pure(Result<&1, &1, U32 & String, Final & String>, Fail{e})
204    case Done{Parsed{+nonce, +salt, +iters}}:
205      +fb = "c=biws,r=" ++ nonce
206      +auth = bare ++ "," ++ sf ++ "," ++ fb
207      step(pbkdf2(pass, salt, iters), +salted =>
208        step(hmac(salted, "Client Key"), +ck =>
209          step(sha(ck), +sk =>
210            step(hmac(sk, auth), +cs =>
211              step(hmac(salted, "Server Key"), +svk =>
212                step(hmac(svk, auth), +ss =>
213                  IO.pure(Result<&1, &1, U32 & String, Final & String>, Done{(Final{ss}, fb ++ ",p=" ++ Bytes.to_base64(Bytes.from_string(xor(ck, cs))))})))))))

Uses (17)

Used by (1)