1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
|
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, format = HEX_FORMAT, res = TCL_OK, flags = 0;
int idx, start = 1, format = HEX_FORMAT, res = TCL_OK;
const char *digestName, *channel = NULL;
Tcl_Obj *cmdObj = NULL, *dataObj = NULL, *fileObj = NULL, *keyObj = NULL;
unsigned char *cipherName = 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
|
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 = 1; idx < objc; idx++) {
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
|
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;
}
/*
*-------------------------------------------------------------------
*
|