Tests/ASN1: add test for commit 6dc7b3e

This commit is contained in:
terrafrost 2018-04-15 08:30:02 -05:00
parent c63c223972
commit 7fc3cf69f8

View File

@ -299,4 +299,36 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
$data = base64_decode('MD6gJQYKKwYBBAGCNxQCA6AXDBVvZmZpY2VAY2VydGRpZ2l0YWwucm+BFW9mZmljZUBjZXJ0ZGlnaXRhbC5ybw==');
$asn1->decodeBER($data);
}
public function testApplicationTag()
{
$map = array(
'type' => FILE_ASN1_TYPE_SEQUENCE,
'children' => array(
// technically, default implies optional, but we'll define it as being optional, none-the-less, just to
// reenforce that fact
'version' => array(
// if class isn't present it's assumed to be FILE_ASN1_CLASS_UNIVERSAL or
// (if constant is present) FILE_ASN1_CLASS_CONTEXT_SPECIFIC
'class' => FILE_ASN1_CLASS_APPLICATION,
'cast' => 2,
'optional' => true,
'explicit' => true,
'default' => 'v1',
'type' => FILE_ASN1_TYPE_INTEGER,
'mapping' => array('v1', 'v2', 'v3')
)
)
);
$data = array('version' => 'v3');
$asn1 = new File_ASN1();
$str = $asn1->encodeDER($data, $map);
$decoded = $asn1->decodeBER($str);
$arr = $asn1->asn1map($decoded[0], $map);
$this->assertSame($data, $arr);
}
}