From 7fc3cf69f817c50688b26b2d2228360fd733585d Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 15 Apr 2018 08:30:02 -0500 Subject: [PATCH] Tests/ASN1: add test for commit 6dc7b3e --- tests/Unit/File/ASN1Test.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Unit/File/ASN1Test.php b/tests/Unit/File/ASN1Test.php index 2708b858..7e01e1aa 100644 --- a/tests/Unit/File/ASN1Test.php +++ b/tests/Unit/File/ASN1Test.php @@ -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); + } }