Skip to content

Commit 0a6ee6c

Browse files
authored
Merge pull request #14 from rtckit/v0.5.0
v0.5.0
2 parents 24affc9 + 7464e6e commit 0a6ee6c

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rtckit/sip",
33
"description": "Parser/Renderer for SIP protocol written in PHP",
4-
"version": "0.4.0",
4+
"version": "0.5.0",
55
"type": "library",
66
"keywords": [
77
"sip",

src/Header/AuthHeader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ public static function parse(array $hbody): AuthHeader
159159
break;
160160

161161
case 'nc':
162-
if (!ctype_digit($pv)) {
163-
throw new InvalidHeaderParameter('Invalid Auth header, non-integer nc parameter', Response::BAD_REQUEST);
162+
if (!ctype_xdigit($pv)) {
163+
throw new InvalidHeaderParameter('Invalid Auth header, non-hexadecimal nc parameter', Response::BAD_REQUEST);
164164
}
165165

166-
$val->nc = (int)$pv;
166+
$val->nc = $pv;
167167
break;
168168

169169
case 'opaque':
@@ -245,7 +245,7 @@ public function render(string $hname): string
245245
}
246246

247247
if (isset($value->nc)) {
248-
$params[] = sprintf('ns=%08d', $value->nc);
248+
$params[] = sprintf('nc=%08s', $value->nc);
249249
}
250250

251251
if (isset($value->opaque)) {

src/Header/AuthValue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class AuthValue
4444
/** @var string Quality of protection */
4545
public string $qop;
4646

47-
/** @var int Number once count */
48-
public int $nc;
47+
/** @var string Number once count */
48+
public string $nc;
4949

5050
/** @var string Server's opaque data blob */
5151
public string $opaque;

tests/Header/AuthHeaderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function testShouldParseEnclosedCharacters()
100100

101101
public function testShouldParseVariousNcValueFormatting()
102102
{
103-
$nc = 42;
103+
$nc = hexdec('00000042');
104104

105105
$auth = AuthHeader::parse([
106106
'Digest realm="sip.domain.net",qop="auth",nonce="7900f98e-3d80-4504-adbc-a61e5e040207",stale=FALSE,algorithm=MD5,nc=42',
@@ -114,7 +114,7 @@ public function testShouldParseVariousNcValueFormatting()
114114
$count = count($auth->values);
115115

116116
for ($i = 0; $i < $count; $i++) {
117-
$this->assertEquals($nc, $auth->values[$i]->nc);
117+
$this->assertEquals($nc, hexdec($auth->values[$i]->nc));
118118
}
119119
}
120120

@@ -170,15 +170,15 @@ public function testShouldRenderWellFormedValues()
170170
$digest->values[0]->algorithm = 'MD5';
171171
$digest->values[0]->cnonce = '7900f98e';
172172
$digest->values[0]->qop = 'auth-int';
173-
$digest->values[0]->nc = 42;
173+
$digest->values[0]->nc = '42';
174174
$digest->values[0]->opaque = 'misc';
175175

176176
$rendered = $digest->render('Authorization');
177177

178178
$this->assertNotNull($rendered);
179179
$this->assertIsString($rendered);
180180
$this->assertEquals(
181-
'Authorization: Digest username="bob",realm="sip.domain.net",domain="sip:sip.domain.net",nonce="a61e5e040207",uri="sip:sip.domain.net",response="KJHAFgHFIUAG",stale=TRUE,algorithm="MD5",cnonce="7900f98e",qop="auth-int",ns=00000042,opaque="misc"' . "\r\n",
181+
'Authorization: Digest username="bob",realm="sip.domain.net",domain="sip:sip.domain.net",nonce="a61e5e040207",uri="sip:sip.domain.net",response="KJHAFgHFIUAG",stale=TRUE,algorithm="MD5",cnonce="7900f98e",qop="auth-int",nc=00000042,opaque="misc"' . "\r\n",
182182
$rendered
183183
);
184184

@@ -204,7 +204,7 @@ public function testShouldRenderWellFormedValues()
204204
$this->assertNotNull($rendered);
205205
$this->assertIsString($rendered);
206206
$this->assertEquals(
207-
'Authorization: Digest username="bob",realm="sip.domain.net",domain="sip:sip.domain.net",nonce="a61e5e040207",uri="sip:sip.domain.net",response="KJHAFgHFIUAG",stale=TRUE,algorithm="MD5",cnonce="7900f98e",qop="auth-int",ns=00000042,opaque="misc"' . "\r\n" .
207+
'Authorization: Digest username="bob",realm="sip.domain.net",domain="sip:sip.domain.net",nonce="a61e5e040207",uri="sip:sip.domain.net",response="KJHAFgHFIUAG",stale=TRUE,algorithm="MD5",cnonce="7900f98e",qop="auth-int",nc=00000042,opaque="misc"' . "\r\n" .
208208
'Authorization: Basic MiScCreds' . "\r\n",
209209
$rendered
210210
);

0 commit comments

Comments
 (0)