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 tsp 22 */ 23 24/** 25 * Base class for GuardTime verification results. 26 * 27 * @package tsp 28 */ 29abstract class GTVerifificationResultBase { 30 31 const NO_CHECKS = 0; 32 const NO_FAILURES = 0; 33 34 private $errorCode; 35 private $statusCode; 36 37 /** 38 * Construct a new instance of GTVerificationResultBase. 39 * 40 * @param int $statusCode verification status code bitfield 41 * @param int $errorCode verification error code bitfield 42 */ 43 public function __construct($statusCode = null, $errorCode = null) { 44 45 if (is_null($statusCode)) { 46 $statusCode = self::NO_CHECKS; 47 } 48 49 if (is_null($errorCode)) { 50 $errorCode = self::NO_FAILURES; 51 } 52 53 $this->statusCode = $statusCode; 54 $this->errorCode = $errorCode; 55 } 56 57 /** 58 * Gets the status bitfield for this verification result. 59 * 60 * @return int status bitfield 61 */ 62 public function getStatusCode() { 63 return $this->statusCode; 64 } 65 66 /** 67 * Gets the error bitfield for this verification result. 68 * 69 * @return int error bitfield 70 */ 71 public function getErrorCode() { 72 return $this->errorCode; 73 } 74 75 /** 76 * Checks if this verification result has specified status code set. 77 * 78 * @param int $statusCode the status code to check for 79 * @return bool true if this verification result has specified status code set 80 */ 81 public function hasStatus($statusCode) { 82 return ($statusCode & $this->statusCode) > 0; 83 } 84 85 /** 86 * Checks if this verification result has specified error code set. 87 * 88 * @param int $errorCode the error code to check for 89 * @return bool 90 */ 91 public function hasError($errorCode) { 92 return ($errorCode & $this->errorCode) > 0; 93 } 94 95 /** 96 * Checks if this verification result is valid. 97 * 98 * @return bool true if no error codes are set 99 */ 100 public function isValid() { 101 return $this->errorCode == self::NO_FAILURES; 102 } 103 104 /** 105 * Updates this verification result status bitfield with specified status code. 106 * 107 * @param int $statusCode the status code to set 108 * @return void 109 */ 110 public function updateStatus($statusCode) { 111 $this->statusCode |= $statusCode; 112 } 113 114 /** 115 * Updates this verification result error bitfield with specified error code. 116 * 117 * @param int $errorCode the error code to set 118 * @return void 119 */ 120 public function updateErrors($errorCode) { 121 $this->errorCode |= $errorCode; 122 } 123 124} 125 126?> 127