00001 /* Copyright 2009 Andreas Gölzer 00002 00003 This file is part of readESM. 00004 00005 readESM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 00006 00007 readESM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 00008 00009 You should have received a copy of the GNU General Public License along with readESM. If not, see <http://www.gnu.org/licenses/>. */ 00010 #ifndef VUBLOCK_H 00011 #define VUBLOCK_H 00012 #include <string> 00013 #include "time.h" 00014 #ifndef HAVE_NO_CRYPTO 00015 #include "crypto.h" 00016 #endif 00017 #include "block.h" 00018 #include "readTypes.h" 00019 00020 00021 class vublock : public block { 00022 public: 00023 virtual string name() const = 0; 00024 vublock(iter nstart) : block(nstart), block_start(&nstart[2]), runningIndex(0) { 00025 hassignature = true; 00026 } 00027 virtual void Init(){ signature = start + size() - 128; } 00028 int getBEInt32(const unsigned char* start) const{ 00029 return (start[0] << 24) + (start[1] << 16) + (start[2] << 8) + start[3]; 00030 } 00031 Time readDate(const unsigned char* in) const{ 00032 return Time::fromBigEndianChars32(in); 00033 } 00034 00035 Time readDate(int start) const{ 00036 return readDate(&block_start[start]); 00037 } 00038 Time readDate() const{ 00039 runningIndex += 4; 00040 return readDate(runningIndex - 4); 00041 } 00042 string fixedString(int length) const{ 00043 runningIndex += length; 00044 return ::fixedString(start + 2 + runningIndex - length, length); 00045 } 00046 int IntByte(int start) const{ 00047 return int(block_start[start]); 00048 } 00049 int IntByte() const{ 00050 runningIndex += 1; 00051 return IntByte(runningIndex - 1); 00052 } 00053 int Int16(int start) const{ 00054 return (block_start[start] << 8)+ block_start[start+1]; 00055 } 00056 int Int16() const{ 00057 runningIndex += 2; 00058 return Int16(runningIndex - 2); 00059 } 00060 00061 int Odometer(int start) const{ 00062 return (block_start[start] << 16) + (block_start[start + 1] << 8) + block_start[start + 2]; 00063 } 00064 int Odometer() const{ 00065 runningIndex += 3; 00066 return Odometer(runningIndex - 3); 00067 } 00068 00069 string fixedString(int offset, int length) const{ 00070 return ::fixedString(start + 2 + offset, length); 00071 } 00072 const unsigned char* block_start; 00073 mutable int runningIndex; 00074 virtual int size() const = 0; 00075 virtual void CompleteReport(reporter& report) const = 0; 00076 virtual void BriefReport(reporter& report) const = 0; 00077 virtual void printOn(reporter& report) const{ 00078 if(report.verbose) CompleteReport(report); 00079 else BriefReport(report); 00080 } 00081 #ifndef HAVE_NO_CRYPTO 00082 virtual bool checksig(const rsa& key){; 00083 validsignature = CheckSignature(start + 2 + nonhashedbytes(), size() - 128 - 2 - nonhashedbytes(), signature, 128, key); 00084 return validsignature; 00085 } 00086 #endif 00087 virtual int nonhashedbytes() const{ return 0;} 00088 }; 00089 00090 #endif