URI: 
       Use a type field in snap.c - dedup - deduplicating backup program
  HTML git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit ba06cd1fc2b7c9c50147f5af8898e524cfb741b6
   DIR parent 17e33eb2f548925c5a1fead6c2bfe65f6f16cade
  HTML Author: sin <sin@2f30.org>
       Date:   Fri, 17 May 2019 14:28:53 +0300
       
       Use a type field in snap.c
       
       Similar to how it is done for the compression/encryption modules.
       
       Diffstat:
         M snap.c                              |      36 +++++++++++++++++--------------
       
       1 file changed, 20 insertions(+), 16 deletions(-)
       ---
   DIR diff --git a/snap.c b/snap.c
       @@ -21,6 +21,10 @@
        #include "snap.h"
        #include "state.h"
        
       +/* snapshot encryption algorithms */
       +#define SNONETYPE        0x400
       +#define SCHACHATYPE        0x401
       +
        /* snapshot header constants */
        #define SHDRMAGIC        "SNAPSNAPPYSNOOP"
        #define NSHDRMAGIC        sizeof(SHDRMAGIC)
       @@ -55,7 +59,7 @@ struct mdnode {
        struct sctx {
                TAILQ_HEAD(mdhead, mdnode) mdhead;        /* list of hashes contained in snapshot */
                struct mdnode *mdnext;                        /* next hash to be returned via sget() */
       -        int crypto;                                /* when set, snapshots are encrypted */
       +        int type;                                /* encryption algorithm */
                int fd;                                        /* underlying snapshot file descriptor */
                int rdonly;                                /* when set, ssync() is a no-op */
                struct shdr shdr;                        /* snapshot header */
       @@ -114,7 +118,7 @@ loadmdnone(struct sctx *sctx, int first)
        }
        
        static int
       -loadmdcrypto(struct sctx *sctx, int first)
       +loadmdchacha(struct sctx *sctx, int first)
        {
                unsigned char buf[MDSIZE + crypto_secretstream_xchacha20poly1305_ABYTES];
                unsigned char hdr[SHDRSIZE];
       @@ -161,10 +165,10 @@ initmdhead(struct sctx *sctx)
                int (*loadmd)(struct sctx *, int);
                uint64_t i;
        
       -        if (!sctx->crypto)
       +        if (sctx->type == SNONETYPE)
                        loadmd = loadmdnone;
                else
       -                loadmd = loadmdcrypto;
       +                loadmd = loadmdchacha;
        
                shdr = &sctx->shdr;
                for (i = 0; i < shdr->nbd; i++) {
       @@ -188,7 +192,7 @@ screat(char *path, int mode, struct sctx **sctx)
        {
                unsigned char buf[SHDRSIZE];
                struct shdr *shdr;
       -        int crypto;
       +        int type;
                int fd;
        
                if (path == NULL || sctx == NULL) {
       @@ -198,16 +202,16 @@ screat(char *path, int mode, struct sctx **sctx)
        
                /* Determine algorithm type */
                if (strcasecmp(param.ealgo, "none") == 0) {
       -                crypto = 0;
       +                type = SNONETYPE;
                } else if (strcasecmp(param.ealgo, "XChaCha20-Poly1305") == 0) {
       -                crypto = 1;
       +                type = SCHACHATYPE;
                } else {
                        seterr("invalid encryption type: %s", param.ealgo);
                        return -1;
                }
        
                /* Ensure a key has been provided if caller requested encryption */
       -        if (crypto && !param.keyloaded) {
       +        if (type != SNONETYPE && !param.keyloaded) {
                        seterr("expected encryption key");
                        return -1;
                }
       @@ -232,7 +236,7 @@ screat(char *path, int mode, struct sctx **sctx)
        
                TAILQ_INIT(&(*sctx)->mdhead);
                (*sctx)->mdnext = NULL;
       -        (*sctx)->crypto = crypto;
       +        (*sctx)->type = type;
                (*sctx)->fd = fd;
        
                shdr = &(*sctx)->shdr;
       @@ -255,7 +259,7 @@ sopen(char *path, int flags, int mode, struct sctx **sctx)
        {
                unsigned char buf[SHDRSIZE];
                struct shdr *shdr;
       -        int crypto;
       +        int type;
                int fd;
        
                if (path == NULL || sctx == NULL) {
       @@ -271,9 +275,9 @@ sopen(char *path, int flags, int mode, struct sctx **sctx)
        
                /* Determine algorithm type */
                if (strcasecmp(param.ealgo, "none") == 0) {
       -                crypto = 0;
       +                type = SNONETYPE;
                } else if (strcasecmp(param.ealgo, "XChaCha20-Poly1305") == 0) {
       -                crypto = 1;
       +                type = SCHACHATYPE;
                } else {
                        seterr("invalid encryption type: %s", param.ealgo);
                        return -1;
       @@ -299,7 +303,7 @@ sopen(char *path, int flags, int mode, struct sctx **sctx)
        
                TAILQ_INIT(&(*sctx)->mdhead);
                (*sctx)->mdnext = NULL;
       -        (*sctx)->crypto = crypto;
       +        (*sctx)->type = type;
                (*sctx)->fd = fd;
                (*sctx)->rdonly = 1;
        
       @@ -418,7 +422,7 @@ syncnone(struct sctx *sctx)
        }
        
        static int
       -synccrypto(struct sctx *sctx)
       +syncchacha(struct sctx *sctx)
        {
                unsigned char hdr[SHDRSIZE];
                crypto_secretstream_xchacha20poly1305_state state;
       @@ -474,10 +478,10 @@ ssync(struct sctx *sctx)
                        return -1;
                }
        
       -        if (!sctx->crypto)
       +        if (sctx->type == SNONETYPE)
                        syncnone(sctx);
                else
       -                synccrypto(sctx);
       +                syncchacha(sctx);
        
                fsync(sctx->fd);
                return 0;