Skip to content

Commit

Permalink
Rename ElementWrapper to UnspecifiedType
Browse files Browse the repository at this point in the history
  • Loading branch information
sop committed Jun 2, 2016
1 parent 58ee59f commit 2e5bb5d
Show file tree
Hide file tree
Showing 37 changed files with 122 additions and 121 deletions.
8 changes: 4 additions & 4 deletions lib/ASN1/Type/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use ASN1\Component\Identifier;
use ASN1\Component\Length;
use ASN1\Element;
use ASN1\ElementWrapper;
use ASN1\Exception\DecodeException;
use ASN1\Type\UnspecifiedType;


/**
Expand Down Expand Up @@ -217,13 +217,13 @@ public function has($idx, $expectedTag = null) {
* Optionally check that the element has a given tag.
*
* NOTE! Expectation checking is deprecated and shall be done
* with ElementWrapper.
* with UnspecifiedType.
*
* @param int $idx Index, first element is 0
* @param int $expectedTag Type tag to expect
* @throws \OutOfBoundsException If element doesn't exists
* @throws \UnexpectedValueException If expectation fails
* @return ElementWrapper
* @return UnspecifiedType
*/
public function at($idx, $expectedTag = null) {
if (!isset($this->_elements[$idx])) {
Expand All @@ -234,7 +234,7 @@ public function at($idx, $expectedTag = null) {
if (isset($expectedTag)) {
$element->expectType($expectedTag);
}
return new ElementWrapper($element);
return new UnspecifiedType($element);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/ASN1/Type/Tagged/DERTaggedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use ASN1\Component\Identifier;
use ASN1\Component\Length;
use ASN1\Element;
use ASN1\ElementWrapper;
use ASN1\Type\TaggedType;
use ASN1\Type\UnspecifiedType;


/**
Expand Down Expand Up @@ -73,20 +73,20 @@ protected function _encodedContentDER() {
/**
*
* @see \ASN1\Type\Tagged\ImplicitTagging::implicit()
* @return ElementWrapper
* @return UnspecifiedType
*/
public function implicit($tag, $class = Identifier::CLASS_UNIVERSAL) {
$identifier = $this->_identifier->withClass($class)->withTag($tag);
$cls = self::_determineImplClass($identifier);
$idx = $this->_offset;
$element = $cls::_decodeFromDER($identifier, $this->_data, $idx);
return new ElementWrapper($element);
return new UnspecifiedType($element);
}

/**
*
* @see \ASN1\Type\Tagged\ExplicitTagging::explicit()
* @return ElementWrapper
* @return UnspecifiedType
*/
public function explicit($expectedTag = null) {
$idx = $this->_offset;
Expand All @@ -95,6 +95,6 @@ public function explicit($expectedTag = null) {
if (isset($expectedTag)) {
$element->expectType($expectedTag);
}
return new ElementWrapper($element);
return new UnspecifiedType($element);
}
}
6 changes: 3 additions & 3 deletions lib/ASN1/Type/Tagged/ExplicitTagging.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace ASN1\Type\Tagged;

use ASN1\Element;
use ASN1\ElementWrapper;
use ASN1\Feature\ElementBase;
use ASN1\Type\UnspecifiedType;


interface ExplicitTagging extends ElementBase
Expand All @@ -13,11 +13,11 @@ interface ExplicitTagging extends ElementBase
* Get explicitly tagged wrapped element.
*
* NOTE! Expectation checking is deprecated and shall be done
* with ElementWrapper.
* with UnspecifiedType.
*
* @param int|null $expectedTag Expected tag of the underlying type
* @throws \UnexpectedValueException If expectation fails
* @return ElementWrapper
* @return UnspecifiedType
*/
public function explicit($expectedTag = null);
}
6 changes: 3 additions & 3 deletions lib/ASN1/Type/Tagged/ExplicitlyTaggedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ASN1\Type\Tagged;

use ASN1\Element;
use ASN1\ElementWrapper;
use ASN1\Type\UnspecifiedType;


/**
Expand Down Expand Up @@ -37,12 +37,12 @@ protected function _encodedContentDER() {
/**
*
* @see \ASN1\Type\Tagged\ExplicitTagging::explicit()
* @return ElementWrapper
* @return UnspecifiedType
*/
public function explicit($expectedTag = null) {
if (isset($expectedTag)) {
$this->_element->expectType($expectedTag);
}
return new ElementWrapper($this->_element);
return new UnspecifiedType($this->_element);
}
}
4 changes: 2 additions & 2 deletions lib/ASN1/Type/Tagged/ImplicitTagging.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use ASN1\Component\Identifier;
use ASN1\Element;
use ASN1\ElementWrapper;
use ASN1\Feature\ElementBase;
use ASN1\Type\UnspecifiedType;


interface ImplicitTagging extends ElementBase
Expand All @@ -16,7 +16,7 @@ interface ImplicitTagging extends ElementBase
* @param int $tag Tag of the element
* @param int $class Expected type class of the element
* @throws \UnexpectedValueException If expectation fails
* @return ElementWrapper
* @return UnspecifiedType
*/
public function implicit($tag, $class = Identifier::CLASS_UNIVERSAL);
}
6 changes: 3 additions & 3 deletions lib/ASN1/Type/Tagged/ImplicitlyTaggedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ASN1\Component\Identifier;
use ASN1\Element;
use ASN1\ElementWrapper;
use ASN1\Type\UnspecifiedType;


