commit 0b82fde85e265955b50ed2a97109c2ca0af2b5ca
parent 2df09c44626321bba7b319ea5dad5f5dc0475e71
Author: sin <sin@2f30.org>
Date: Thu, 16 May 2019 13:38:15 +0300
Reorder param checks
Diffstat:
2 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/bcompress.c b/bcompress.c
@@ -136,11 +136,6 @@ bcopen(struct bctx *bctx, char *path, int flags, int mode)
}
cctx = bctx->cctx;
- if (bencryptops()->open(bctx, path, flags, mode) < 0) {
- free(cctx);
- return -1;
- }
-
if (strcasecmp(param.calgo, "none") == 0) {
cctx->type = CDNONETYPE;
} else if (strcasecmp(param.calgo, "snappy") == 0) {
@@ -148,11 +143,15 @@ bcopen(struct bctx *bctx, char *path, int flags, int mode)
} else if (strcasecmp(param.calgo, "lz4") == 0) {
cctx->type = CDLZ4TYPE;
} else {
- bencryptops()->close(bctx);
free(cctx);
seterr("invalid compression type: %s", param.calgo);
return -1;
}
+
+ if (bencryptops()->open(bctx, path, flags, mode) < 0) {
+ free(cctx);
+ return -1;
+ }
return 0;
}
diff --git a/bencrypt.c b/bencrypt.c
@@ -148,12 +148,6 @@ beopen(struct bctx *bctx, char *path, int flags, int mode)
return -1;
}
ectx = bctx->ectx;
- memcpy(ectx->key, param.key, KEYSIZE);
-
- if (bstorageops()->open(bctx, path, flags, mode) < 0) {
- free(ectx);
- return -1;
- }
/* Determine algorithm type */
if (strcasecmp(param.ealgo, "none") == 0)
@@ -161,7 +155,6 @@ beopen(struct bctx *bctx, char *path, int flags, int mode)
else if (strcasecmp(param.ealgo, "XChaCha20-Poly1305") == 0)
ectx->type = EDCHACHATYPE;
else {
- bstorageops()->close(bctx);
free(ectx);
seterr("invalid encryption type: %s", param.ealgo);
return -1;
@@ -169,12 +162,17 @@ beopen(struct bctx *bctx, char *path, int flags, int mode)
/* Ensure that if repo is encrypted, a key was provided */
if (ectx->type != EDNONETYPE && !param.keyloaded) {
- bstorageops()->close(bctx);
free(ectx);
seterr("expected encryption key");
return -1;
}
+ memcpy(ectx->key, param.key, KEYSIZE);
+
+ if (bstorageops()->open(bctx, path, flags, mode) < 0) {
+ free(ectx);
+ return -1;
+ }
return 0;
}