* * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * (1) Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * (2) Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * (3) Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ include_once "@PHP_MODULE_FILE_NAME@"; /** * @coversDefaultClass VirgilAsn1Writer */ class VirgilAsn1Writer_Test extends PHPUnit_Framework_TestCase { /** * @covers VirgilAsn1Writer::__construct */ public function test_asn1_writer_creation() { $asn1Writer = new VirgilAsn1Writer(); $this->assertInstanceOf("VirgilAsn1Writer", $asn1Writer); return $asn1Writer; } /** * @covers VirgilAsn1Writer::writeInteger * @depends test_asn1_writer_creation */ public function test_asn1_write_integer(VirgilAsn1Writer $asn1Writer) { $expectedAsn1 = file_get_contents("data/asn1_integer.der"); $asn1Writer->reset(); $asn1Writer->writeInteger(7); $asn1 = $asn1Writer->finish(); $this->assertEquals($expectedAsn1, $asn1); } /** * @covers VirgilAsn1Writer::writeOctetString * @depends test_asn1_writer_creation */ public function test_asn1_write_octet_string(VirgilAsn1Writer $asn1Writer) { $expectedAsn1 = file_get_contents("data/asn1_octet_string.der"); $asn1Writer->reset(); $asn1Writer->writeOctetString(pack("H*", "00112233445566778899AABBCCDDEEFF")); $asn1 = $asn1Writer->finish(); $this->assertEquals($expectedAsn1, $asn1); } /** * @covers VirgilAsn1Writer::writeUTF8String * @depends test_asn1_writer_creation */ public function test_asn1_write_utf8_string(VirgilAsn1Writer $asn1Writer) { $expectedAsn1 = file_get_contents("data/asn1_utf8_string.der"); $utf8StringValue = "Строка в UTF8"; $asn1Writer->reset(); $asn1Writer->writeUTF8String($utf8StringValue); $asn1 = $asn1Writer->finish(); $this->assertEquals($expectedAsn1, $asn1); } /** * @covers VirgilAsn1Writer::writeInteger * @covers VirgilAsn1Writer::writeOctetString * @covers VirgilAsn1Writer::writeSequence * @depends test_asn1_writer_creation */ public function test_asn1_write_sequence(VirgilAsn1Writer $asn1Writer) { $expectedAsn1 = file_get_contents("data/asn1_sequence.der"); $asn1Writer->reset(); $writtenBytes = 0; $writtenBytes += $asn1Writer->writeOctetString(pack("H*", "00112233445566778899AABBCCDDEEFF")); $writtenBytes += $asn1Writer->writeInteger(7); $writtenBytes += $asn1Writer->writeSequence($writtenBytes); $asn1 = $asn1Writer->finish(); $this->assertEquals($expectedAsn1, $asn1); } /** * @covers VirgilAsn1Writer::writeInteger * @covers VirgilAsn1Writer::writeOctetString * @covers VirgilAsn1Writer::writeSequence * @depends test_asn1_writer_creation */ public function test_asn1_write_complex(VirgilAsn1Writer $asn1Writer) { $expectedAsn1 = file_get_contents("data/asn1_complex.der"); $asn1Writer->reset(); $seqBytesCount = 0; $seqBytesCount += $asn1Writer->writeOctetString(pack("H*", "00112233445566778899AABBCCDDEEFF")); $seqBytesCount += $asn1Writer->writeInteger(7); $seqBytesCount += $asn1Writer->writeSequence($seqBytesCount); $seq2BytesCount = 0; $seq2BytesCount += $asn1Writer->writeInteger(7); $seq2BytesCount += $asn1Writer->writeOctetString(pack("H*", "00112233445566778899AABBCCDDEEFF")); $seq2BytesCount += $asn1Writer->writeSequence($seq2BytesCount); $asn1Writer->writeSequence($seqBytesCount + $seq2BytesCount); $asn1 = $asn1Writer->finish(); $this->assertEquals($expectedAsn1, $asn1); } /** * @covers VirgilAsn1Writer::writeInteger * @covers VirgilAsn1Writer::writeOctetString * @covers VirgilAsn1Writer::writeSequence * @covers VirgilAsn1Writer::writeContextTag * @depends test_asn1_writer_creation */ public function test_asn1_write_context_tag(VirgilAsn1Writer $asn1Writer) { $expectedAsn1 = file_get_contents("data/asn1_custom_tag.der"); $asn1Writer->reset(); $seqBytesCount = 0; $seqBytesCount += $asn1Writer->writeOctetString(pack("H*", "00112233445566778899AABBCCDDEEFF")); $seqBytesCount += $integerLen = $asn1Writer->writeInteger(7); $seqBytesCount += $asn1Writer->writeContextTag(0, $integerLen); $seqBytesCount += $asn1Writer->writeSequence($seqBytesCount); $asn1 = $asn1Writer->finish(); $this->assertEquals($expectedAsn1, $asn1); } } ?>