Skip to content

Commit

Permalink
[common] Refactor Protected Files, part 1
Browse files Browse the repository at this point in the history
This commit refactors PF code without changing functionality (part 1 in
a series of commits). In particular, this commit removes unused
functions, variables, fields, typedefs and macros.

Signed-off-by: Dmitrii Kuvaiskii <[email protected]>
  • Loading branch information
Dmitrii Kuvaiskii committed May 2, 2024
1 parent 8b91c2f commit 7f3f02d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 32 deletions.
8 changes: 0 additions & 8 deletions common/src/protected_files/protected_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -1356,11 +1356,3 @@ pf_status_t pf_flush(pf_context_t* pf) {

return PF_STATUS_SUCCESS;
}

pf_status_t pf_get_handle(pf_context_t* pf, pf_handle_t* handle) {
if (!g_initialized)
return PF_STATUS_UNINITIALIZED;

*handle = pf->file;
return PF_STATUS_SUCCESS;
}
15 changes: 0 additions & 15 deletions common/src/protected_files/protected_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ typedef uint8_t pf_mac_t[PF_MAC_SIZE];
typedef uint8_t pf_key_t[PF_KEY_SIZE];
typedef uint8_t pf_keyid_t[32]; /* key derivation material */

extern pf_key_t g_pf_mrenclave_key;
extern pf_key_t g_pf_mrsigner_key;
extern pf_key_t g_pf_wrap_key;
extern bool g_pf_wrap_key_set;

typedef enum _pf_status_t {
PF_STATUS_SUCCESS = 0,
PF_STATUS_UNKNOWN_ERROR = -1,
Expand Down Expand Up @@ -296,16 +291,6 @@ pf_status_t pf_set_size(pf_context_t* pf, uint64_t size);
*/
pf_status_t pf_rename(pf_context_t* pf, const char* new_path);

/*!
* \brief Get underlying handle of a PF.
*
* \param pf PF context.
* \param[out] handle Handle to the backing file.
*
* \returns PF status.
*/
pf_status_t pf_get_handle(pf_context_t* pf, pf_handle_t* handle);

/*!
* \brief Flush any pending data of a protected file to disk.
*
Expand Down
12 changes: 3 additions & 9 deletions common/src/protected_files/protected_files_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include <limits.h>

#include "list.h"
#include "protected_files.h"

#define PF_FILE_ID 0x46505f5346415247 /* GRAFS_PF */
Expand Down Expand Up @@ -53,9 +52,7 @@ typedef struct _metadata_encrypted {

typedef uint8_t metadata_encrypted_blob_t[sizeof(metadata_encrypted_t)];

#define METADATA_NODE_SIZE PF_NODE_SIZE

typedef uint8_t metadata_padding_t[METADATA_NODE_SIZE -
typedef uint8_t metadata_padding_t[PF_NODE_SIZE -
(sizeof(metadata_plain_t) + sizeof(metadata_encrypted_blob_t))];

typedef struct _metadata_node {
Expand Down Expand Up @@ -102,18 +99,16 @@ static_assert(sizeof(encrypted_node_t) == PF_NODE_SIZE, "sizeof(encrypted_node_t

#define MAX_PAGES_IN_CACHE 48

typedef enum {
enum {
FILE_MHT_NODE_TYPE = 1,
FILE_DATA_NODE_TYPE = 2,
} mht_node_type_e;
};

// make sure these are the same size
static_assert(sizeof(mht_node_t) == sizeof(data_node_t),
"sizeof(mht_node_t) == sizeof(data_node_t)");

DEFINE_LIST(_file_node);
typedef struct _file_node {
LIST_TYPE(_file_node) list;
uint8_t type;
uint64_t node_number;
struct _file_node* parent;
Expand All @@ -127,7 +122,6 @@ typedef struct _file_node {
data_node_t data;
} decrypted;
} file_node_t;
DEFINE_LISTP(_file_node);

typedef struct {
uint32_t index;
Expand Down

0 comments on commit 7f3f02d

Please sign in to comment.