public static SIPAuthorisationDigest ParseAuthorisationDigest(SIPAuthorisationHeadersEnum authorisationType, string authorisationRequest)
{
SIPAuthorisationDigest authRequest = new SIPAuthorisationDigest(authorisationType);
string noDigestHeader = Regex.Replace(authorisationRequest, @"^\s*Digest\s*", "", RegexOptions.IgnoreCase);
string[] headerFields = noDigestHeader.Split(',');
if (headerFields != null && headerFields.Length > 0)
{
foreach (string headerField in headerFields)
{
int equalsIndex = headerField.IndexOf('=');
if (equalsIndex != -1 && equalsIndex < headerField.Length)
{
string headerName = headerField.Substring(0, equalsIndex).Trim();
string headerValue = headerField.Substring(equalsIndex + 1).Trim(m_headerFieldRemoveChars);
if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_REALM_KEY + "$", RegexOptions.IgnoreCase).Success)
{
authRequest.Realm = headerValue;
}
else if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_NONCE_KEY + "$", RegexOptions.IgnoreCase).Success)
{
authRequest.Nonce = headerValue;
}
else if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_USERNAME_KEY + "$", RegexOptions.IgnoreCase).Success)
{
authRequest.Username = headerValue;
}
else if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_RESPONSE_KEY + "$", RegexOptions.IgnoreCase).Success)
{
authRequest.Response = headerValue;
}
else if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_URI_KEY + "$", RegexOptions.IgnoreCase).Success)
{
authRequest.URI = headerValue;
}
else if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_CNONCE_KEY + "$", RegexOptions.IgnoreCase).Success)
{
authRequest.Cnonce = headerValue;
}
else if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_NONCECOUNT_KEY + "$", RegexOptions.IgnoreCase).Success)
{
Int32.TryParse(headerValue, out authRequest.NonceCount);
}
else if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_QOP_KEY + "$", RegexOptions.IgnoreCase).Success)
{
authRequest.Qop = headerValue.ToLower();
}
else if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_OPAQUE_KEY + "$", RegexOptions.IgnoreCase).Success)
{
authRequest.Opaque = headerValue;
}
else if (Regex.Match(headerName, "^" + AuthHeaders.AUTH_ALGORITHM_KEY + "$", RegexOptions.IgnoreCase).Success)
{
authRequest.Algorithhm = headerValue;
}
}
}
}
return authRequest;
}