MCPcopy Index your code
hub / github.com/assaultcube/AC / parse

Method parse

source/src/crypto.cpp:1150–1229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1148static inline int aktcerttime() { return time(NULL) / (time_t) 60; } // use minutes instead of seconds as timebase, so int will be more than enough
1149
1150bool cert::parse() // parse orgmsg[] and check the signature
1151{
1152 isvalid = ischecked = needsrenewal = expired = false;
1153 pubkey = signedby = NULL; name = NULL;
1154 type = CERT_MISC;
1155 DELETEA(workmsg);
1156 lines.setsize(0);
1157 if(orglen > certheaderlenfull && orglen < (1<<20) && !strncmp(orgmsg, certheader, certheaderlen) && orgmsg[certheaderlen + 128] == '\n')
1158 { // frame ok
1159 workmsg = new char[orglen + 1];
1160 memcpy(workmsg, orgmsg, orglen + 1);
1161 uchar *signature = (uchar*) orgmsg + certheaderlenfull - 64;
1162 if(hex2bin(signature, workmsg + certheaderlen, 64) == 64)
1163 { // parse all lines
1164 certline line;
1165 for(char *b, *l = strtok_r(workmsg + certheaderlenfull, "\n\r", &b); l; l = strtok_r(NULL, "\n\r", &b))
1166 {
1167 // get comment
1168 line.comment = strstr(l, "//");
1169 if(line.comment)
1170 {
1171 *line.comment = '\0';
1172 line.comment += 2 + strspn(line.comment + 2, " ");
1173 trimtrailingwhitespace(line.comment);
1174 }
1175 trimtrailingwhitespace(l);
1176
1177 // get keyword and value, separated by ":"
1178 l += strspn(l, " \t");
1179 line.val = strchr(l, ':');
1180 if(line.val && line.val > l)
1181 {
1182 line.key = l;
1183 *line.val++ = '\0';
1184 line.val += strspn(line.val, " \t");
1185 trimtrailingwhitespace(line.key);
1186 trimtrailingwhitespace(line.val);
1187 if(!strcasecmp(line.key, "signed-by"))
1188 { // parse "signed-by" key directly
1189 if(!(strlen(line.val) == 64 && (signedby = (uchar*)line.val) && hex2bin(signedby, orgmsg + (line.val - workmsg), 32) == 32)) signedby = NULL;
1190 }
1191 else if(!strcasecmp(line.key, "signed-date"))
1192 { // parse "signed-date" key directly
1193 signeddate = atoi(line.val);
1194 }
1195 else if(!strcasecmp(line.key, "pubkey"))
1196 { // parse "pubkey" key directly
1197 if(!(strlen(line.val) == 64 && (pubkey = (uchar*)line.val) && hex2bin(pubkey, orgmsg + (line.val - workmsg), 32) == 32)) pubkey = NULL;
1198 }
1199 else if(!strcasecmp(line.key, "name"))
1200 { // parse "name" key directly
1201 name = line.val;
1202 }
1203 else
1204 { // add to list
1205 lines.add(line);
1206 if(!strcasecmp(line.key, "type")) type = getlistindex(line.val, certtypekeywords, false, 0);
1207 }

Callers

nothing calls this directly

Calls 9

hex2binFunction · 0.85
strtok_rFunction · 0.85
trimtrailingwhitespaceFunction · 0.85
getlistindexFunction · 0.85
ed25519_sign_checkFunction · 0.85
aktcerttimeFunction · 0.85
bin2hexFunction · 0.85
setsizeMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected