2017-07-16 01:13:49 +00:00
|
|
|
//==============================================================================
|
|
|
|
// This file is part of Master Password.
|
|
|
|
// Copyright (c) 2011-2017, Maarten Billemont.
|
|
|
|
//
|
|
|
|
// Master Password is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Master Password is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You can find a copy of the GNU General Public License in the
|
|
|
|
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
|
|
|
|
//==============================================================================
|
|
|
|
|
|
|
|
#ifndef _MPW_MARSHALL_H
|
|
|
|
#define _MPW_MARSHALL_H
|
|
|
|
|
2017-07-28 13:50:26 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "mpw-algorithm.h"
|
2017-07-16 01:13:49 +00:00
|
|
|
|
|
|
|
//// Types.
|
|
|
|
|
|
|
|
typedef enum( unsigned int, MPMarshallFormat ) {
|
2017-08-13 01:57:47 +00:00
|
|
|
/** Generate a key for authentication. */
|
|
|
|
MPMarshallFormatNone,
|
2017-07-16 01:13:49 +00:00
|
|
|
/** Generate a key for authentication. */
|
|
|
|
MPMarshallFormatFlat,
|
|
|
|
/** Generate a name for identification. */
|
|
|
|
MPMarshallFormatJSON,
|
2017-08-06 03:19:24 +00:00
|
|
|
|
|
|
|
MPMarshallFormatDefault = MPMarshallFormatJSON,
|
2017-07-16 01:13:49 +00:00
|
|
|
};
|
|
|
|
|
2017-08-03 05:07:19 +00:00
|
|
|
typedef enum( unsigned int, MPMarshallErrorType ) {
|
2017-07-23 20:49:55 +00:00
|
|
|
/** The marshalling operation completed successfully. */
|
|
|
|
MPMarshallSuccess,
|
|
|
|
/** An error in the structure of the marshall file interrupted marshalling. */
|
|
|
|
MPMarshallErrorStructure,
|
|
|
|
/** The marshall file uses an unsupported format version. */
|
|
|
|
MPMarshallErrorFormat,
|
|
|
|
/** A required value is missing or not specified. */
|
|
|
|
MPMarshallErrorMissing,
|
|
|
|
/** The given master password is not valid. */
|
|
|
|
MPMarshallErrorMasterPassword,
|
|
|
|
/** An illegal value was specified. */
|
|
|
|
MPMarshallErrorIllegal,
|
|
|
|
/** An internal system error interrupted marshalling. */
|
|
|
|
MPMarshallErrorInternal,
|
|
|
|
};
|
2017-08-03 05:07:19 +00:00
|
|
|
typedef struct MPMarshallError {
|
|
|
|
MPMarshallErrorType type;
|
|
|
|
const char *description;
|
|
|
|
} MPMarshallError;
|
2017-07-23 20:49:55 +00:00
|
|
|
|
2017-07-16 01:13:49 +00:00
|
|
|
typedef struct MPMarshalledQuestion {
|
|
|
|
const char *keyword;
|
|
|
|
} MPMarshalledQuestion;
|
|
|
|
|
|
|
|
typedef struct MPMarshalledSite {
|
|
|
|
const char *name;
|
|
|
|
const char *content;
|
2017-08-10 16:30:42 +00:00
|
|
|
MPResultType type;
|
2017-08-08 00:27:08 +00:00
|
|
|
MPCounterValue counter;
|
2017-07-23 01:38:53 +00:00
|
|
|
MPAlgorithmVersion algorithm;
|
2017-07-16 01:13:49 +00:00
|
|
|
|
|
|
|
const char *loginName;
|
|
|
|
bool loginGenerated;
|
|
|
|
|
|
|
|
const char *url;
|
|
|
|
unsigned int uses;
|
|
|
|
time_t lastUsed;
|
|
|
|
|
|
|
|
size_t questions_count;
|
|
|
|
MPMarshalledQuestion *questions;
|
|
|
|
} MPMarshalledSite;
|
|
|
|
|
|
|
|
typedef struct MPMarshalledUser {
|
2017-08-06 03:19:24 +00:00
|
|
|
const char *fullName;
|
2017-07-23 03:45:54 +00:00
|
|
|
const char *masterPassword;
|
2017-07-23 01:38:53 +00:00
|
|
|
MPAlgorithmVersion algorithm;
|
2017-07-23 03:45:54 +00:00
|
|
|
bool redacted;
|
2017-07-16 01:13:49 +00:00
|
|
|
|
|
|
|
unsigned int avatar;
|
2017-08-10 16:30:42 +00:00
|
|
|
MPResultType defaultType;
|
2017-07-16 01:13:49 +00:00
|
|
|
time_t lastUsed;
|
|
|
|
|
|
|
|
size_t sites_count;
|
|
|
|
MPMarshalledSite *sites;
|
|
|
|
} MPMarshalledUser;
|
|
|
|
|
2017-08-13 01:57:47 +00:00
|
|
|
typedef struct MPMarshallInfo {
|
|
|
|
MPMarshallFormat format;
|
|
|
|
MPAlgorithmVersion algorithm;
|
|
|
|
const char *fullName;
|
|
|
|
const char *keyID;
|
|
|
|
bool redacted;
|
|
|
|
time_t date;
|
|
|
|
} MPMarshallInfo;
|
|
|
|
|
2017-07-16 01:13:49 +00:00
|
|
|
//// Marshalling.
|
|
|
|
|
2017-08-13 01:57:47 +00:00
|
|
|
/** Write the user and all associated data out to the given output buffer using the given marshalling format. */
|
2017-07-16 01:13:49 +00:00
|
|
|
bool mpw_marshall_write(
|
2017-08-07 21:42:38 +00:00
|
|
|
char **out, const MPMarshallFormat outFormat, const MPMarshalledUser *user, MPMarshallError *error);
|
2017-08-13 01:57:47 +00:00
|
|
|
/** Try to read metadata on the sites in the input buffer. */
|
|
|
|
MPMarshallInfo *mpw_marshall_read_info(
|
|
|
|
const char *in);
|
|
|
|
/** Unmarshall sites in the given input buffer by parsing it using the given marshalling format. */
|
2017-07-23 01:38:53 +00:00
|
|
|
MPMarshalledUser *mpw_marshall_read(
|
2017-08-13 01:57:47 +00:00
|
|
|
const char *in, const MPMarshallFormat inFormat, const char *masterPassword, MPMarshallError *error);
|
2017-07-16 01:13:49 +00:00
|
|
|
|
|
|
|
//// Utilities.
|
|
|
|
|
2017-08-13 01:57:47 +00:00
|
|
|
/** Create a new user object ready for marshalling. */
|
2017-07-23 01:38:53 +00:00
|
|
|
MPMarshalledUser *mpw_marshall_user(
|
2017-07-23 03:45:54 +00:00
|
|
|
const char *fullName, const char *masterPassword, const MPAlgorithmVersion algorithmVersion);
|
2017-08-13 01:57:47 +00:00
|
|
|
/** Create a new site attached to the given user object, ready for marshalling. */
|
2017-07-23 01:38:53 +00:00
|
|
|
MPMarshalledSite *mpw_marshall_site(
|
2017-08-07 21:42:38 +00:00
|
|
|
MPMarshalledUser *user,
|
2017-08-10 16:30:42 +00:00
|
|
|
const char *siteName, const MPResultType resultType, const MPCounterValue siteCounter, const MPAlgorithmVersion algorithmVersion);
|
2017-08-13 01:57:47 +00:00
|
|
|
/** Create a new question attached to the given site object, ready for marshalling. */
|
2017-07-23 01:38:53 +00:00
|
|
|
MPMarshalledQuestion *mpw_marshal_question(
|
2017-08-07 21:42:38 +00:00
|
|
|
MPMarshalledSite *site, const char *keyword);
|
2017-08-13 01:57:47 +00:00
|
|
|
/** Free the given user object and all associated data. */
|
|
|
|
bool mpw_marshal_info_free(
|
|
|
|
MPMarshallInfo *info);
|
2017-07-23 01:38:53 +00:00
|
|
|
bool mpw_marshal_free(
|
2017-08-07 21:42:38 +00:00
|
|
|
MPMarshalledUser *user);
|
2017-07-16 01:13:49 +00:00
|
|
|
|
2017-08-06 03:19:24 +00:00
|
|
|
//// Format.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The purpose represented by the given name.
|
|
|
|
*/
|
|
|
|
const MPMarshallFormat mpw_formatWithName(
|
|
|
|
const char *formatName);
|
|
|
|
/**
|
|
|
|
* @return The standard name for the given purpose.
|
|
|
|
*/
|
|
|
|
const char *mpw_nameForFormat(
|
|
|
|
const MPMarshallFormat format);
|
2017-08-13 01:57:47 +00:00
|
|
|
/**
|
|
|
|
* @return The file extension that's recommended for files that use the given marshalling format.
|
|
|
|
*/
|
2017-08-06 03:19:24 +00:00
|
|
|
const char *mpw_marshall_format_extension(
|
|
|
|
const MPMarshallFormat format);
|
|
|
|
|
2017-07-16 01:13:49 +00:00
|
|
|
#endif // _MPW_MARSHALL_H
|