00001 // LICENSE: (Please see the file COPYING for details) 00002 // 00003 // NUS - Nemesis Utilities System: A C++ application development framework 00004 // Copyright (C) 2006, 2008 Otavio Rodolfo Piske 00005 // 00006 // This file is part of NUS 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Lesser General Public 00010 // License as published by the Free Software Foundation version 2.1 00011 // of the License. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Lesser General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Lesser General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 // 00022 #include "nsha1hash.h" 00023 00028 NSha1Hash::NSha1Hash(void) { 00029 setHashBufferSize(48); 00030 init("sha1"); 00031 } 00032 00033 00034 NSha1Hash::~NSha1Hash(void) { 00035 00036 } 00037 00038 00039 NHash NSha1Hash::calculate(const NString &str) { 00040 NString value; 00041 00042 update(str.toChar(), str.length()); 00043 value = cleanup(); 00044 00045 return NHash("sha1", value); 00046 } 00047 00048 00049 NHash NSha1Hash::calculate(const NDataStream &data, nint32 size) { 00050 NString value; 00051 update(data.data(), size); 00052 00053 value = cleanup(); 00054 00055 return NHash("sha1", value); 00056 } 00057 00058 00059 NHash NSha1Hash::calculateFile(const NString &filename) { 00060 NFile file(filename, NIODevice::ReadOnly); 00061 00062 return calculateFile(&file); 00063 00064 } 00065 00066 00067 NHash NSha1Hash::calculateFile(NFile *file) { 00068 NDataStream buffer; 00069 00070 while (!file->atEnd()) { 00071 file->read(&buffer, 48); 00072 update(buffer.data(), buffer.size()); 00073 00074 } 00075 00076 return NHash("sha1", cleanup()); 00077 }