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 VerificationRequest implementation. 27 * 28 * <pre> 29 * VerificationRequest :: = SEQUENCE { 30 * version INTEGER { v1(1) }, 31 * content ContentInfo, 32 * data OCTET STRING 33 * } 34 * </pre> 35 * 36 * @package asn1 37 * @subpackage gt 38 */ 39class GTVerificationRequest implements ASN1DEREncodable { 40 41 private $version; 42 private $content; 43 private $data; 44 45 /** 46 * Constructs a new instance of GTVerificationRequest. 47 * 48 */ 49 public function __construct() { 50 } 51 52 /** 53 * Decodes the given ASN1Sequence as GTVerificationRequest. 54 * 55 * @throws GTException 56 * @param ASN1Sequence $object GTVerificationRequest encoded as ASN1Sequence 57 * @return void 58 */ 59 public function decode($object) { 60 61 if (!$object instanceof ASN1Sequence) { 62 throw new GTException("Expecting an ASN1Sequence"); 63 } 64 65 $size = $object->getObjectCount(); 66 67 if ($size != 3) { 68 throw new GTException("Invalid sequence size: {$size}"); 69 } 70 71 $version = $object->getObjectAt(0); 72 73 if (!$version instanceof ASN1Integer) { 74 throw new GTException("Expecting an ASN1Integer as version"); 75 } 76 77 $this->version = (int) $version->getValue(); 78 79 if ($this->version != 1) { 80 throw new GTException("Invalid value for version: {$this->version}"); 81 } 82 83 $content = new CMSContentInfo(); 84 $content->decode($object->getObjectAt(1)); 85 86 $this->content = $content; 87 88 $data = $object->getObjectAt(2); 89 90 if (!$data instanceof ASN1OctetString) { 91 throw new GTException("Expecting an ASN1OctetString as data"); 92 } 93 94 $this->data = $data->getValue(); 95 96 } 97 98 /** 99 * Encodes this GTVerificationRequest using DER. 100 * 101 * @return array byte array that contains the DER encoding of this GTVerificationRequest 102 */ 103 public function encodeDER() { 104 105 $sequence = new ASN1Sequence(); 106 $sequence->add(new ASN1Integer($this->version)); 107 $sequence->add($this->content); 108 $sequence->add(new ASN1OctetString($this->data)); 109 110 return $sequence->encodeDER(); 111 } 112 113 /** 114 * Gets the version. 115 * 116 * @return int version 117 */ 118 public function getVersion() { 119 return $this->version; 120 } 121 122 /** 123 * Sets the version. 124 * 125 * @param int $version the version 126 * @return void 127 */ 128 public function setVersion($version) { 129 $this->version = $version; 130 } 131 132 /** 133 * Gets the content (timestamp). 134 * 135 * @return CMSContentInfo timestamp 136 */ 137 public function getContent() { 138 return $this->content; 139 } 140 141 /** 142 * Sets the content (timestamp). 143 * 144 * @param CMSContentInfo $content timestamp 145 * @return void 146 */ 147 public function setContent($content) { 148 $this->content = $content; 149 } 150 151 /** 152 * Gets the data. 153 * 154 * @return array byte array containing the data bytes. 155 */ 156 public function getData() { 157 return $this->data; 158 } 159 160 /** 161 * Sets the data. 162 * 163 * @param array $data byte array containing the data bytes. 164 * @return void 165 */ 166 public function setData($data) { 167 $this->data = $data; 168 } 169 170} 171 172?> 173