From: Josh T <spa...@us...> - 2006-09-29 17:32:12
|
Update of /cvsroot/sashimi/ReAdW In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv31246 Modified Files: ReAdW.cpp ReAdW.dsp ReAdW.h StdAfx.cpp StdAfx.h resource.h xml_out.cpp xml_out.h xrawfile2.cpp xrawfile2.h Added Files: Base64.cpp Base64.h SHA1.cpp SHA1.h Removed Files: base64.cpp base64.h sha1.cpp sha1.h Log Message: renamed base64 to Base64, sha1 to SHA1 in prep for unifying shared code amnong converters --- NEW FILE: SHA1.h --- /*--------------------------------------------------------------------------- ## File: ## @@(#) sha1.h ## Author: ## Dominik Reichl <Dom...@ti...> ## ##***************************************************************************** ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU Library or "Lesser" General Public ## License (LGPL) as published by the Free Software Foundation; ## either version 2 of the License, or (at your option) any later ## version. ## ##***************************************************************************** ## ## Changes ## ## $Log: SHA1.h,v $ ## Revision 1.1 2006/09/29 17:32:07 spacepod ## renamed base64 to Base64, sha1 to SHA1 in prep for unifying shared code amnong converters ## ## Revision 1.2 2004/08/30 19:11:15 brendanx ## Fix line endings. ## ## Revision 1.1.1.1 2004/03/28 21:47:05 ppatrick ## Initial import. ## ## ## ##---------------------------------------------------------------------------*/ /* 100% free public domain implementation of the SHA-1 algorithm by Dominik Reichl <Dom...@ti...> === Test Vectors (from FIPS PUB 180-1) === "abc" A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 A million repetitions of "a" 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F */ #if !defined(___SHA1_H___) #define ___SHA1_H___ #include <stdio.h> // Needed for file access #include <memory.h> // Needed for memset and memcpy #include <string> // Needed for strcat and strcpy #define LITTLE_ENDIAN #define MAX_FILE_READ_BUFFER 8000 class CSHA1 { public: // Rotate x bits to the left #define ROL32(value, bits) (((value)<<(bits))|((value)>>(32-(bits)))) #ifdef LITTLE_ENDIAN #define SHABLK0(i) (block->l[i] = (ROL32(block->l[i],24) & 0xFF00FF00) \ | (ROL32(block->l[i],8) & 0x00FF00FF)) #else #define SHABLK0(i) (block->l[i]) #endif #define SHABLK(i) (block->l[i&15] = ROL32(block->l[(i+13)&15] ^ block->l[(i+8)&15] \ ^ block->l[(i+2)&15] ^ block->l[i&15],1)) // SHA-1 rounds #define R0(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK0(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } #define R1(v,w,x,y,z,i) { z+=((w&(x^y))^y)+SHABLK(i)+0x5A827999+ROL32(v,5); w=ROL32(w,30); } #define R2(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0x6ED9EBA1+ROL32(v,5); w=ROL32(w,30); } #define R3(v,w,x,y,z,i) { z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5); w=ROL32(w,30); } #define R4(v,w,x,y,z,i) { z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5); w=ROL32(w,30); } typedef union { unsigned char c[64]; unsigned long l[16]; } SHA1_WORKSPACE_BLOCK; // Two different formats for ReportHash(...) enum { REPORT_HEX = 0, REPORT_DIGIT = 1 }; // Constructor and Destructor CSHA1(); virtual ~CSHA1(); unsigned long m_state[5]; unsigned long m_count[2]; unsigned char m_buffer[64]; unsigned char m_digest[20]; void Reset(); // Update the hash value void Update(unsigned char* data, unsigned int len); bool HashFile(char *szFileName); // Finalize hash and report void Final(); void ReportHash(char *szReport, unsigned char uReportType = REPORT_HEX); void GetHash(unsigned char *uDest); private: // Private SHA-1 transformation void Transform(unsigned long state[5], unsigned char buffer[64]); }; #endif // ___SHA1_H___ Index: xrawfile2.h =================================================================== RCS file: /cvsroot/sashimi/ReAdW/xrawfile2.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** xrawfile2.h 14 Dec 2004 22:25:40 -0000 1.4 --- xrawfile2.h 29 Sep 2006 17:32:07 -0000 1.5 *************** *** 1,2 **** --- 1,4 ---- + // -*- mode: c++ -*- + /*************************************************************************** ReAdW *************** *** 23,26 **** --- 25,30 ---- #define __XRAWFILE2 + #include "StdAfx.h" + // Machine generated IDispatch wrapper class(es) created with ClassWizard ///////////////////////////////////////////////////////////////////////////// *************** *** 165,167 **** }; ! #endif //__XRAWFILE2 \ No newline at end of file --- 169,171 ---- }; ! #endif //__XRAWFILE2 Index: ReAdW.cpp =================================================================== RCS file: /cvsroot/sashimi/ReAdW/ReAdW.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ReAdW.cpp 20 Sep 2006 21:19:42 -0000 1.13 --- ReAdW.cpp 29 Sep 2006 17:32:07 -0000 1.14 *************** *** 1,21 **** /*************************************************************************** ! ReAdW This program converts Xcalibur native data into mzXML format. The program requires the XRawfile library from ThermoFinnigan to run. ! ------------------- ! begin : Sat Mar 27 ! copyright : (C) 2004 by Pedrioli Patrick, ISB, Proteomics ! email : ppa...@st... ***************************************************************************/ /*************************************************************************** ! * * ! * This program 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 2 of the License, or * ! * (at your option) any later version. * ! * * ***************************************************************************/ --- 1,23 ---- + // -*- mode: c++ -*- + /*************************************************************************** ! ReAdW This program converts Xcalibur native data into mzXML format. The program requires the XRawfile library from ThermoFinnigan to run. ! ------------------- ! begin : Sat Mar 27 ! copyright : (C) 2004 by Pedrioli Patrick, ISB, Proteomics ! email : ppa...@st... ***************************************************************************/ /*************************************************************************** ! * * ! * This program 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 2 of the License, or * ! * (at your option) any later version. * ! * * ***************************************************************************/ *************** *** 63,77 **** cerr << std::endl << exeName << " version " << T2X_VERSION << std::endl << std::endl; cerr << "Usage: " << exeName << " [-c , -NoCompression , -NoRulers ] <raw file path> [<output file>]\n" ! << " -c: Centroid the data (meaningfull only\n" ! << " if RAW data is profile)\n" ! << " -NoCompression: Do not use zlib for comrpessing peaks.\n" ! << " -NoRulers: Do not attempt compression using m/z\n" ! << " ruler.\n" << endl ! << " output file: if not supplied, the raw filename will be used,\n" ! << " with the extension reset to .mzXML.\n" << endl << " --------- By Patrick Pedrioli ------------\n"; ! return -1; } --- 65,80 ---- cerr << std::endl << exeName << " version " << T2X_VERSION << std::endl << std::endl; cerr << "Usage: " << exeName << " [-c , -NoCompression , -NoRulers ] <raw file path> [<output file>]\n" ! << " -c: Centroid the data (meaningfull only\n" ! << " if RAW data is profile)\n" ! << " -NoCompression: Do not use zlib for comrpessing peaks.\n" ! << " -NoRulers: Do not attempt compression using m/z\n" ! << " ruler.\n" << endl ! << " output file: Filename for mzXML output;\n" ! << " if not supplied, the raw filename will be used,\n" ! << " with the extension reset to .mzXML.\n" << endl << " --------- By Patrick Pedrioli ------------\n"; ! return -1; } *************** *** 84,90 **** for( fileArg = 1 ; fileArg < argc ; ++fileArg ) ! { if (*argv[fileArg] == '-') ! { bDoCentroid = ( NULL != strchr( argv[fileArg] , 'c' ) ); if( strstr( argv[fileArg] , "NoCompression" ) ) --- 87,93 ---- for( fileArg = 1 ; fileArg < argc ; ++fileArg ) ! { if (*argv[fileArg] == '-') ! { bDoCentroid = ( NULL != strchr( argv[fileArg] , 'c' ) ); if( strstr( argv[fileArg] , "NoCompression" ) ) *************** *** 96,103 **** bDoRulers = false; } ! } ! } fileArg -= 2; ! int outputFileArg = fileArg + 1; --- 99,106 ---- bDoRulers = false; } ! } ! } fileArg -= 2; ! int outputFileArg = fileArg + 1; *************** *** 120,124 **** cout << "Processing scans\n"; for( scanNum = firstScan ; scanNum <= lastScan ; scanNum++ ) ! { XmlWriter.writeScan( scanNum ); } --- 123,128 ---- cout << "Processing scans\n"; for( scanNum = firstScan ; scanNum <= lastScan ; scanNum++ ) ! { ! //cout << "scan " << scanNum << std::endl; XmlWriter.writeScan( scanNum ); } Index: ReAdW.dsp =================================================================== RCS file: /cvsroot/sashimi/ReAdW/ReAdW.dsp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ReAdW.dsp 6 Jun 2006 22:11:30 -0000 1.11 --- ReAdW.dsp 29 Sep 2006 17:32:07 -0000 1.12 *************** *** 33,43 **** # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 ! # PROP BASE Output_Dir "ReAdW___Win32_Release" ! # PROP BASE Intermediate_Dir "ReAdW___Win32_Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 ! # PROP Output_Dir "ReAdW___Win32_Release" ! # PROP Intermediate_Dir "ReAdW___Win32_Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c --- 33,43 ---- # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 ! # PROP BASE Output_Dir "Release" ! # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 ! # PROP Output_Dir "Release" ! # PROP Intermediate_Dir "Release" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c *************** *** 49,54 **** # ADD BSC32 /nologo LINK32=link.exe ! # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 ! # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "ReAdW - Win32 Debug" --- 49,54 ---- # ADD BSC32 /nologo LINK32=link.exe ! # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 ! # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 !ELSEIF "$(CFG)" == "ReAdW - Win32 Debug" *************** *** 56,77 **** # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 ! # PROP BASE Output_Dir "ReAdW___Win32_Debug" ! # PROP BASE Intermediate_Dir "ReAdW___Win32_Debug" # PROP BASE Target_Dir "" ! # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 ! # PROP Output_Dir "ReAdW___Win32_Debug" ! # PROP Intermediate_Dir "ReAdW___Win32_Debug" # PROP Target_Dir "" ! # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c ! # ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" ! # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe ! # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept ! # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept !ENDIF --- 56,79 ---- # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 ! # PROP BASE Output_Dir "Debug" ! # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" ! # PROP Use_MFC 2 # PROP Use_Debug_Libraries 1 ! # PROP Output_Dir "Debug" ! # PROP Intermediate_Dir "Debug" ! # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" ! # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c ! # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../../common/zlib/include" /I "../../../common" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "_AFXDLL" /FR /FD /GZ /c ! # SUBTRACT CPP /YX # ADD BASE RSC /l 0x409 /d "_DEBUG" ! # ADD RSC /l 0x409 /fo"ReAdW.res" /d "_DEBUG" /d "_AFXDLL" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe ! # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept ! # ADD LINK32 ws2_32.lib zlib1.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../../../common/zlib/lib" !ENDIF *************** *** 84,96 **** --- 86,150 ---- # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" + # Begin Source File + + SOURCE=.\ReAdW.cpp + # End Source File + # Begin Source File + + SOURCE=.\StdAfx.cpp + # End Source File + # Begin Source File + + SOURCE=.\xml_out.cpp + # End Source File + # Begin Source File + + SOURCE=.\xrawfile2.cpp + # End Source File # End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" + # Begin Source File + + SOURCE=.\ReAdW.h + # End Source File + # Begin Source File + + SOURCE=.\resource.h + # End Source File + # Begin Source File + + SOURCE=.\StdAfx.h + # End Source File + # Begin Source File + + SOURCE=.\xml_out.h + # End Source File + # Begin Source File + + SOURCE=.\xrawfile2.h + # End Source File # End Group # Begin Group "Resource Files" # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" + # Begin Source File + + SOURCE=.\fish.ico + # End Source File + # Begin Source File + + SOURCE=.\ReAdW.rc + # End Source File # End Group + # Begin Source File + + SOURCE=..\..\..\common\Base64.cpp + # End Source File + # Begin Source File + + SOURCE=..\..\..\common\SHA1.cpp + # End Source File # End Target # End Project --- sha1.cpp DELETED --- --- NEW FILE: Base64.cpp --- /* downloaded from web */ #include "stdafx.h" #include <string.h> #include <stdio.h> #include <math.h> //#include <winsock.h> #include "base64.h" inline int getPosition( char buf ); static const unsigned char *b64_tbl = (const unsigned char*) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const unsigned char b64_pad = '='; /* base64 encode a group of between 1 and 3 input chars into a group of 4 output chars */ static void encode_group (unsigned char output[], const unsigned char input[], int n) { unsigned char ingrp[3]; ingrp[0] = n > 0 ? input[0] : 0; ingrp[1] = n > 1 ? input[1] : 0; ingrp[2] = n > 2 ? input[2] : 0; /* upper 6 bits of ingrp[0] */ output[0] = n > 0 ? b64_tbl[ingrp[0] >> 2] : b64_pad; /* lower 2 bits of ingrp[0] | upper 4 bits of ingrp[1] */ output[1] = n > 0 ? b64_tbl[((ingrp[0] & 0x3) << 4) | (ingrp[1] >> 4)] : b64_pad; /* lower 4 bits of ingrp[1] | upper 2 bits of ingrp[2] */ output[2] = n > 1 ? b64_tbl[((ingrp[1] & 0xf) << 2) | (ingrp[2] >> 6)] : b64_pad; /* lower 6 bits of ingrp[2] */ output[3] = n > 2 ? b64_tbl[ingrp[2] & 0x3f] : b64_pad; } int b64_encode (char *dest, const unsigned char *src, int len) { int outsz = 0; while (len > 0) { encode_group ((unsigned char*)dest + outsz, src, len > 3 ? 3 : len); len -= 3; src += 3; outsz += 4; } return outsz; } /* base64 decode a group of 4 input chars into a group of between 0 and * 3 output chars */ static void decode_group (unsigned char output[], const unsigned char input[], int *n) { unsigned char *t1, *t2; *n = 0; if (input[0] == '=') return; t1 = (unsigned char*) strchr ((const char*)b64_tbl, input[0]); t2 = (unsigned char*) strchr ((const char*)b64_tbl, input[1]); output[(*n)++] = ((t1 - b64_tbl) << 2) | ((t2 - b64_tbl) >> 4); if (input[2] == '=') return; t1 = (unsigned char*) strchr ((const char*)b64_tbl, input[2]); output[(*n)++] = ((t2 - b64_tbl) << 4) | ((t1 - b64_tbl) >> 2); if (input[3] == '=') return; t2 = (unsigned char*) strchr ((const char*)b64_tbl, input[3]); output[(*n)++] = ((t1 - b64_tbl) << 6) | (t2 - b64_tbl); return; } inline int getPosition( char buf ) { if( buf > 96 ) // [a-z] return (buf - 71); else if( buf > 64 ) // [A-Z] return (buf - 65); else if( buf > 47 ) // [0-9] return (buf + 4); else if( buf == 43 ) return 63; else // buf == '/' return 64; } void b64_decode_mio ( char *dest, char *src ) { char *temp; temp = dest; while (*src) { int register a; int register b; int t1,t2,t3,t4; t1 = src[0]; t2 = src[1]; t3 = src[2]; t4 = src[3]; if (t1 == 61 ) // if == '=' return; if( t1 > 96 ) // [a-z] a = (t1 - 71); else if( t1 > 64 ) // [A-Z] a = (t1 - 65); else if( t1 > 47 ) // [0-9] a = (t1 + 4); else if( t1 == 43 ) a = 62; else // src[0] == '/' a = 63; if( t2 > 96 ) // [a-z] b = (t2 - 71); else if( t2 > 64 ) // [A-Z] b = (t2 - 65); else if( t2 > 47 ) // [0-9] b = (t2 + 4); else if( t2 == 43 ) b = 62; else // src[0] == '/' b = 63; *temp++ = ( a << 2) | ( b >> 4); if (t3 == 61) return; if( t3 > 96 ) // [a-z] a = (t3 - 71); else if( t3 > 64 ) // [A-Z] a = (t3 - 65); else if( t3 > 47 ) // [0-9] a = (t3 + 4); else if( t3 == 43 ) a = 62; else // src[0] == '/' a = 63; *temp++ = ( b << 4) | ( a >> 2); if (t4 == 61) return; if( t4 > 96 ) // [a-z] b = (t4 - 71); else if( t4 > 64 ) // [A-Z] b = (t4 - 65); else if( t4 > 47 ) // [0-9] b = (t4 + 4); else if( t4 == 43 ) b = 62; else // src[0] == '/' b = 63; *temp++ = ( a << 6) | ( b ); src += 4; } } Index: ReAdW.h =================================================================== RCS file: /cvsroot/sashimi/ReAdW/ReAdW.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ReAdW.h 30 Aug 2004 19:11:15 -0000 1.2 --- ReAdW.h 29 Sep 2006 17:32:07 -0000 1.3 *************** *** 1,2 **** --- 1,4 ---- + // -*- mode: c++ -*- + /*************************************************************************** ReAdW --- NEW FILE: Base64.h --- #ifndef _BASE64_H #define _BASE64_H int b64_encode (char *dest, const unsigned char *src, int len); void b64_decode_mio (char *dest, char *src); #endif /* BASE64_H */ Index: StdAfx.h =================================================================== RCS file: /cvsroot/sashimi/ReAdW/StdAfx.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** StdAfx.h 14 Jul 2006 14:59:44 -0000 1.5 --- StdAfx.h 29 Sep 2006 17:32:07 -0000 1.6 *************** *** 1,2 **** --- 1,4 ---- + // -*- mode: c++ -*- + // stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but *************** *** 30,33 **** --- 32,37 ---- #include <string> + + #include "zlib.h" --- base64.cpp DELETED --- Index: xrawfile2.cpp =================================================================== RCS file: /cvsroot/sashimi/ReAdW/xrawfile2.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** xrawfile2.cpp 14 Dec 2004 22:25:40 -0000 1.4 --- xrawfile2.cpp 29 Sep 2006 17:32:07 -0000 1.5 *************** *** 1,2 **** --- 1,4 ---- + // -*- mode: c++ -*- + /*************************************************************************** ReAdW Index: StdAfx.cpp =================================================================== RCS file: /cvsroot/sashimi/ReAdW/StdAfx.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StdAfx.cpp 30 Aug 2004 19:11:15 -0000 1.2 --- StdAfx.cpp 29 Sep 2006 17:32:07 -0000 1.3 *************** *** 1,2 **** --- 1,4 ---- + // -*- mode: c++ -*- + // stdafx.cpp : source file that includes just the standard includes // Thermo2mzXML.pch will be the pre-compiled header Index: xml_out.cpp =================================================================== RCS file: /cvsroot/sashimi/ReAdW/xml_out.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** xml_out.cpp 20 Sep 2006 21:19:42 -0000 1.34 --- xml_out.cpp 29 Sep 2006 17:32:07 -0000 1.35 *************** *** 1,2 **** --- 1,4 ---- + // -*- mode: c++ -*- + /*************************************************************************** ReAdW *************** *** 192,196 **** } m_Csha1.Final(); ! m_Csha1.ReportHash( m_pReport, CSHA1::REPORT_HEX ); --- 194,198 ---- } m_Csha1.Final(); ! m_Csha1.ReportHash( m_pReport, SHA1::REPORT_HEX ); *************** *** 348,351 **** --- 350,385 ---- void XmlOut::m_prepareScan() { + /* + pull out 'filter' line + + extract ms level from filter line + + close previous scan if required + + extract polarity from filter line + + extract scan type (zoom, survey) from filter line + + get # peaks (numPackets / 2) + + if level > 1, get precursor Mz and Ce + + first use DLL call + otherwise, extract from filter line (presumably less accurate) + + try to get precursor charge state + + get precursor intensity + flip through prev scan, looking for +/- 0.05 expected mass + + get m/z pairs, intensity + + compress if requested + then convert to b64 + + otherwise, just convert to b64 + + */ + char lf = 0xA; *************** *** 356,359 **** --- 390,395 ---- /* Get the scan filter + + For example, "ITMS + c NSI Full ms [ 300.00-2000.00] */ m_bstrFilter = NULL; *************** *** 366,369 **** --- 402,408 ---- /* extract the msLevel + + The level is the character after the 'ms' in the filter string; + ' ' is a level 1/survey scan */ char* msLevel = strstr( szTemp , "ms" ); *************** *** 558,561 **** --- 597,603 ---- } + + // CE: RT of the survey scan from which the precursor was selected + // and then the CE VariantClear( &varValue ); *************** *** 564,571 **** if( m_xRawfile.GetTrailerExtraValueForScanNum(m_scanNum, "API Source CID Energy:" , &varValue ) ) { // First try to use the OCX ! if( varValue.vt == VT_R4 ) m_CE = varValue.fltVal; ! else if ( varValue.vt != VT_ERROR ) cerr << "Unexpected type when looking for CE\n"; } --- 606,617 ---- if( m_xRawfile.GetTrailerExtraValueForScanNum(m_scanNum, "API Source CID Energy:" , &varValue ) ) { // First try to use the OCX ! if( varValue.vt == VT_R4 ) { ! // VT_R4: OLE float type m_CE = varValue.fltVal; ! } ! // JMT: !!! missing R8 !!! ! else if ( varValue.vt != VT_ERROR ) { cerr << "Unexpected type when looking for CE\n"; + } } *************** *** 610,614 **** --- 656,671 ---- long scanNum = m_scanNum; + + + + + /** + find the precursor mass/charge and intensity info + */ if( m_numPakets != 0 ) { + + // jmt: the goal is to get the parent scan's info: I don't know if this + // is sequentially the previous scan number, or the scan's + // parent, somehow wrapped in this scan? m_xRawfile.GetPrevMassListFromScanNum(&scanNum, szFilter, // filter *************** *** 622,634 **** &nArraySize); // arraySize if( nArraySize ) { // Get a pointer to the SafeArray SAFEARRAY FAR* psa = varMassList.parray; - DataPeak* pDataPeaks = NULL; SafeArrayAccessData( psa, (void**)(&pDataPeaks) ); m_precursorIntensity = 0; // Find most intense peak around precursorMz for( long j=0; j<nArraySize; j++ ) { double dMass = pDataPeaks[j].dMass; --- 679,699 ---- &nArraySize); // arraySize + // nArraySize: (presuming) number of mass/intensity pairs for this scan + // if empty, no precursor scan if( nArraySize ) { + // Get a pointer to the SafeArray SAFEARRAY FAR* psa = varMassList.parray; DataPeak* pDataPeaks = NULL; + // use our pDataPeaks array to access the SafeArray data. SafeArrayAccessData( psa, (void**)(&pDataPeaks) ); m_precursorIntensity = 0; + // Find most intense peak around precursorMz + /* + the goal is to search the precursor's scan info to get the + m/z and intensity + */ for( long j=0; j<nArraySize; j++ ) { double dMass = pDataPeaks[j].dMass; *************** *** 641,645 **** } } ! } if( dMass - m_precursorMz > 0.05 ) { break; --- 706,710 ---- } } ! } if( dMass - m_precursorMz > 0.05 ) { break; *************** *** 651,655 **** ! // jmt: check this? VariantClear( &varMassList ); // Delete all memory associated with the variant and --- 716,720 ---- ! VariantClear( &varMassList ); // Delete all memory associated with the variant and *************** *** 734,739 **** } // We add 5 bytes for the the trailing == and the /0 ! m_pEncoded = (char *) new char [( (((2 * nArraySize) * sizeof(uint32_t) + (int)ceil(( nArraySize * 2 * sizeof(uint32_t)) * 0.1) + 12) / 3) * 4 + 5)]; //m_pEncoded = (char *) new char [( (((2 * nArraySize) * sizeof(float) + ceil(( nArraySize * 2 * sizeof(float)) * 0.1) + 12) / 3) * 4 + 5)]; //m_pEncodedPrevScan = (char *) new char [( (((2 * nArraySize) * sizeof(float)) / 3) * 4 + 5)]; --- 799,809 ---- } + + // we now allocate m_pEncoded after the network data is base64 + // converted and we know the size of the converted string + + // We add 5 bytes for the the trailing == and the /0 ! // m_pEncoded = (char *) new char [( (((2 * nArraySize) * sizeof(uint32_t) + (int)ceil(( nArraySize * 2 * sizeof(uint32_t)) * 0.1) + 12) / 3) * 4 + 5)]; //m_pEncoded = (char *) new char [( (((2 * nArraySize) * sizeof(float) + ceil(( nArraySize * 2 * sizeof(float)) * 0.1) + 12) / 3) * 4 + 5)]; //m_pEncodedPrevScan = (char *) new char [( (((2 * nArraySize) * sizeof(float)) / 3) * 4 + 5)]; *************** *** 851,863 **** // Using the vectors is a little more complicated and slow, // but the conversion does not work directly ! *dMass = (float) pDataPeaks[j].dMass; ! *dIntensity = (float) pDataPeaks[j].dIntensity; ! ! // Convert form host to network ! (unsigned int) ((unsigned int *)pDataNetwork)[n] = (unsigned int) htonl( *(unsigned int*) dMass ); ! n++; ! (unsigned int) ((unsigned int *)pDataNetwork)[n] = (unsigned int) htonl( *(unsigned int*) dIntensity ); ! n++; } } --- 921,977 ---- // Using the vectors is a little more complicated and slow, // but the conversion does not work directly + + // convert from double to float + float mz = (float) pDataPeaks[j].dMass; + float intensity = (float) pDataPeaks[j].dIntensity; + + // get the 4 bytes that represent a float: + // get the addr of the float, treat it as a uint32 ptr, and dereference + uint32_t mzBytes = (*(uint32_t *)(&mz) ); + + // pretend that peakDataNework stores 4-byte unsigned ints, rather + // than 4-byte floats, for the sake of the conversion + ( (uint32_t *) pDataNetwork)[n] = htonl(mzBytes); + //printf("%f, %8.8X, %8.8X; ", mz, mzBytes, ( (uint32_t *) pDataNetwork)[n] ); + n++; + + + // Convert from host to network + //(unsigned int) ((unsigned int *)pDataNetwork)[n] = (unsigned int) htonl( *(unsigned int*) dMass ); + + + //n++; + + // convert from double to float + + //float intensity = (float) pDataPeaks[j].dIntensity; + + // get the 4 bytes that represent a float: + // get the addr of the float, treat it as a uint32 ptr, and dereference + uint32_t intensityBytes = (*(uint32_t *)(&intensity) ); + + // pretend that peakDataNework stores 4-byte unsigned ints, rather + // than 4-byte floats, for the sake of the conversion + ( (uint32_t *) pDataNetwork)[n] = htonl(intensityBytes); + //printf("%f, %8.8X, %8.8X; ", intensity, intensityBytes, ( (uint32_t *) pDataNetwork)[n] ); + n++; + + + // Convert from host to network + //(unsigned int) ((unsigned int *)pDataNetwork)[n] = (unsigned int) htonl( *(unsigned int*) dMass ); + + + + // sanity check + uint32_t mb2; + uint32_t ib2; + mb2 = ntohl(( (uint32_t *) pDataNetwork)[n-2]); + ib2 = ntohl(( (uint32_t *) pDataNetwork)[n-1]); + //printf("%f, %f\n\n", (*(float*)(&mb2)), (*(float*)(&ib2)) ); + ! //(unsigned int) ((unsigned int *)pDataNetwork)[n] = (unsigned int) htonl( *(unsigned int*) dIntensity ); ! //printf("%f, %8.8X, %8.8X\n", *dIntensity, *(unsigned int *)dIntensity, (unsigned int) ((unsigned int *)pDataNetwork)[n]); ! //n++; } } *************** *** 899,915 **** m_compressedLen = comprLen; ! int encodedLength = b64_encode( m_pEncoded, (const unsigned char *) compr, ! comprLen); ! ! m_pEncoded[encodedLength] = '\0'; free( compr ); } ! else { ! // no zlib compression; // do base64 encoding directly ! int encodedLength = b64_encode( m_pEncoded, (const unsigned char *) pDataNetwork, ! n * sizeof(float) ); // This one is for m/z increments peaks element ! m_pEncoded[encodedLength] = '\0'; } --- 1013,1038 ---- m_compressedLen = comprLen; ! Base64 base64Encoder; ! int encodedLength = base64Encoder.b64_encode( (const unsigned char *) compr, ! comprLen); ! // copy encoded bytes to m_pEncoded ! unsigned char* encodedByteArray = base64Encoder.getOutputBuffer(); ! for (int bc=0; bc<=encodedLength; bc++) { // <= to get the \0 ! m_pEncoded[bc] = encodedByteArray[bc]; ! } ! // this is now done in Base64::b64_encode: ! // m_pEncoded[encodedLength] = '\0'; ! base64Encoder.freeOutputBuffer(); free( compr ); } ! else { // no zlib compression; // do base64 encoding directly ! Base64 base64Encoder; ! int encodedLength = base64Encoder.b64_encode( (const unsigned char *) pDataNetwork, ! (nArraySize*2) * sizeof(float) ); // This one is for m/z increments peaks element ! m_pEncoded = new char[strlen((const char*)base64Encoder.getOutputBuffer()) + 1]; // +1 for \0 ! strcpy(m_pEncoded, (const char*)base64Encoder.getOutputBuffer()); ! base64Encoder.freeOutputBuffer(); } *************** *** 1029,1033 **** << " peaksCount=\"" << m_numPakets/2 << "\"" << lf << " polarity=\"" << m_polarity << "\"" << lf ! << " scanType=\"" << m_scanType << "\"" << lf << " retentionTime=\"PT" << m_RT*60 << "S\"" << lf; if( m_msLevel > 1 ) { --- 1152,1156 ---- << " peaksCount=\"" << m_numPakets/2 << "\"" << lf << " polarity=\"" << m_polarity << "\"" << lf ! //<< " scanType=\"" << m_scanType << "\"" << lf << " retentionTime=\"PT" << m_RT*60 << "S\"" << lf; if( m_msLevel > 1 ) { *************** *** 1051,1073 **** m_fout << " <peaks precision=\"32\"" << lf ! << " byteOrder=\"network\"" << lf; if( m_isRulers ) { ! m_fout << " contentType=\"m/z ruler\"" << lf; } ! else { ! m_fout << " contentType=\"m/z-int\"" << lf; } if( m_doCompression ) { ! m_fout << " compressionType=\"zlib\"" << lf << " compressedLen=\"" << m_compressedLen; } ! ! m_fout << "\">" << m_pEncoded << "</peaks>" << lf; // We don't close the scan element untill we are sure if the next ! // scan will be dependent on this one or not We save the params we // are going to need to see if the next scan element will be a // children of the current one --- 1174,1201 ---- m_fout << " <peaks precision=\"32\"" << lf ! << " byteOrder=\"network\""; if( m_isRulers ) { ! m_fout << lf << " contentType=\"m/z ruler\"" ; } ! else { ! // JMT TEMP TESTING ! m_fout << lf << " pairOrder=\"m/z-int\""; ! // JMT ! ! //m_fout << lf << " contentType=\"m/z-int\""; } if( m_doCompression ) { ! m_fout << lf << " compressionType=\"zlib\"" << lf << " compressedLen=\"" << m_compressedLen; } ! ! m_fout << ">"; ! m_fout << m_pEncoded << "</peaks>" << lf; // We don't close the scan element untill we are sure if the next ! // scan will be dependent on this one or not. We save the params we // are going to need to see if the next scan element will be a // children of the current one *************** *** 1164,1168 **** } m_Csha1.Final(); ! m_Csha1.ReportHash( m_pReport, CSHA1::REPORT_HEX ); m_fout << m_pReport << "</sha1>" << lf; --- 1292,1296 ---- } m_Csha1.Final(); ! m_Csha1.ReportHash( m_pReport, SHA1::REPORT_HEX ); m_fout << m_pReport << "</sha1>" << lf; Index: xml_out.h =================================================================== RCS file: /cvsroot/sashimi/ReAdW/xml_out.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** xml_out.h 20 Sep 2006 18:43:26 -0000 1.14 --- xml_out.h 29 Sep 2006 17:32:07 -0000 1.15 *************** *** 1,2 **** --- 1,4 ---- + // -*- mode: c++ -*- + /*************************************************************************** ReAdW *************** *** 32,37 **** #include "xrawfile2.h" ! #include "sha1.h" ! #include "base64.h" #define LITTLE_ENDIAN --- 34,39 ---- #include "xrawfile2.h" ! #include "SHA1.h" ! #include "Base64.h" #define LITTLE_ENDIAN *************** *** 132,139 **** // variables IXRawfile m_xRawfile; // Create an instance fo the COleDispatchDriver object ! __int64* m_index; char* m_xmlName; ! BOOL m_doCompression; ! BOOL m_doRulers; BOOL m_doCentroid; int m_fieldCorrection; --- 134,141 ---- // variables IXRawfile m_xRawfile; // Create an instance fo the COleDispatchDriver object ! __int64* m_index; char* m_xmlName; ! BOOL m_doCompression; ! BOOL m_doRulers; BOOL m_doCentroid; int m_fieldCorrection; *************** *** 144,150 **** long m_firstScan; long m_lastScan; ! double m_startTime; ! double m_endTime; ! CSHA1 m_Csha1; char m_pReport[1024]; // sha1 hash BSTR m_bstrInstModel; --- 146,152 ---- long m_firstScan; long m_lastScan; ! double m_startTime; ! double m_endTime; ! SHA1 m_Csha1; char m_pReport[1024]; // sha1 hash BSTR m_bstrInstModel; *************** *** 152,157 **** // Scan information ! bool m_isRulers; ! int m_compressedLen; long m_scanNum; BSTR m_bstrFilter; --- 154,159 ---- // Scan information ! bool m_isRulers; ! int m_compressedLen; long m_scanNum; BSTR m_bstrFilter; *************** *** 160,180 **** char* m_scanType; long m_numPakets; ! double m_RT; ! double m_lowMass; ! double m_highMass ; ! double m_TIC; ! double m_basePeakMass; ! double m_basePeakIntensity; long m_channel; long m_uniformTime; ! double m_frequency; ! double m_CE; // RT of the survey scan from which the precursor was selected ! double m_precursorIntensity; ! double m_precursorMz; ! int m_precursorCharge; ! char *m_pEncoded , *m_pEncodedPrevScan; std::ofstream m_fout; ! int m_idxFout; static int M_accurateMasses; --- 162,182 ---- char* m_scanType; long m_numPakets; ! double m_RT; ! double m_lowMass; ! double m_highMass ; ! double m_TIC; ! double m_basePeakMass; ! double m_basePeakIntensity; long m_channel; long m_uniformTime; ! double m_frequency; ! double m_CE; // RT of the survey scan from which the precursor was selected ! double m_precursorIntensity; ! double m_precursorMz; ! int m_precursorCharge; ! char *m_pEncoded , *m_pEncodedPrevScan; std::ofstream m_fout; ! int m_idxFout; static int M_accurateMasses; --- base64.h DELETED --- Index: resource.h =================================================================== RCS file: /cvsroot/sashimi/ReAdW/resource.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** resource.h 30 Aug 2004 19:11:15 -0000 1.3 --- resource.h 29 Sep 2006 17:32:07 -0000 1.4 *************** *** 1,2 **** --- 1,4 ---- + // -*- mode: c++ -*- + //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. --- NEW FILE: SHA1.cpp --- /*--------------------------------------------------------------------------- ## File: ## @@(#) sha1.cpp ## Author: ## Dominik Reichl <Dom...@ti...> ## - Modified by Patrick Pedrioli ## ## Description: ## A generic sha1 hash. ## ##***************************************************************************** ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU Library or "Lesser" General Public ## License (LGPL) as published by the Free Software Foundation; ## either version 2 of the License, or (at your option) any later ## version. ## ##***************************************************************************** ## ## Changes ## ## $Log: SHA1.cpp,v $ ## Revision 1.1 2006/09/29 17:32:07 spacepod ## renamed base64 to Base64, sha1 to SHA1 in prep for unifying shared code amnong converters ## ## Revision 1.2 2004/08/30 19:11:15 brendanx ## Fix line endings. ## ## Revision 1.1.1.1 2004/03/28 21:47:05 ppatrick ## Initial import. ## ## ## ##---------------------------------------------------------------------------*/ /* 100% free public domain implementation of the SHA-1 algorithm by Dominik Reichl <Dom...@ti...> === Test Vectors (from FIPS PUB 180-1) === "abc" A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 A million repetitions of "a" 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F */ #include "stdafx.h" #include "sha1.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif CSHA1::CSHA1() { Reset(); } CSHA1::~CSHA1() { Reset(); } void CSHA1::Reset() { // SHA1 initialization constants m_state[0] = 0x67452301; m_state[1] = 0xEFCDAB89; m_state[2] = 0x98BADCFE; m_state[3] = 0x10325476; m_state[4] = 0xC3D2E1F0; m_count[0] = 0; m_count[1] = 0; } void CSHA1::Transform(unsigned long state[5], unsigned char buffer[64]) { unsigned long a = 0, b = 0, c = 0, d = 0, e = 0; SHA1_WORKSPACE_BLOCK* block; static unsigned char workspace[64]; block = (SHA1_WORKSPACE_BLOCK *)workspace; memcpy(block, buffer, 64); // Copy state[] to working vars a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; // 4 rounds of 20 operations each. Loop unrolled. R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); // Add the working vars back into state[] state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; // Wipe variables a = 0; b = 0; c = 0; d = 0; e = 0; } // Use this function to hash in binary data and strings void CSHA1::Update(unsigned char* data, unsigned int len) { unsigned long i = 0, j = 0; j = (m_count[0] >> 3) & 63; if((m_count[0] += len << 3) < (len << 3)) m_count[1]++; m_count[1] += (len >> 29); if((j + len) > 63) { memcpy(&m_buffer[j], data, (i = 64 - j)); Transform(m_state, m_buffer); for (; i+63 < len; i += 64) { Transform(m_state, &data[i]); } j = 0; } else i = 0; memcpy(&m_buffer[j], &data[i], len - i); } // Hash in file contents bool CSHA1::HashFile(char *szFileName) { unsigned long ulFileSize = 0, ulRest = 0, ulBlocks = 0; unsigned long i = 0; unsigned char uData[MAX_FILE_READ_BUFFER]; FILE *fIn = NULL; if((fIn = fopen(szFileName, "rb")) == NULL) return(false); fseek(fIn, 0, SEEK_END); ulFileSize = ftell(fIn); fseek(fIn, 0, SEEK_SET); ulRest = ulFileSize % MAX_FILE_READ_BUFFER; ulBlocks = ulFileSize / MAX_FILE_READ_BUFFER; for(i = 0; i < ulBlocks; i++) { fread(uData, 1, MAX_FILE_READ_BUFFER, fIn); Update(uData, MAX_FILE_READ_BUFFER); } if(ulRest != 0) { fread(uData, 1, ulRest, fIn); Update(uData, ulRest); } fclose(fIn); fIn = NULL; return(true); } void CSHA1::Final() { unsigned long i = 0, j = 0; unsigned char finalcount[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; for (i = 0; i < 8; i++) finalcount[i] = (unsigned char)((m_count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8) ) & 255); // Endian independent Update((unsigned char *)"\200", 1); while ((m_count[0] & 504) != 448) Update((unsigned char *)"\0", 1); Update(finalcount, 8); // Cause a SHA1Transform() for (i = 0; i < 20; i++) { m_digest[i] = (unsigned char)((m_state[i >> 2] >> ((3 - (i & 3)) * 8) ) & 255); } // Wipe variables for security reasons i = 0; j = 0; memset(m_buffer, 0, 64); memset(m_state, 0, 20); memset(m_count, 0, 8); memset(finalcount, 0, 8); Transform(m_state, m_buffer); } // Get the final hash as a pre-formatted string void CSHA1::ReportHash(char *szReport, unsigned char uReportType) { unsigned char i = 0; char szTemp[4]; if(uReportType == REPORT_HEX) { for(i = 0; i < 20; i++) { sprintf(szTemp, "%02x", m_digest[i]); strcat(szReport, szTemp); } } else if(uReportType == REPORT_DIGIT) { sprintf(szTemp, "%u", m_digest[0]); strcat(szReport, szTemp); for(i = 1; i < 20; i++) { sprintf(szTemp, " %u", m_digest[i]); strcat(szReport, szTemp); } } else strcpy(szReport, "Error: Unknown report type!"); } // Get the raw message digest void CSHA1::GetHash(unsigned char *uDest) { memcpy(uDest, m_digest, 20); } --- sha1.h DELETED --- |