Merge pull request #480 from terrafrost/asn1-fix

ASN1: fix issue with non-constructed context-specific tags

* terrafrost/asn1-fix:
  ASN1: fix unit test
  ASN1: add unit test for non-constructed context-specific change
  ASN1: fix issue with non-constructed context-specific tags
This commit is contained in:
Andreas Fischer 2014-09-24 16:50:03 +02:00
commit ba5101e77b
2 changed files with 20 additions and 5 deletions

View File

@ -347,19 +347,24 @@ class File_ASN1
case FILE_ASN1_CLASS_APPLICATION:
case FILE_ASN1_CLASS_PRIVATE:
case FILE_ASN1_CLASS_CONTEXT_SPECIFIC:
if ($constructed) {
$newcontent = $this->_decode_ber($content, $start);
$length = $newcontent['length'];
if (substr($content, $length, 2) == "\0\0") {
$length+= 2;
}
// the array encapsulation is for BC with the old format
$content = array($newcontent);
}
$start+= $length;
return array(
'type' => $class,
'constant' => $tag,
// the array encapsulation is for BC with the old format
'content' => array($newcontent),
'content' => $content,
// the only time when $content['headerlength'] isn't defined is when the length is indefinite.
// the absence of $content['headerlength'] is how we know if something is indefinite or not.
// technically, it could be defined to be 2 and then another indicator could be used but whatever.

View File

@ -268,4 +268,14 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
$decoded = $asn1->decodeBER(base64_decode($str));
$this->assertCount(3, $decoded[0]['content']);
}
/**
* @group github477
*/
public function testContextSpecificNonConstructed()
{
$asn1 = new File_ASN1();
$decoded = $asn1->decodeBER(base64_decode('MBaAFJtUo7c00HsI5EPZ4bkICfkOY2Pv'));
$this->assertInternalType('string', $decoded[0]['content'][0]['content']);
}
}