svn: /pear2/Pyrus/trunk/src/Pyrus/DER/ ObjectIdentifier.php
| From: | Helgi Þormar Þorbjörnsson | Date: | Sun, 28 Feb 2010 02:53:29 +0000 |
| Subject: | svn: /pear2/Pyrus/trunk/src/Pyrus/DER/ ObjectIdentifier.php | ||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-9216@lists.php.net to get a copy of this message | ||
dufuz Sun, 28 Feb 2010 02:53:29 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=295571
Log:
Make sure we don't let serialize continue processing if the value is not formatted properly.
the setValue call catches it unless people use fluent interfaces.
Example:
try {
$der->objectIdentifier('foo')->serialize();
} catch () {
}
Changed paths:
U pear2/Pyrus/trunk/src/Pyrus/DER/ObjectIdentifier.php
Modified: pear2/Pyrus/trunk/src/Pyrus/DER/ObjectIdentifier.php
===================================================================
--- pear2/Pyrus/trunk/src/Pyrus/DER/ObjectIdentifier.php 2010-02-28 02:41:40 UTC (rev 295570)
+++ pear2/Pyrus/trunk/src/Pyrus/DER/ObjectIdentifier.php 2010-02-28 02:53:29 UTC (rev 295571)
@@ -59,20 +59,27 @@
if (!is_string($value)) {
throw new Exception('Object Identifier must be a string');
}
+
$value = explode('.', $value);
foreach ($value as $val) {
if (!preg_match('/[0-9]+/', $val)) {
throw new Exception('Object Identifier must be a period-delimited string of
numbers');
}
}
+
$this->value = $value;
}
function serialize()
{
- $obj = $this->value;
+ $obj = $this->value;
+ if (count($obj) < 4) {
+ throw new Exception('The Object Identifier value can be no less than 4 numbers in
a period-delimited string');
+ }
+
$value = chr($obj[0] * 40 + $obj[1]);
- $obj = array_slice($obj, 2);
+ $obj = array_slice($obj, 2);
+
foreach ($obj as $node) {
if ($node > 127) {
// value is encoded in base 128, all significant bits set to 1 except
@@ -83,6 +90,7 @@
$components[] = $node % 128;
$node = floor($node / 128);
}
+
$components = array_reverse($components);
$componentcount = count($components);
for ($i = 0; $i < $componentcount; $i++) {
@@ -95,6 +103,7 @@
$value .= chr((int) $node);
}
}
+
return $this->prependTLV($value, strlen($value));
}