File: utils.h

package info (click to toggle)
afflib 3.5.12-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,168 kB
  • ctags: 4,723
  • sloc: cpp: 21,800; ansic: 14,696; sh: 9,697; makefile: 531; python: 95
file content (80 lines) | stat: -rw-r--r-- 1,939 bytes parent folder | download
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
/*
 * utils.h:
 * Some useful utilities for building AFF-aware programs.
 */

#ifndef AFF_UTILS_H
#define AFF_UTILS_H

#ifdef __cplusplus
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <iostream>

#ifdef HAVE_OPENSSL_PEM_H
#include <openssl/x509.h>
#include <openssl/pem.h>
#else
typedef void X509;
typedef void EVP_PKEY;
typedef void BIO;
#define BIO_free free
#endif

namespace aff {

    std::string command_line(int argc,char **argv);
    bool ends_with(const char *buf,const char *with);
    bool ends_with(std::string str,std::string ending);

    /* Structure for hash map */
    struct less_c_str
    {
	inline bool operator()( const char* x, const char* y) const
	{     return ( strcmp( x,y ) < 0 );
	}
    };

    struct md5blob {
	unsigned char buf[16];
    };

    typedef std::map< const char*, struct md5blob, less_c_str > hashMapT;

    /* The seginfo stores information about a segment other than its data*/
    class seginfo {
    public:
	seginfo(std::string n1,size_t l1,u_int a1): name(n1),len(l1),arg(a1) {}
	std::string name;
	size_t len;
	u_long arg;
	/** pagenumber returns <0 for invalid pages, >= for a page */
	int64_t pagenumber() const {return af_segname_page_number(name.c_str());}
	bool inline operator==(const class seginfo &b) const {
	    return name == b.name;
	}
    };
    
    /* the seglist provides AFF internal functions and tools an easy way to get
     * a list of all of the segments in the currently open AFF file.
     * Use the seglist(af) constructor to populate it with all the segments
     * when you create. Each element is populated with the name, length and arg.
     */
    class seglist : public std::vector<seginfo> {
    public:
	bool contains(std::string segname);
	bool has_signed_segments();
	int get_seglist(AFFILE *af);
	seglist(){}
	seglist(AFFILE *af){
	    get_seglist(af);
	}
    };
}
#endif

#endif