Skip to content

Commit

Permalink
Add getters to the sip.Authorization type
Browse files Browse the repository at this point in the history
  • Loading branch information
ghettovoice committed Apr 27, 2021
1 parent 138e2d2 commit c965c6b
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions sip/auth.go
Expand Up @@ -36,6 +36,12 @@ func AuthFromValue(value string) *Authorization {
auth.algorithm = match[2]
case "nonce":
auth.nonce = match[2]
case "username":
auth.username = match[2]
case "uri":
auth.uri = match[2]
case "response":
auth.response = match[2]
default:
auth.other[match[1]] = match[2]
}
Expand All @@ -44,12 +50,38 @@ func AuthFromValue(value string) *Authorization {
return auth
}

func (auth *Authorization) Realm() string {
return auth.realm
}

func (auth *Authorization) Nonce() string {
return auth.nonce
}

func (auth *Authorization) Algorithm() string {
return auth.algorithm
}

func (auth *Authorization) Username() string {
return auth.username
}

func (auth *Authorization) SetUsername(username string) *Authorization {
auth.username = username

return auth
}

func (auth *Authorization) SetPassword(password string) *Authorization {
auth.password = password

return auth
}

func (auth *Authorization) Uri() string {
return auth.uri
}

func (auth *Authorization) SetUri(uri string) *Authorization {
auth.uri = uri

Expand All @@ -62,23 +94,23 @@ func (auth *Authorization) SetMethod(method string) *Authorization {
return auth
}

func (auth *Authorization) SetPassword(password string) *Authorization {
auth.password = password
func (auth *Authorization) Response() string {
return auth.response
}

return auth
func (auth *Authorization) SetResponse(response string) {
auth.response = response
}

func (auth *Authorization) CalcResponse() *Authorization {
auth.response = calcResponse(
func (auth *Authorization) CalcResponse() string {
return calcResponse(
auth.username,
auth.realm,
auth.password,
auth.method,
auth.uri,
auth.nonce,
)

return auth
}

func (auth *Authorization) String() string {
Expand Down Expand Up @@ -139,8 +171,7 @@ func AuthorizeRequest(request Request, response Response, user, password MaybeSt
if password != nil {
auth.SetPassword(password.String())
}

auth.CalcResponse()
auth.SetResponse(auth.CalcResponse())

if hdrs = request.GetHeaders(authorizeHeaderName); len(hdrs) > 0 {
authorizationHeader := hdrs[0].(*GenericHeader)
Expand Down

0 comments on commit c965c6b

Please sign in to comment.