Skip to content

Commit d5c568e

Browse files
committed
Add HMACOutputLength element
1 parent a6cd186 commit d5c568e

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/XML/ds/HMACOutputLength.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\XML\ds;
6+
7+
use SimpleSAML\XML\IntegerElementTrait;
8+
9+
/**
10+
* Class representing a ds:HMACOutputLength element.
11+
*
12+
* @package simplesamlphp/xml-security
13+
*/
14+
final class HMACOutputLength extends AbstractDsElement
15+
{
16+
use IntegerElementTrait;
17+
18+
19+
/**
20+
* @param string $length
21+
*/
22+
public function __construct(string $length)
23+
{
24+
$this->setContent($length);
25+
}
26+
}

tests/XML/ds/HMACOutputLengthTest.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\Test\XML\ds;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\TestCase;
9+
use SimpleSAML\XML\DOMDocumentFactory;
10+
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
11+
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
12+
use SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength;
13+
14+
use function dirname;
15+
use function strval;
16+
17+
/**
18+
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\HMACOutputLengthTest
19+
*
20+
* @package simplesamlphp/xml-security
21+
*/
22+
#[CoversClass(AbstractDsElement::class)]
23+
#[CoversClass(HMACOutputLength::class)]
24+
final class HMACOutputLengthTest extends TestCase
25+
{
26+
use SerializableElementTestTrait;
27+
28+
/**
29+
*/
30+
public static function setUpBeforeClass(): void
31+
{
32+
self::$testedClass = HMACOutputLength::class;
33+
34+
self::$xmlRepresentation = DOMDocumentFactory::fromFile(
35+
dirname(__FILE__, 3) . '/resources/xml/ds_HMACOutputLength.xml',
36+
);
37+
}
38+
39+
40+
/**
41+
*/
42+
public function testMarshalling(): void
43+
{
44+
$hmacOutputLength = new HMACOutputLength('1234');
45+
46+
$this->assertEquals(
47+
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
48+
strval($hmacOutputLength),
49+
);
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ds:HMACOutputLength xmlns:ds="http://www.w3.org/2000/09/xmldsig#">1234</ds:HMACOutputLength>

0 commit comments

Comments
 (0)