|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace SimpleSAML\XMLSecurity\Test\XML\dsig11; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use SimpleSAML\XML\Chunk; |
| 10 | +use SimpleSAML\XML\DOMDocumentFactory; |
| 11 | +use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; |
| 12 | +use SimpleSAML\XMLSecurity\XML\dsig11\A; |
| 13 | +use SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element; |
| 14 | +use SimpleSAML\XMLSecurity\XML\dsig11\AbstractECParametersType; |
| 15 | +use SimpleSAML\XMLSecurity\XML\dsig11\B; |
| 16 | +use SimpleSAML\XMLSecurity\XML\dsig11\Base; |
| 17 | +use SimpleSAML\XMLSecurity\XML\dsig11\CoFactor; |
| 18 | +use SimpleSAML\XMLSecurity\XML\dsig11\Curve; |
| 19 | +use SimpleSAML\XMLSecurity\XML\dsig11\ECParameters; |
| 20 | +use SimpleSAML\XMLSecurity\XML\dsig11\FieldID; |
| 21 | +use SimpleSAML\XMLSecurity\XML\dsig11\GnB; |
| 22 | +use SimpleSAML\XMLSecurity\XML\dsig11\K; |
| 23 | +use SimpleSAML\XMLSecurity\XML\dsig11\K1; |
| 24 | +use SimpleSAML\XMLSecurity\XML\dsig11\K2; |
| 25 | +use SimpleSAML\XMLSecurity\XML\dsig11\K3; |
| 26 | +use SimpleSAML\XMLSecurity\XML\dsig11\M; |
| 27 | +use SimpleSAML\XMLSecurity\XML\dsig11\Order; |
| 28 | +use SimpleSAML\XMLSecurity\XML\dsig11\P; |
| 29 | +use SimpleSAML\XMLSecurity\XML\dsig11\PnB; |
| 30 | +use SimpleSAML\XMLSecurity\XML\dsig11\Prime; |
| 31 | +use SimpleSAML\XMLSecurity\XML\dsig11\Seed; |
| 32 | +use SimpleSAML\XMLSecurity\XML\dsig11\TnB; |
| 33 | +use SimpleSAML\XMLSecurity\XML\dsig11\ValidationData; |
| 34 | + |
| 35 | +use function dirname; |
| 36 | +use function strval; |
| 37 | + |
| 38 | +/** |
| 39 | + * Class \SimpleSAML\XMLSecurity\Test\XML\dsig11\ECParametersTest |
| 40 | + * |
| 41 | + * @package simplesamlphp/xml-security |
| 42 | + */ |
| 43 | +#[CoversClass(AbstractDsig11Element::class)] |
| 44 | +#[CoversClass(AbstractECParametersType::class)] |
| 45 | +#[CoversClass(ECParameters::class)] |
| 46 | +final class ECParametersTest extends TestCase |
| 47 | +{ |
| 48 | + use SerializableElementTestTrait; |
| 49 | + |
| 50 | + |
| 51 | + /** |
| 52 | + */ |
| 53 | + public static function setUpBeforeClass(): void |
| 54 | + { |
| 55 | + self::$testedClass = ECParameters::class; |
| 56 | + |
| 57 | + self::$xmlRepresentation = DOMDocumentFactory::fromFile( |
| 58 | + dirname(__FILE__, 3) . '/resources/xml/dsig11_ECParameters.xml', |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + |
| 63 | + /** |
| 64 | + */ |
| 65 | + public function testMarshalling(): void |
| 66 | + { |
| 67 | + // Build FieldID |
| 68 | + $p = new P('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); |
| 69 | + $prime = new Prime($p); |
| 70 | + |
| 71 | + $m = new M(1024); |
| 72 | + $k = new K(64); |
| 73 | + $tnb = new TnB($m, $k); |
| 74 | + |
| 75 | + $k1 = new K1(128); |
| 76 | + $k2 = new K2(256); |
| 77 | + $k3 = new K3(512); |
| 78 | + $pnb = new PnB($m, $k1, $k2, $k3); |
| 79 | + |
| 80 | + $gnb = new GnB($m); |
| 81 | + |
| 82 | + $chunk = new Chunk(DOMDocumentFactory::fromString( |
| 83 | + '<ssp:Chunk xmlns:ssp="urn:x-simplesamlphp:namespace">some</ssp:Chunk>', |
| 84 | + )->documentElement); |
| 85 | + |
| 86 | + $fieldId = new FieldID($prime, $tnb, $pnb, $gnb, [$chunk]); |
| 87 | + |
| 88 | + // Build Curve |
| 89 | + $a = new A('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); |
| 90 | + $b = new B('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); |
| 91 | + $curve = new Curve($a, $b); |
| 92 | + |
| 93 | + // Build Base |
| 94 | + $base = new Base('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); |
| 95 | + |
| 96 | + // Build Order |
| 97 | + $order = new Order('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); |
| 98 | + |
| 99 | + // Build CoFactor |
| 100 | + $coFactor = new CoFactor('128'); |
| 101 | + |
| 102 | + // Build ValidationData |
| 103 | + $seed = new Seed('6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE='); |
| 104 | + $validationData = new ValidationData($seed, C::DIGEST_SHA1); |
| 105 | + |
| 106 | + // Build ECParameters |
| 107 | + $ecParameters = new ECParameters($fieldId, $curve, $base, $order, $coFactor, $validationData); |
| 108 | + |
| 109 | + $this->assertEquals( |
| 110 | + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), |
| 111 | + strval($ecParameters), |
| 112 | + ); |
| 113 | + } |
| 114 | +} |
0 commit comments