view include/pws.h @ 13:2bb1bbac1d0a default tip

Added tag version-1.0.0 for changeset 1926dfc9feb0
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Sun, 04 Aug 2019 21:37:56 +0200
parents 96a507a110c8
children
line wrap: on
line source

/*
 * Copyright (C) 2015 Guido Berhoerster <guido+libpws@berhoerster.name>
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef	PWS_H
#define	PWS_H

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include <stdint.h>
#include <sys/types.h>
#include <stdio.h>

#define	LIBPWS_VERSION_MAJOR	1
#define	LIBPWS_VERSION_MINOR	0
#define	LIBPWS_VERSION_MICRO	0

#define	PWS3_VERSION		0x030E

#define	PWS3_MAX_FIELD_SIZE	(16 * 1024)
#define	PWS3_MAX_PASSWORD_LEN	1023
#define	PWS3_UUID_SIZE		16

struct pws3_field;
struct pws3_record;
struct pws3_file;

enum pws_error_code {
	PWS_ERR_GENERIC_ERROR,
	PWS_ERR_NO_MEMORY,
	PWS_ERR_IO_ERROR,
	PWS_ERR_TRUNCATED_FILE,
	PWS_ERR_INVALID_CHECKSUM,
	PWS_ERR_INVALID_RECORD,
	PWS_ERR_INVALID_HEADER,
	PWS_ERR_UNSUPPORTED_VERSION
};

enum pws_data_type {
	PWS_DATA_TYPE_BYTES,
	PWS_DATA_TYPE_UUID,
	PWS_DATA_TYPE_TEXT,
	PWS_DATA_TYPE_TIME,
	PWS_DATA_TYPE_UINT8,
	PWS_DATA_TYPE_UINT16,
	PWS_DATA_TYPE_UINT32
};

enum pws3_header_field_type {
	PWS3_HEADER_FIELD_VERSION,			/* 0x00 */
	PWS3_HEADER_FIELD_UUID,				/* 0x01 */
	PWS3_HEADER_FIELD_NON_DEFAULT_PREFERENCES,	/* 0x02 */
	PWS3_HEADER_FIELD_TREE_DISPLAY_STATUS,		/* 0x03 */
	PWS3_HEADER_FIELD_SAVE_TIMESTAMP,		/* 0x04 */
	PWS3_HEADER_FIELD_SAVE_USER_HOST,		/* 0x05 */
	PWS3_HEADER_FIELD_SAVE_APPLICATION,		/* 0x06 */
	PWS3_HEADER_FIELD_SAVE_USER,			/* 0x07 */
	PWS3_HEADER_FIELD_SAVE_HOST,			/* 0x08 */
	PWS3_HEADER_FIELD_DATABASE_NAME,		/* 0x09 */
	PWS3_HEADER_FIELD_DATABASE_DESCRIPTION,		/* 0x0a */
	PWS3_HEADER_FIELD_DATABASE_FILTERS,		/* 0x0b */
	PWS3_HEADER_FIELD_RESERVED_1,			/* 0x0c */
	PWS3_HEADER_FIELD_RESERVED_2,			/* 0x0d */
	PWS3_HEADER_FIELD_RESERVED_3,			/* 0x0e */
	PWS3_HEADER_FIELD_RECENTLY_USED_ENTRIES,	/* 0x0f */
	PWS3_HEADER_FIELD_NAMED_PASSWORD_POLICIES,	/* 0x10 */
	PWS3_HEADER_FIELD_EMPTY_GROUPS,			/* 0x11 */
	PWS3_HEADER_FIELD_YUBICO,			/* 0x12 */
	PWS3_HEADER_FIELD_PASSWORD_TIMESTAMP,		/* 0x13 */
	PWS3_HEADER_FIELD_END = 0xff
};

enum pws3_record_field_type {
	PWS3_RECORD_FIELD_UUID = 0x01,
	PWS3_RECORD_FIELD_GROUP,			/* 0x02 */
	PWS3_RECORD_FIELD_TITLE,			/* 0x03 */
	PWS3_RECORD_FIELD_USERNAME,			/* 0x04 */
	PWS3_RECORD_FIELD_NOTES,			/* 0x05 */
	PWS3_RECORD_FIELD_PASSWORD,			/* 0x06 */
	PWS3_RECORD_FIELD_CREATION_TIME,		/* 0x07 */
	PWS3_RECORD_FIELD_PASSWORD_MODIFICATION_TIME,	/* 0x08 */
	PWS3_RECORD_FIELD_ACCESS_TIME,			/* 0x09 */
	PWS3_RECORD_FIELD_PASSWORD_EXPIRY_TIME,		/* 0x0a */
	PWS3_RECORD_FIELD_RESERVED_1,			/* 0x0b */
	PWS3_RECORD_FIELD_MODIFICATION_TIME,		/* 0x0c */
	PWS3_RECORD_FIELD_URL,				/* 0x0d */
	PWS3_RECORD_FIELD_AUTOTYPE,			/* 0x0e */
	PWS3_RECORD_FIELD_PASSWORD_HISTORY,		/* 0x0f */
	PWS3_RECORD_FIELD_PASSWORD_POLICY,		/* 0x10 */
	PWS3_RECORD_FIELD_PASSWORD_EXPIRY_INTERVAL,	/* 0x11 */
	PWS3_RECORD_FIELD_RUN_COMMAND,			/* 0x12 */
	PWS3_RECORD_FIELD_DOUBLE_CLICK_ACTION,		/* 0x13 */
	PWS3_RECORD_FIELD_EMAIL_ADDRESS,		/* 0x14 */
	PWS3_RECORD_FIELD_PROTECTED,			/* 0x15 */
	PWS3_RECORD_FIELD_ALLOWED_PASSWORD_SYMBOLS,	/* 0x16 */
	PWS3_RECORD_FIELD_SHIFT_DOUBLE_CLICK_ACTION,	/* 0x17 */
	PWS3_RECORD_FIELD_PASSWORD_POLICY_NAME,		/* 0x18 */
	PWS3_RECORD_FIELD_KEYBOARD_SHORTCUT,		/* 0x19 */
	PWS3_RECORD_FIELD_RESERVED_2,			/* 0x1a */
	PWS3_RECORD_FIELD_TWO_FACTOR_KEY,		/* 0x1b */
	PWS3_RECORD_FIELD_CREDIT_CARD_NUMBER,		/* 0x1c */
	PWS3_RECORD_FIELD_CREDIT_CARD_EXPIRATION,	/* 0x1d */
	PWS3_RECORD_FIELD_CREDIT_CARD_VERIFICATION_VALUE, /* 0x1e */
	PWS3_RECORD_FIELD_CREDIT_CARD_PIN,		/* 0x1f */
	PWS3_RECORD_FIELD_QR_CODE,			/* 0x20 */
	PWS3_RECORD_FIELD_TESTING_1,			/* 0xdf */
	PWS3_RECORD_FIELD_END = 0xff
};

