func (auth *Authorization) CalcResponse(request sip.Request) *Authorization {
	auth.nc += 1
	hex := fmt.Sprintf("%x", auth.nc)
	ncHex := "00000000"
	auth.ncHex = ncHex[:len(ncHex)-1-len(hex)] + hex
	if auth.nc == 4294967296 {
		auth.nc = 1
		auth.ncHex = "00000001"
	}
	ha1 := md5Hex(auth.username + ":" + auth.realm + ":" + auth.password)
	if auth.qop == "auth" {
		ha2 := md5Hex(auth.method + ":" + auth.uri)
		auth.response = md5Hex(ha1 + ":" + auth.nonce + ":" + auth.ncHex + ":" + auth.cnonce + ":auth:" + ha2)
	} else if auth.qop == "auth-int" {
		ha2 := md5Hex(auth.method + ":" + auth.uri + ":" + md5Hex(request.Body()))
		auth.response = md5Hex(ha1 + ":" + auth.nonce + ":" + auth.ncHex + ":" + auth.cnonce + ":auth-int:" + ha2)
	} else {
		ha2 := md5Hex(auth.method + ":" + auth.uri)
		auth.response = md5Hex(ha1 + ":" + auth.nonce + ":" + ha2)
	}
	return auth
}
calculates Authorization response https://www.ietf.org/rfc/rfc2617.txt
package auth
import (
	"fmt"
	"regexp"
	"strings"
	"github.com/ghettovoice/gosip/sip"
)
type Authorization struct {
	realm     string
	qop       string
	nonce     string
	cnonce    string
	opaque    string
	algorithm string
	username  string
	password  string
	uri       string
	response  string
	method    string
	stale     string
	nc        int
	ncHex     string
	domain    string
	other     map[string]string
}
func AuthFromValue(value string) *Authorization {
	auth := &Authorization{
		algorithm: "MD5",
		cnonce:    generateNonce(12),
		opaque:    "",
		stale:     "",
		qop:       "",
		nc:        0,
		ncHex:     "00000000",
		domain:    "",
		other:     make(map[string]string),
	}
	re := regexp.MustCompile(`([\w]+)=("([^"]+)"|([\w]+))`)
	matches := re.FindAllStringSubmatch(value, -1)
	for _, match := range matches {
		value2 := strings.Replace(match[2], "\"", "", -1)
		switch match[1] {
		case "qop":
			auth.qop = value2
		case "realm":
			auth.realm = value2
		case "algorithm":
			auth.algorithm = value2
		case "opaque":
			auth.opaque = value2
		case "nonce":
			auth.nonce = value2
		case "stale":
			auth.stale = value2
		case "domain":
			auth.domain = value2
		default:
			auth.other[match[1]] = value2
		}
	}
	return auth
}
func (auth *Authorization) SetUsername(username string) *Authorization {
	auth.username = username
	return auth
}
func (auth *Authorization) SetUri(uri string) *Authorization {
	auth.uri = uri
	return auth
}
func (auth *Authorization) SetMethod(method string) *Authorization {
	auth.method = method
	return auth
}
func (auth *Authorization) SetPassword(password string) *Authorization {
	auth.password = password
	return auth
}