Skip to content

Commit

Permalink
Add element xenc:P
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Nov 27, 2024
1 parent 79d3329 commit 3392644
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
36 changes: 36 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pick 7612dde Refactor ds:KeyInfo
pick 396cecd Add element xenc:OriginatorKeyInfo
pick 26d0811 Add element xenc:RecipientKeyInfo
pick 3fbdc66 Add element xenc:AgreementMethod
s 25beba4 Add element xenc:AgreementMethod

# Rebase 271d943..25beba4 onto 271d943 (5 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
# commit's log message, unless -C is used, in which case
# keep only this commit's message; -c is same as -C but
# opens the editor
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# create a merge commit using the original merge commit's
# message (or the oneline, if no original merge commit was
# specified); use -c <commit> to reword the commit message
# u, update-ref <ref> = track a placeholder for the <ref> to be updated
# to this position in the new commits. The <ref> is
# updated at the end of the rebase
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
26 changes: 26 additions & 0 deletions src/XML/xenc/P.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\XML\xenc;

use SimpleSAML\XML\Base64ElementTrait;

/**
* Class representing a xenc:P element.
*
* @package simplesaml/xml-security
*/
final class P extends AbstractXencElement
{
use Base64ElementTrait;


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

declare(strict_types=1);

namespace SimpleSAML\XMLSecurity\Test\XML\xenc;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait;
use SimpleSAML\XMLSecurity\Test\XML\XMLDumper;
use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement;
use SimpleSAML\XMLSecurity\XML\xenc\P;

use function dirname;
use function strval;

/**
* Class \SimpleSAML\XMLSecurity\Test\XML\xenc\PTest
*
* @covers \SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement
* @covers \SimpleSAML\XMLSecurity\XML\xenc\P
*
* @package simplesamlphp/xml-security
*/
#[CoversClass(AbstractXencElement::class)]
#[CoversClass(P::class)]
final class PTest extends TestCase
{
use SerializableElementTestTrait;

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

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


/**
*/
public function testMarshalling(): void
{
$p = new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');

$this->assertEquals(
XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation),
strval($p),
);
}


/**
*/
public function testMarshallingNotBase64(): void
{
$this->expectException(AssertionFailedException::class);
new P('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
}
}
1 change: 1 addition & 0 deletions tests/resources/xml/xenc_P.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<xenc:P xmlns:xenc="http://www.w3.org/2001/04/xmlenc#">/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=</xenc:P>

0 comments on commit 3392644

Please sign in to comment.