Skip to content

Commit 73c7c6e

Browse files
committed
Refactor X509SerialNumber
1 parent 0156f2b commit 73c7c6e

File tree

5 files changed

+8
-54
lines changed

5 files changed

+8
-54
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"ext-spl": "*",
4545

4646
"simplesamlphp/assert": "^1.3",
47-
"simplesamlphp/xml-common": "^1.18.5"
47+
"simplesamlphp/xml-common": "^1.19.0"
4848
},
4949
"require-dev": {
5050
"simplesamlphp/simplesamlphp-test-framework": "^1.7"

src/XML/ds/X509SerialNumber.php

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use SimpleSAML\Assert\Assert;
99
use SimpleSAML\XML\Exception\InvalidDOMElementException;
1010
use SimpleSAML\XML\Exception\SchemaViolationException;
11-
use SimpleSAML\XML\StringElementTrait;
11+
use SimpleSAML\XML\IntegerElementTrait;
1212

1313
/**
1414
* Class representing a ds:X509SerialNumber element.
@@ -17,60 +17,14 @@
1717
*/
1818
final class X509SerialNumber extends AbstractDsElement
1919
{
20-
use StringElementTrait;
20+
use IntegerElementTrait;
2121

2222

2323
/**
24-
* @param string $content
24+
* @param int $content
2525
*/
26-
public function __construct(string $content)
26+
public function __construct(int $content)
2727
{
2828
$this->setContent($content);
2929
}
30-
31-
32-
/**
33-
* Validate the content of the element.
34-
*
35-
* @param string $content The value to go in the XML textContent
36-
* @throws \Exception on failure
37-
* @return void
38-
*/
39-
protected function validateContent(/** @scrutinizer ignore-unused */ string $content): void
40-
{
41-
Assert::numeric($content, SchemaViolationException::class);
42-
}
43-
44-
45-
/**
46-
* Convert XML into a X509SerialNumber
47-
*
48-
* @param \DOMElement $xml The XML element we should load
49-
* @return static
50-
*
51-
* @throws \SimpleSAML\XML\Exception\InvalidDOMElementException
52-
* If the qualified name of the supplied element is wrong
53-
*/
54-
public static function fromXML(DOMElement $xml): static
55-
{
56-
Assert::same($xml->localName, 'X509SerialNumber', InvalidDOMElementException::class);
57-
Assert::same($xml->namespaceURI, X509SerialNumber::NS, InvalidDOMElementException::class);
58-
59-
return new static($xml->textContent);
60-
}
61-
62-
63-
/**
64-
* Convert this X509SerialNumber element to XML.
65-
*
66-
* @param \DOMElement|null $parent The element we should append this X509SerialNumber element to.
67-
* @return \DOMElement
68-
*/
69-
public function toXML(DOMElement $parent = null): DOMElement
70-
{
71-
$e = $this->instantiateParentElement($parent);
72-
$e->textContent = $this->getContent();
73-
74-
return $e;
75-
}
7630
}

tests/XML/ds/X509DataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function testMarshalling(): void
111111
'C=US,ST=Hawaii,L=Honolulu,O=SimpleSAMLphp HQ,CN=SimpleSAMLphp Testing CA,emailAddress=%s',
112112
113113
)),
114-
new X509SerialNumber('2'),
114+
new X509SerialNumber(2),
115115
),
116116
new X509SubjectName(self::$certData['name']),
117117
new X509Digest(self::$digest, C::DIGEST_SHA256),

tests/XML/ds/X509IssuerSerialTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function setUp(): void
5757
/** @var string[] $details */
5858
$details = self::$key->getCertificateDetails();
5959
self::$issuer = new X509IssuerName(CertificateUtils::parseIssuer($details['issuer']));
60-
self::$serial = new X509SerialNumber($details['serialNumber']);
60+
self::$serial = new X509SerialNumber(intval($details['serialNumber']));
6161
}
6262

6363

tests/XML/ds/X509SerialNumberTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function setUpBeforeClass(): void
4343
*/
4444
public function testMarshalling(): void
4545
{
46-
$serialNumber = new X509SerialNumber('123456');
46+
$serialNumber = new X509SerialNumber(123456);
4747

4848
$this->assertEquals(
4949
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement),

0 commit comments

Comments
 (0)