FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
checksum.h
1 /************************************************************
2  checksum.h - Checksum computation header file
3 
4  Copyright (C) 2007-2011 Hewlett-Packard Development Company, L.P.
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  version 2 as published by the Free Software Foundation.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  ************************************************************/
19 #ifndef CHECKSUM_H
20 #define CHECKSUM_H
21 
22 #include <stdint.h> /* for uint8_t */
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <sys/mman.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <fcntl.h>
32 #include <dirent.h>
33 
34 #include "libfossology.h"
35 
39 struct Cksum
40 {
41  uint8_t MD5digest[16];
42  uint8_t SHA1digest[20];
43  uint64_t DataLen;
44 };
45 typedef struct Cksum Cksum;
46 
50 struct CksumFile
51 {
52  int FileHandle;
53  unsigned char *Mmap;
54  uint64_t MmapSize;
55  uint64_t MmapOffset;
56 };
57 typedef struct CksumFile CksumFile;
58 
59 CksumFile * SumOpenFile (char *Fname);
60 void SumCloseFile (CksumFile *CF);
61 int CountDigits (uint64_t Num);
62 Cksum * SumComputeFile (FILE *Fin);
64 char * SumToString (Cksum *Sum);
65 int calc_sha256sum(char* filename, char* dst);
66 #endif
CksumFile * SumOpenFile(char *Fname)
Open and mmap a file.
Definition: checksum.c:38
Cksum * SumComputeFile(FILE *Fin)
Compute the checksum, allocate and return a string containing the sum value.
Definition: checksum.c:127
uint64_t MmapOffset
Index into mmap.
Definition: checksum.h:55
uint8_t SHA1digest[20]
SHA1 digest of the file.
Definition: checksum.h:42
int CountDigits(uint64_t Num)
Count how many digits are in a number.
Definition: checksum.c:109
uint8_t MD5digest[16]
MD5 digest of the file.
Definition: checksum.h:41
The main FOSSology C library.
unsigned char * Mmap
Mmap of the file.
Definition: checksum.h:53
Store check sum of a file.
Definition: checksum.h:39
uint64_t DataLen
Size of the file.
Definition: checksum.h:43
char * SumToString(Cksum *Sum)
Return string representing a Cksum. NOTE: The calling function must free() the string! ...
Definition: checksum.c:249
uint64_t MmapSize
Size of mmap.
Definition: checksum.h:54
void SumCloseFile(CksumFile *CF)
Close a file that was opened with SumOpenFile()
Definition: checksum.c:95
Cksum * SumComputeBuff(CksumFile *CF)
Compute the checksum, allocate and return a Cksum containing the sum value.
Definition: checksum.c:194
int FileHandle
File handler for the file.
Definition: checksum.h:52
Store file handler and mmap of a file.
Definition: checksum.h:50