-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTOC.h
82 lines (66 loc) · 2.18 KB
/
TOC.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright Pavel Kraynyukhov 2018.
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* $Id: lar:TOC.h Jun 14, 2018 11:35:54 AM $
*
* EMail: [email protected]
*/
#ifndef __TOC_H__
#define __TOC_H__
#include <vector>
#include <memory>
#include <experimental/filesystem>
#include <wolfCryptHaCW.h>
#include <bz2Compression.h>
#include <fstream>
#include <utils.h>
namespace fs = std::experimental::filesystem::v1;
namespace lar{
struct TOCItem
{
size_t fsize;
size_t compressedSize;
uint32_t path_size;
fs::perms permissions;
wolf::SHA256SUM hashsum;
fs::path relativePath;
explicit TOCItem(const fs::path& _path)
: fsize(fs::file_size(_path)),
compressedSize(0),
path_size(_path.u8string().length()),
permissions(fs::status(_path).permissions()),
hashsum{0,},
relativePath(_path)
{
}
explicit TOCItem(const std::vector<uint8_t>& bytes, const size_t offset=0)
{
if(bytes.size() < (56+offset))
throw std::system_error(EINVAL,std::system_category(),"TOCItem(const std::vector<uint8_t>&): provided vector is too small");
memcpy((void*)(this),bytes.data()+offset,56);
if(bytes.size()< (offset+56+this->path_size))
throw std::system_error(EINVAL,std::system_category(),"TOCItem(const std::vector<uint8_t>&): provided vector is too small");
std::string tmp(path_size,'\0');
memcpy((void*)(tmp.data()),bytes.data()+56+offset,path_size);
relativePath=tmp;
}
TOCItem()=delete;
TOCItem(const TOCItem&)=delete;
TOCItem(TOCItem&)=delete;
void calcHashSum(const std::vector<uint8_t>& content)
{
wolf::sha256sum(content,hashsum);
}
void dump(std::vector<uint8_t>& out)
{
out.resize(56+relativePath.u8string().size());
memcpy(out.data(),this,56);
memcpy(out.data()+56,relativePath.u8string().data(),relativePath.u8string().size());
}
};
}
#endif /* __TOC_H__ */