Skip to content

Commit

Permalink
Add HMACOutputLength element
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Nov 29, 2024
1 parent 5855e0e commit 310db4e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/XML/ds/HMACOutputLength.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\XML\ds;

use SimpleSAML\XML\IntegerElementTrait;

/**
* Class representing a ds:HMACOutputLength element.
*
* @package simplesamlphp/xml-security
*/
final class HMACOutputLength extends AbstractDsElement
{
use IntegerElementTrait;


/**
* @param string $length
*/
public function __construct(string $length)
{
$this->setContent($length);
}
}
51 changes: 51 additions & 0 deletions tests/XML/ds/HMACOutputLengthTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\Test\XML\ds;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement;
use SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength;

use function dirname;
use function strval;

/**
* Class \SimpleSAML\XMLSecurity\Test\XML\ds\HMACOutputLengthTest
*
* @package simplesamlphp/xml-security
*/
#[CoversClass(AbstractDsElement::class)]
#[CoversClass(HMACOutputLength::class)]
final class HMACOutputLengthTest extends TestCase
{
use SerializableElementTestTrait;

/**
*/
public static function setUpBeforeClass(): void
{
self::$testedClass = HMACOutputLength::class;

self::$xmlRepresentation = DOMDocumentFactory::fromFile(
dirname(__FILE__, 3) . '/resources/xml/ds_HMACOutputLength.xml',
);
}


/**
*/
public function testMarshalling(): void
{
$hmacOutputLength = new HMACOutputLength('1234');

$this->assertEquals(
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),
strval($hmacOutputLength),
);
}
}
1 change: 1 addition & 0 deletions tests/resources/xml/ds_HMACOutputLength.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<ds:HMACOutputLength xmlns:ds="http://www.w3.org/2000/09/xmldsig#">1234</ds:HMACOutputLength>

0 comments on commit 310db4e

Please sign in to comment.