///|
/// Cryptographically secure SCRAM-SHA-256 client nonce generation on Native target (OS CSPRNG).

///|
extern "c" fn c_pg_random_bytes(len : Int32) -> Bytes = "ciallo_pg_random_bytes"

///|
fn generate_scram_nonce() -> String raise @codec.DataError {
  let raw = c_pg_random_bytes(18)
  if raw.length() != 18 {
    raise @codec.DataError::AuthFailed(
      "OS CSPRNG failed to generate SCRAM-SHA-256 client nonce",
    )
  }
  @base64.encode(raw[:])
}