computeResponse function
Map<String, String?>
computeResponse(
- String method,
- String path,
- String body,
- String? algorithm,
- String? qop,
- String? opaque,
- String realm,
- String? cnonce,
- String? nonce,
- int nc,
- String username,
- String password,
)
Implementation
Map<String, String?> computeResponse(
String method,
String path,
String body,
String? algorithm,
String? qop,
String? opaque,
String realm,
String? cnonce,
String? nonce,
int nc,
String username,
String password,
) {
var ret = <String, String?>{};
algorithm ??= 'MD5';
final ha1 = _computeHA1(realm, algorithm, username, password, nonce, cnonce);
String ha2;
if (algorithm.startsWith('MD5')) {
if (qop == 'auth-int') {
final bodyHash = md5Hash(body);
final token2 = '$method:$path:$bodyHash';
ha2 = md5Hash(token2);
} else {
// qop in [null, auth]
final token2 = '$method:$path';
ha2 = md5Hash(token2);
}
} else {
if (qop == 'auth-int') {
final bodyHash = sha256Hash(body);
final token2 = '$method:$path:$bodyHash';
ha2 = sha256Hash(token2);
} else {
// qop in [null, auth]
final token2 = '$method:$path';
ha2 = sha256Hash(token2);
}
}
final nonceCount = _formatNonceCount(nc);
ret['username'] = username;
ret['realm'] = realm;
ret['nonce'] = nonce;
ret['uri'] = path;
if (qop != null) {
ret['qop'] = qop;
}
ret['nc'] = nonceCount;
ret['cnonce'] = cnonce;
if (opaque != null) {
ret['opaque'] = opaque;
}
ret['algorithm'] = algorithm;
if (algorithm.startsWith('MD5')) {
if (qop == null) {
final token3 = '$ha1:$nonce:$ha2';
ret['response'] = md5Hash(token3);
} else if (kQop.contains(qop)) {
final token3 = '$ha1:$nonce:$nonceCount:$cnonce:$qop:$ha2';
ret['response'] = md5Hash(token3);
}
} else {
if (qop == null) {
final token3 = '$ha1:$nonce:$ha2';
ret['response'] = sha256Hash(token3);
} else if (kQop.contains(qop)) {
final token3 = '$ha1:$nonce:$nonceCount:$cnonce:$qop:$ha2';
ret['response'] = sha256Hash(token3);
}
}
return ret;
}