String authorization()

in lib/src/http_impl.dart [2926:2979]


  String authorization(_Credentials credentials, _HttpClientRequest request) {
    String requestUri = request._requestUri();
    var hasher = MD5()
      ..add(request.method.codeUnits)
      ..add([CharCode.COLON])
      ..add(requestUri.codeUnits);
    var ha2 = CryptoUtils.bytesToHex(hasher.close());

    String qop;
    String cnonce;
    String nc;
    hasher = MD5()
      ..add(credentials.ha1.codeUnits)
      ..add([CharCode.COLON]);
    if (credentials.qop == "auth") {
      qop = credentials.qop;
      cnonce = CryptoUtils.bytesToHex(CryptoUtils.getRandomBytes(4));
      ++credentials.nonceCount;
      nc = credentials.nonceCount.toRadixString(16);
      nc = "00000000".substring(0, 8 - nc.length + 1) + nc;
      hasher
        ..add(credentials.nonce.codeUnits)
        ..add([CharCode.COLON])
        ..add(nc.codeUnits)
        ..add([CharCode.COLON])
        ..add(cnonce.codeUnits)
        ..add([CharCode.COLON])
        ..add(credentials.qop.codeUnits)
        ..add([CharCode.COLON])
        ..add(ha2.codeUnits);
    } else {
      hasher
        ..add(credentials.nonce.codeUnits)
        ..add([CharCode.COLON])
        ..add(ha2.codeUnits);
    }
    var response = CryptoUtils.bytesToHex(hasher.close());

    StringBuffer buffer = StringBuffer()
      ..write('Digest ')
      ..write('username="$username"')
      ..write(', realm="${credentials.realm}"')
      ..write(', nonce="${credentials.nonce}"')
      ..write(', uri="$requestUri"')
      ..write(', algorithm="${credentials.algorithm}"');
    if (qop == "auth") {
      buffer
        ..write(', qop="$qop"')
        ..write(', cnonce="$cnonce"')
        ..write(', nc="$nc"');
    }
    buffer.write(', response="$response"');
    return buffer.toString();
  }