#ifndef LIBIDAV_PWDSTORE_H
#define LIBIDAV_PWDSTORE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <inttypes.h>
#include <cx/map.h>
#include <cx/buffer.h>
#include <cx/linked_list.h>
#include "crypto.h"
#ifdef __cplusplus
extern "C" {
#endif
#define PWDSTORE_MAX_LEN 4096
#define PWDS_HEADER_SIZE 24
typedef struct PwdStore PwdStore;
typedef struct PwdEntry PwdEntry;
typedef struct PwdIndexEntry PwdIndexEntry;
struct PwdStore {
CxMap *ids;
CxList *locations;
CxList *noloc;
CxMap *index;
CxBuffer *content;
DavKey *key;
char *unlock_cmd;
char *lock_cmd;
uint32_t encoffset;
uint8_t isdecrypted;
};
#define PWDS_MAGIC(p) (p)->content->space[
0]
#define PWDS_VERSION(p) (p)->content->space[
1]
#define PWDS_ENC(p) (p)->content->space[
2]
#define PWDS_PWFUNC(p) (p)->content->space[
3]
#define PWDS_MAGIC_CHAR 'P'
struct PwdEntry {
char *id;
char *user;
char *password;
};
struct PwdIndexEntry {
char *id;
CxList *locations;
};
PwdStore* pwdstore_open(
const char *file);
PwdStore* pwdstore_new(
void);
PwdStore* pwdstore_clone(PwdStore *p);
int pwdstore_decrypt(PwdStore *p);
int pwdstore_setpassword(PwdStore *p,
const char *password);
void pwdstore_encsettings(PwdStore *p,
uint8_t enc,
uint8_t pwfunc);
void pwdstore_free_entry(PwdEntry *e);
void pwdstore_free(PwdStore* p);
int pwdstore_has_id(PwdStore *s,
const char *id);
PwdEntry* pwdstore_get(PwdStore *p,
const char *id);
void pwdstore_put(PwdStore *p,
const char *id,
const char *username,
const char *password);
void pwdstore_put_index(PwdStore *p,
char *id, CxList *locations);
void pwdstore_remove_entry(PwdStore *s,
const char *id);
int pwdstore_store(PwdStore *p,
const char *file);
int pwdstore_decrypt_secrets(PwdStore *secrets);
typedef char*(*pwdstore_pwinput_func)(
void *userdata);
void pwdstore_set_pwinput_func(pwdstore_pwinput_func func,
void *userdata);
char * pwdstore_default_pwinput(
char *prompt);
int pwdstore_getindex(PwdStore *s);
#ifdef __cplusplus
}
#endif
#endif