/**
Expand Down Expand Up @@ -40,7 +40,7 @@ protected function _encodedContentDER() {
/**
*
* @see \ASN1\Type\Tagged\ImplicitTagging::implicit()
* @return ElementWrapper
* @return UnspecifiedType
*/
public function implicit($tag, $class = Identifier::CLASS_UNIVERSAL) {
$this->_element->expectType($tag);
Expand All @@ -50,6 +50,6 @@ public function implicit($tag, $class = Identifier::CLASS_UNIVERSAL) {
" expected, got " .
Identifier::classToName($this->_element->typeClass()) . ".");
}
return new ElementWrapper($this->_element);
return new UnspecifiedType($this->_element);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

namespace ASN1;
namespace ASN1\Type;

use ASN1\Component\Identifier;
use ASN1\Element;
use ASN1\Feature\ElementBase;
use ASN1\Type\Constructed\Sequence;
use ASN1\Type\Constructed\Set;
Expand Down Expand Up @@ -42,7 +43,7 @@
* Provides accessor methods to test the underlying type and return a type
* hinted instance of the concrete element.
*/
class ElementWrapper implements ElementBase
class UnspecifiedType implements ElementBase
{
/**
* Wrapped element.
Expand Down
28 changes: 14 additions & 14 deletions test/tests/ElementWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@

use ASN1\DERData;
use ASN1\Element;
use ASN1\ElementWrapper;
use ASN1\Feature\ElementBase;
use ASN1\Type\Primitive\NullType;
use ASN1\Type\Tagged\ImplicitlyTaggedType;
use ASN1\Type\UnspecifiedType;


class ElementWrapperTest extends PHPUnit_Framework_TestCase
{
public function testAsElement() {
$wrap = new ElementWrapper(new NullType());
$wrap = new UnspecifiedType(new NullType());
$this->assertInstanceOf(ElementBase::class, $wrap->asElement());
}

/**
* @expectedException UnexpectedValueException
*/
public function testAsTaggedFail() {
$wrap = new ElementWrapper(new NullType());
$wrap = new UnspecifiedType(new NullType());
$wrap->asTagged();
}

/**
* @expectedException UnexpectedValueException
*/
public function testAsStringFail() {
$wrap = new ElementWrapper(new NullType());
$wrap = new UnspecifiedType(new NullType());
$wrap->asString();
}

/**
* @expectedException UnexpectedValueException
*/
public function testAsTimeFail() {
$wrap = new ElementWrapper(new NullType());
$wrap = new UnspecifiedType(new NullType());
$wrap->asTime();
}

Expand All @@ -44,56 +44,56 @@ public function testAsTimeFail() {
*/
public function testPrivateTypeFail() {
$el = new DERData("\xdf\x7f\x0");
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$wrap->asNull();
}

public function testToDER() {
$el = new NullType();
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertEquals($el->toDER(), $wrap->toDER());
}

public function testTypeClass() {
$el = new NullType();
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertEquals($el->typeClass(), $wrap->typeClass());
}

public function testIsConstructed() {
$el = new NullType();
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertEquals($el->isConstructed(), $wrap->isConstructed());
}

public function testTag() {
$el = new NullType();
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertEquals($el->tag(), $wrap->tag());
}

public function testIsType() {
$el = new NullType();
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertTrue($wrap->isType(Element::TYPE_NULL));
}

public function testExpectType() {
$el = new NullType();
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertInstanceOf(ElementBase::class,
$wrap->expectType(Element::TYPE_NULL));
}

public function testIsTagged() {
$el = new NullType();
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertEquals($el->isTagged(), $wrap->isTagged());
}

public function testExpectTagged() {
$el = new ImplicitlyTaggedType(0, new NullType());
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertInstanceOf(ElementBase::class, $wrap->expectTagged(0));
}
}
4 changes: 2 additions & 2 deletions test/tests/tagging/DERTaggedTypeTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use ASN1\Element;
use ASN1\ElementWrapper;
use ASN1\Type\Tagged\DERTaggedType;
use ASN1\Type\TaggedType;
use ASN1\Type\UnspecifiedType;


/**
Expand Down Expand Up @@ -51,7 +51,7 @@ public function testExpectImplicit(DERTaggedType $el) {
* @param Element $el
*/
public function testWrapped(Element $el) {
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertInstanceOf(TaggedType::class, $wrap->asTagged());
}
}
4 changes: 2 additions & 2 deletions test/tests/type/StringTypeTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use ASN1\ElementWrapper;
use ASN1\Type\Primitive\OctetString;
use ASN1\Type\StringType;
use ASN1\Type\UnspecifiedType;


