30 typedef struct x509_st X509;
31 typedef struct evp_pkey_st EVP_PKEY;
46 BLOCKING
bool open_read(
const Filename &multifile_name,
const std::streampos &offset = 0);
47 BLOCKING
bool open_read(
IStreamWrapper *multifile_stream,
bool owns_pointer =
false,
const std::streampos &offset = 0);
48 BLOCKING
bool open_write(
const Filename &multifile_name);
49 BLOCKING
bool open_write(std::ostream *multifile_stream,
bool owns_pointer =
false);
50 BLOCKING
bool open_read_write(
const Filename &multifile_name);
51 BLOCKING
bool open_read_write(std::iostream *multifile_stream,
bool owns_pointer =
false);
52 BLOCKING
void close();
54 INLINE
const Filename &get_multifile_name()
const;
55 INLINE
void set_multifile_name(
const Filename &multifile_name);
57 INLINE
bool is_read_valid()
const;
58 INLINE
bool is_write_valid()
const;
59 INLINE
bool needs_repack()
const;
61 INLINE time_t get_timestamp()
const;
63 INLINE
void set_record_timestamp(
bool record_timestamp);
64 INLINE
bool get_record_timestamp()
const;
66 void set_scale_factor(
size_t scale_factor);
67 INLINE
size_t get_scale_factor()
const;
69 INLINE
void set_encryption_flag(
bool flag);
70 INLINE
bool get_encryption_flag()
const;
71 INLINE
void set_encryption_password(
const std::string &encryption_password);
72 INLINE
const std::string &get_encryption_password()
const;
74 INLINE
void set_encryption_algorithm(
const std::string &encryption_algorithm);
75 INLINE
const std::string &get_encryption_algorithm()
const;
76 INLINE
void set_encryption_key_length(
int encryption_key_length);
77 INLINE
int get_encryption_key_length()
const;
78 INLINE
void set_encryption_iteration_count(
int encryption_iteration_count);
79 INLINE
int get_encryption_iteration_count()
const;
81 std::string add_subfile(
const std::string &subfile_name,
const Filename &filename,
82 int compression_level);
83 std::string add_subfile(
const std::string &subfile_name, std::istream *subfile_data,
84 int compression_level);
85 std::string update_subfile(
const std::string &subfile_name,
const Filename &filename,
86 int compression_level);
89 bool add_signature(
const Filename &certificate,
92 const std::string &password =
"");
93 bool add_signature(
const Filename &composite,
94 const std::string &password =
"");
96 int get_num_signatures()
const;
97 std::string get_signature_subject_name(
int n)
const;
98 std::string get_signature_friendly_name(
int n)
const;
99 std::string get_signature_public_key(
int n)
const;
100 void print_signature_certificate(
int n, std::ostream &out)
const;
101 void write_signature_certificate(
int n, std::ostream &out)
const;
103 int validate_signature_certificate(
int n)
const;
104 #endif // HAVE_OPENSSL
106 BLOCKING
bool flush();
107 BLOCKING
bool repack();
109 int get_num_subfiles()
const;
110 int find_subfile(
const std::string &subfile_name)
const;
111 bool has_directory(
const std::string &subfile_name)
const;
112 bool scan_directory(vector_string &contents,
113 const std::string &subfile_name)
const;
114 void remove_subfile(
int index);
115 INLINE
bool remove_subfile(
const std::string &subfile_name);
116 const std::string &get_subfile_name(
int index)
const;
117 MAKE_SEQ(get_subfile_names, get_num_subfiles, get_subfile_name);
118 size_t get_subfile_length(
int index)
const;
119 time_t get_subfile_timestamp(
int index)
const;
120 bool is_subfile_compressed(
int index)
const;
121 bool is_subfile_encrypted(
int index)
const;
122 bool is_subfile_text(
int index)
const;
124 std::streampos get_index_end()
const;
125 std::streampos get_subfile_internal_start(
int index)
const;
126 size_t get_subfile_internal_length(
int index)
const;
128 BLOCKING INLINE vector_uchar read_subfile(
int index);
129 BLOCKING std::istream *open_read_subfile(
int index);
130 BLOCKING
static void close_read_subfile(std::istream *stream);
131 BLOCKING
bool extract_subfile(
int index,
const Filename &filename);
132 BLOCKING
bool extract_subfile_to(
int index, std::ostream &out);
133 BLOCKING
bool compare_subfile(
int index,
const Filename &filename);
135 void output(std::ostream &out)
const;
136 void ls(std::ostream &out = std::cout)
const;
138 static INLINE std::string get_magic_number();
139 MAKE_PROPERTY(magic_number, get_magic_number);
141 void set_header_prefix(
const std::string &header_prefix);
142 INLINE
const std::string &get_header_prefix()
const;
148 INLINE CertRecord(X509 *cert);
149 INLINE CertRecord(
const CertRecord ©);
150 INLINE ~CertRecord();
151 INLINE
void operator = (
const CertRecord &other);
156 bool add_signature(
const CertChain &chain, EVP_PKEY *pkey);
158 const CertChain &get_signature(
int n)
const;
159 #endif // HAVE_OPENSSL
161 bool read_subfile(
int index, std::string &result);
162 bool read_subfile(
int index, vector_uchar &result);
167 SF_index_invalid = 0x0002,
168 SF_data_invalid = 0x0004,
169 SF_compressed = 0x0008,
170 SF_encrypted = 0x0010,
171 SF_signature = 0x0020,
178 INLINE
bool operator < (
const Subfile &other)
const;
179 std::streampos read_index(std::istream &read, std::streampos fpos,
181 std::streampos write_index(std::ostream &write, std::streampos fpos,
183 std::streampos write_data(std::ostream &write, std::istream *read, std::streampos fpos,
185 void rewrite_index_data_start(std::ostream &write,
Multifile *multifile);
186 void rewrite_index_flags(std::ostream &write);
187 INLINE
bool is_deleted()
const;
188 INLINE
bool is_index_invalid()
const;
189 INLINE
bool is_data_invalid()
const;
190 INLINE
bool is_cert_special()
const;
191 INLINE std::streampos get_last_byte_pos()
const;
194 std::streampos _index_start;
195 size_t _index_length;
196 std::streampos _data_start;
198 size_t _uncompressed_length;
200 std::istream *_source;
203 int _compression_level;
209 INLINE std::streampos word_to_streampos(
size_t word)
const;
210 INLINE
size_t streampos_to_word(std::streampos fpos)
const;
211 INLINE std::streampos normalize_streampos(std::streampos fpos)
const;
212 std::streampos pad_to_streampos(std::streampos fpos);
214 void add_new_subfile(Subfile *subfile,
int compression_level);
215 std::istream *open_read_subfile(Subfile *subfile);
216 std::string standardize_subfile_name(
const std::string &subfile_name)
const;
218 void clear_subfiles();
222 void check_signatures();
224 static INLINE
char tohex(
unsigned int nibble);
229 PendingSubfiles _new_subfiles;
230 PendingSubfiles _removed_subfiles;
231 PendingSubfiles _cert_special;
235 Certificates _signatures;
238 std::streampos _offset;
240 std::ostream *_write;
242 std::streampos _next_index;
243 std::streampos _last_index;
244 std::streampos _last_data_byte;
248 bool _timestamp_dirty;
249 bool _record_timestamp;
250 size_t _scale_factor;
251 size_t _new_scale_factor;
253 bool _encryption_flag;
254 std::string _encryption_password;
255 std::string _encryption_algorithm;
256 int _encryption_key_length;
257 int _encryption_iteration_count;
259 pifstream _read_file;
261 pofstream _write_file;
262 pfstream _read_write_file;
265 std::string _header_prefix;
270 static const char _header[];
271 static const size_t _header_size;
272 static const int _current_major_ver;
273 static const int _current_minor_ver;
275 static const char _encrypt_header[];
276 static const size_t _encrypt_header_size;
278 friend class Subfile;