Skip to content

Commit

Permalink
Add ds:PGPKeyPacket element
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Nov 30, 2024
1 parent de26a79 commit 6f5c6f9
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/PGPKeyPacket.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\Base64ElementTrait;

/**
* Class representing a ds:PGPKeyPacket element.
*
* @package simplesaml/xml-security
*/
final class PGPKeyPacket extends AbstractDsElement
{
use Base64ElementTrait;


/**
* @param string $content
*/
public function __construct(string $content)
{
$this->setContent($content);
}
}
51 changes: 51 additions & 0 deletions tests/XML/ds/PGPKeyPacketTest.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\PGPKeyPacket;

use function dirname;
use function strval;

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

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

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


/**
*/
public function testMarshalling(): void
{
$pgpKeyPacket = new PGPKeyPacket('GpM7');

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

0 comments on commit 6f5c6f9

Please sign in to comment.