mirror of
https://github.com/chris2511/xca.git
synced 2026-09-12 19:51:05 +05:00
80 lines
1.7 KiB
C++
80 lines
1.7 KiB
C++
#ifndef _XCA_DB_H_
|
|
#define _XCA_DB_H_
|
|
|
|
#include <stdint.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <Qt/qstring.h>
|
|
|
|
#define XCA_MAGIC 0xcadb1969
|
|
#define NAMELEN 80
|
|
#define FNAMLEN 256
|
|
#define OFF_EOF ((off_t)-1)
|
|
|
|
#define DBFLAG_DELETED 1
|
|
#define DBFLAG_OUTDATED 2
|
|
|
|
enum pki_type {
|
|
none,
|
|
async_key,
|
|
x509_req,
|
|
x509,
|
|
crl,
|
|
tmpl,
|
|
setting,
|
|
};
|
|
|
|
typedef struct db_header_t {
|
|
uint32_t magic;
|
|
uint32_t len; /* length of this entry */
|
|
uint16_t headver;
|
|
uint16_t type;
|
|
uint16_t version;
|
|
uint16_t flags;
|
|
char name[NAMELEN]; /* name of the entry */
|
|
};
|
|
|
|
class db
|
|
{
|
|
private:
|
|
int fd;
|
|
QString name;
|
|
QString errstr;
|
|
int dberrno;
|
|
db_header_t head;
|
|
off_t head_offset;
|
|
|
|
void init_header(db_header_t *db, int ver, int len, enum pki_type type,
|
|
const char *name);
|
|
bool verify_magic(void);
|
|
void convert_header(db_header_t *h);
|
|
|
|
public:
|
|
db(QString, int mode = S_IRUSR | S_IWUSR);
|
|
~db();
|
|
void first(void);
|
|
int find(enum pki_type type, const char *name);
|
|
int next(void);
|
|
QString uniq_name(QString s, enum pki_type type);
|
|
int rename(enum pki_type type, const char *name, const char *n);
|
|
int add(const unsigned char *p, int len, int ver, enum pki_type type,
|
|
const char *name);
|
|
int set(const unsigned char *p, int len, int ver, enum pki_type type,
|
|
const char *name);
|
|
unsigned char *load(db_header_t *u_header);
|
|
int erase(void);
|
|
int shrink(int flags);
|
|
|
|
static int intToData(unsigned char **p, uint32_t val);
|
|
static uint32_t intFromData(const unsigned char **p);
|
|
static int boolToData(unsigned char **p, bool val);
|
|
static bool boolFromData(const unsigned char **p);
|
|
static int stringToData(unsigned char **p, const QString val);
|
|
static QString stringFromData(const unsigned char **p);
|
|
};
|
|
|
|
#endif
|
|
|