int		pws_init(void);
void		pws_finalize(void);
void		pws_set_alloc_functions(void *(*)(size_t),
    void *(*)(void *, size_t), void (*)(void *, size_t), void *(*)(size_t),
    void *(*)(void *, size_t), void (*)(void *, size_t));
int		pws_generate_uuid(unsigned char [static PWS3_UUID_SIZE]);

struct pws3_field * pws3_field_create(int, uint8_t);
void		pws3_field_destroy(struct pws3_field *);
int		pws3_field_is_header(struct pws3_field *);
uint8_t		pws3_field_get_type(struct pws3_field *);
enum pws_data_type pws3_field_get_data_type(struct pws3_field *);
int		pws3_field_set_uuid(struct pws3_field *,
    const unsigned char [static PWS3_UUID_SIZE]);
int		pws3_field_set_text(struct pws3_field *, const char [static 1]);
int		pws3_field_set_time(struct pws3_field *, time_t);
int		pws3_field_set_uint8(struct pws3_field *, uint8_t);
int		pws3_field_set_uint16(struct pws3_field *, uint16_t);
int		pws3_field_set_uint32(struct pws3_field *, uint32_t);
int		pws3_field_set_bytes(struct pws3_field *,
    const unsigned char [static 1], size_t);
const unsigned char * pws3_field_get_uuid(struct pws3_field *);
const char *	pws3_field_get_text(struct pws3_field *);
time_t		pws3_field_get_time(struct pws3_field *);
uint8_t		pws3_field_get_uint8(struct pws3_field *);
uint16_t	pws3_field_get_uint16(struct pws3_field *);
uint32_t	pws3_field_get_uint32(struct pws3_field *);
void		pws3_field_get_bytes(struct pws3_field *,
    const unsigned char **, size_t *);

void		pws3_record_destroy(struct pws3_record *);
struct pws3_record * pws3_record_create(void);
void		pws3_record_set_field(struct pws3_record *,
    struct pws3_field *);
struct pws3_field * pws3_record_get_field(struct pws3_record *, uint8_t);
struct pws3_field * pws3_record_remove_field(struct pws3_record *, uint8_t);

void		pws3_file_destroy(struct pws3_file *);
struct pws3_file * pws3_file_create(void);
enum pws_error_code pws3_file_get_error_code(struct pws3_file *);
const char *	pws3_file_get_error_message(struct pws3_file *);
int		pws3_file_read_mem(struct pws3_file *, const char *,
    unsigned char *, size_t);
int		pws3_file_read_stream(struct pws3_file *, const char *, FILE *);
int		pws3_file_write_mem(struct pws3_file *, const char *, uint32_t,
    unsigned char **, size_t *);
int		pws3_file_write_stream(struct pws3_file *, const char *,
    uint32_t, FILE *);

void		pws3_file_set_header_field(struct pws3_file *,
    struct pws3_field *);
struct pws3_field * pws3_file_get_header_field(struct pws3_file *, uint8_t);
struct pws3_field * pws3_file_remove_header_field(struct pws3_file *, uint8_t);

void		pws3_file_insert_empty_group(struct pws3_file *,
    struct pws3_field *);
struct pws3_field * pws3_file_get_empty_group(struct pws3_file *, const char *);
struct pws3_field * pws3_file_remove_empty_group(struct pws3_file *,
    const char *);
struct pws3_field * pws3_file_first_empty_group(struct pws3_file *);
struct pws3_field * pws3_file_last_empty_group(struct pws3_file *);
struct pws3_field * pws3_file_next_empty_group(struct pws3_file *,
    struct pws3_field *);
struct pws3_field * pws3_file_prev_empty_group(struct pws3_file *,
    struct pws3_field *);

void		pws3_file_insert_record(struct pws3_file *,
    struct pws3_record *);
struct pws3_record * pws3_file_get_record(struct pws3_file *,
    const unsigned char [static PWS3_UUID_SIZE]);
struct pws3_record * pws3_file_remove_record(struct pws3_file *,
    const unsigned char [static PWS3_UUID_SIZE]);
struct pws3_record * pws3_file_first_record(struct pws3_file *);
struct pws3_record * pws3_file_last_record(struct pws3_file *);
struct pws3_record * pws3_file_next_record(struct pws3_file *,
    struct pws3_record *);
struct pws3_record * pws3_file_prev_record(struct pws3_file *,
    struct pws3_record *);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* !PWS_H */