Check-in [c7a5a6f8fa]
Overview
Comment:Set default option name for first argument to md and mac commands if not specified by user. Return error message when no channel, command, data, or file arg is specified.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | crypto
Files: files | file ages | folders
SHA3-256: c7a5a6f8fac107696602e30e6533a02d37f0f882389e25ac96eccb92e7062f9d
User & Date: bohagan on 2023-11-21 23:23:46
Other Links: branch diff | manifest | tags
Context
2023-11-23
02:52
Added more message digest test cases from RFC 6234 and info command error test cases check-in: c6b0a3cd11 user: bohagan tags: crypto
2023-11-21
23:23
Set default option name for first argument to md and mac commands if not specified by user. Return error message when no channel, command, data, or file arg is specified. check-in: c7a5a6f8fa user: bohagan tags: crypto
23:00
Added write to channel for digest transform test cases check-in: 3a6a1f7d03 user: bohagan tags: crypto
Changes

Modified generic/tlsDigest.c from [879253f9c1] to [306b222bb6].

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
 *
 * Side effects:
 *	Sets result to message digest or error message
 *
 *-------------------------------------------------------------------
 */
static int DigestMain(int type, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
    int idx, format = HEX_FORMAT, res = TCL_OK, flags = 0;
    const char *digestName, *channel = NULL;
    Tcl_Obj *cmdObj = NULL, *dataObj = NULL, *fileObj = NULL, *keyObj = NULL;
    unsigned char *cipherName = NULL;
    const EVP_MD *md = NULL;
    const EVP_CIPHER *cipher = NULL;

    /* Clear interp result */
    Tcl_ResetResult(interp);

    /* Validate arg count */







|
<

|







1094
1095
1096
1097
1098
1099
1100
1101

1102
1103
1104
1105
1106
1107
1108
1109
1110
 *
 * Side effects:
 *	Sets result to message digest or error message
 *
 *-------------------------------------------------------------------
 */
static int DigestMain(int type, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
    int idx, start = 1, format = HEX_FORMAT, res = TCL_OK;

    Tcl_Obj *cmdObj = NULL, *dataObj = NULL, *fileObj = NULL, *keyObj = NULL;
    const char *digestName = NULL, *cipherName = NULL, *channel = NULL, *opt;
    const EVP_MD *md = NULL;
    const EVP_CIPHER *cipher = NULL;

    /* Clear interp result */
    Tcl_ResetResult(interp);

    /* Validate arg count */
1119
1120
1121
1122
1123
1124
1125















1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
	digestName = Tcl_GetStringFromObj(objv[1],NULL);
	if ((md = EVP_get_digestbyname(digestName)) != NULL) {
	    return DigestDataHandler(interp, objv[2], md, NULL, HEX_FORMAT | TYPE_MD, NULL);
	} else {
	    Tcl_AppendResult(interp, "Invalid digest \"", digestName, "\"", NULL);
	    return TCL_ERROR;
	}















    }

    /* Get options */
    for (idx = 1; idx < objc; idx++) {
	char *opt = Tcl_GetStringFromObj(objv[idx], NULL);

	if (opt[0] != '-') {
	    break;
	}

	OPTFLAG("-bin", format, BIN_FORMAT);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|







1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
	digestName = Tcl_GetStringFromObj(objv[1],NULL);
	if ((md = EVP_get_digestbyname(digestName)) != NULL) {
	    return DigestDataHandler(interp, objv[2], md, NULL, HEX_FORMAT | TYPE_MD, NULL);
	} else {
	    Tcl_AppendResult(interp, "Invalid digest \"", digestName, "\"", NULL);
	    return TCL_ERROR;
	}
    } else {
	/* Special case if first arg is digest, cipher, or mac */
	opt = Tcl_GetStringFromObj(objv[start], NULL);
	if (opt[0] != '-') {
	    if (type == TYPE_MD || type == TYPE_HMAC) {
		digestName = opt;
		start++;
	    } else if (type == TYPE_CMAC) {
		cipherName = opt;
		start++;
	    } else if (type == TYPE_MAC) {
		macName = opt;
		start++;
	    }
	}
    }

    /* Get options */
    for (idx = start; idx < objc; idx++) {
	char *opt = Tcl_GetStringFromObj(objv[idx], NULL);

	if (opt[0] != '-') {
	    break;
	}

	OPTFLAG("-bin", format, BIN_FORMAT);
1194
1195
1196
1197
1198
1199
1200



1201
1202
1203
1204
1205
1206
1207
	res = DigestFileHandler(interp, fileObj, md, cipher, format | type, keyObj);
    } else if (channel != NULL) {
	res = DigestChannelHandler(interp, channel, md, cipher, format | type, keyObj);
    } else if (cmdObj != NULL) {
	res = DigestCommandHandler(interp, cmdObj, md, cipher, format | type, keyObj);
    } else if (dataObj != NULL) {
	res = DigestDataHandler(interp, dataObj, md, cipher, format | type, keyObj);



    }
    return res;
}

/*
 *-------------------------------------------------------------------
 *







>
>
>







1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
	res = DigestFileHandler(interp, fileObj, md, cipher, format | type, keyObj);
    } else if (channel != NULL) {
	res = DigestChannelHandler(interp, channel, md, cipher, format | type, keyObj);
    } else if (cmdObj != NULL) {
	res = DigestCommandHandler(interp, cmdObj, md, cipher, format | type, keyObj);
    } else if (dataObj != NULL) {
	res = DigestDataHandler(interp, dataObj, md, cipher, format | type, keyObj);
    } else {
	Tcl_AppendResult(interp, "No operation specified: Use -channel, -command, -data, or -file option", NULL);
	res = TCL_ERROR;
    }
    return res;
}

/*
 *-------------------------------------------------------------------
 *