/**
Expand All @@ -17,7 +17,7 @@ public function testStr() {
}

public function testWrapped() {
$wrap = new ElementWrapper(new OctetString(""));
$wrap = new UnspecifiedType(new OctetString(""));
$this->assertInstanceOf(StringType::class, $wrap->asString());
}
}
6 changes: 3 additions & 3 deletions test/tests/type/TimeTypeTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use ASN1\ElementWrapper;
use ASN1\Type\Primitive\GeneralizedTime;
use ASN1\Type\TimeType;
use ASN1\Type\UnspecifiedType;


/**
Expand Down Expand Up @@ -39,11 +39,11 @@ public function testFromStringWithInvalidTzFail() {

/**
* @depends testFromString
*
*
* @param TimeType $time
*/
public function testWrapped(TimeType $time) {
$wrap = new ElementWrapper($time);
$wrap = new UnspecifiedType($time);
$this->assertInstanceOf(TimeType::class, $wrap->asTime());
}
}
6 changes: 3 additions & 3 deletions test/tests/type/constructed/sequence/SequenceTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

use ASN1\Element;
use ASN1\ElementWrapper;
use ASN1\Type\Constructed\Sequence;
use ASN1\Type\Primitive\Boolean;
use ASN1\Type\Primitive\NullType;
use ASN1\Type\Structure;
use ASN1\Type\UnspecifiedType;


/**
Expand Down Expand Up @@ -140,15 +140,15 @@ public function testAtOOB(Sequence $seq) {
* @param Element $el
*/
public function testWrapped(Element $el) {
$wrap = new ElementWrapper($el);
$wrap = new UnspecifiedType($el);
$this->assertInstanceOf(Sequence::class, $wrap->asSequence());
}

/**
* @expectedException UnexpectedValueException
*/
public function testWrappedFail() {
$wrap = new ElementWrapper(new NullType());
$wrap = new UnspecifiedType(new NullType());
$wrap->asSequence();
}
}

0 comments on commit 2e5bb5d

Please sign in to comment.