1<?php 2/* 3 * Copyright 2008-2010 GuardTime AS 4 * 5 * This file is part of the GuardTime PHP SDK. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20/** 21 * @package asn1 22 * @subpackage gt 23 */ 24 25/** 26 * GT CertToken implementation. 27 * 28 * <pre> 29 * CertToken ::= SEQUENCE { 30 * version INTEGER { v1(1) }, 31 * history OCTET STRING, 32 * publishedData PublishedData, 33 * pubReference SET OF OCTET STRING 34 * extensions [0] Extensions OPTIONAL 35 * } 36 * </pre> 37 * 38 * @package asn1 39 * @subpackage gt 40 */ 41class GTCertToken { 42 43 private $version = 1; 44 private $history; 45 private $publishedData; 46 private $pubReference; 47 48 /** 49 * Constructs a new instance of GTCertToken. 50 */ 51 public function __construct() { 52 } 53 54 /** 55 * Decodes the given ASN1Sequence as GTCertToken. 56 * 57 * @throws GTException 58 * @param ASN1Sequence $object GTCertToken encoded as ASN1Sequence 59 * @return void 60 */ 61 public function decode($object) { 62 63 if (!$object instanceof ASN1Sequence) { 64 throw new GTException("Expecting an ASN1Sequence"); 65 } 66 67 if ($object->getObjectCount() < 4 || $object->getObjectCount() > 5) { 68 throw new GTException("Invalid sequence size: " . $object->getObjectCount()); 69 } 70 71 $version = (int) $object->getObjectAt(0)->getValue(); 72 73 if ($version != $this->version) { 74 throw new GTException("Invalid CertToken version: {$version}"); 75 } 76 77 $this->history = $object->getObjectAt(1)->getValue(); 78 79 $publishedData = new GTPublishedData(); 80 $publishedData->decode($object->getObjectAt(2)); 81 82 $this->publishedData = $publishedData; 83 84 $pubReference = array(); 85 86 foreach ($object->getObjectAt(3)->getObjects() as $item) { 87 array_push($pubReference, $item->getValue()); 88 } 89 90 $this->pubReference = $pubReference; 91 92 if ($object->getObjectCount() == 5) { 93 throw new GTException("CertToken.extensions not yet implemented"); 94 } 95 } 96 97 /** 98 * Gets the version. 99 * 100 * @return int version 101 */ 102 public function getVersion() { 103 return $this->version; 104 } 105 106 /** 107 * Gets the history bytes. 108 * 109 * @return array byte array containing the history bytes 110 */ 111 public function getHistory() { 112 return $this->history; 113 } 114 115 /** 116 * Gets the published data. 117 * 118 * @return GTPublishedData published data 119 */ 120 public function getPublishedData() { 121 return $this->publishedData; 122 } 123 124 /** 125 * Gets the pub reference. 126 * 127 * @return array array of byte arrays 128 */ 129 public function getPubReference() { 130 return $this->pubReference; 131 } 132 133} 134 135?> 136