Skip to content

Commit

Permalink
Fix bug with leading fractional zeroes
Browse files Browse the repository at this point in the history
  • Loading branch information
sop committed May 20, 2019
1 parent cc0d0f4 commit bf86e8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ASN1/Type/Primitive/GeneralizedTime.php
Expand Up @@ -109,9 +109,9 @@ protected static function _decodeFromDER(Identifier $identifier,
throw new DecodeException(
"Fractional seconds must omit trailing zeroes.");
}
$frac = (int) $frac;
$frac = $frac;
} else {
$frac = 0;
$frac = '0';
}
$time = $year . $month . $day . $hour . $minute . $second . "." . $frac .
self::TZ_UTC;
Expand Down
15 changes: 15 additions & 0 deletions test/tests/type/primitive/generalized-time/GeneralizedTimeTest.php
Expand Up @@ -102,4 +102,19 @@ public function testClone(Element $el)
$clone = clone $el;
$this->assertInstanceOf(GeneralizedTime::class, $clone);
}

/**
* Test bug where leading zeroes in fraction gets stripped,
* such that `.05` becomes `.5`.
*/
public function testLeadingFractionZeroes()
{
$ts = strtotime('Mon Jan 2 15:04:05 MST 2006');
$dt = \DateTimeImmutable::createFromFormat('U.u', "{$ts}.05",
new \DateTimeZone('UTC'));
$el = new GeneralizedTime($dt);
$der = $el->toDER();
$el = GeneralizedTime::fromDER($der);
$this->assertEquals($der, $el->toDER());
}
}

0 comments on commit bf86e8e

Please sign in to comment.