void outputter(SCREEN_Screen* scr, int terminator, GetCharFunction getf) { while (1) { unsigned char c = getf(); if (c == terminator) { return; } switch (c) { case '\a': break; // TODO: alert? case '\t': tab(scr); break; case '\n': cursor_down(scr); break; case '\b': cursor_left(scr); break; case '\r': carriage_return(scr); break; case 0x1b: { c = getf(); switch (c) { case '[': { int x; if (getnum(getf, &x, &c)) { if (x == 1 && c == 'K') { clr_bol(scr); } else { switch (c) { case 'm': mode(scr, x); break; case 'A': parm_up_cursor(scr, x); break; case 'B': parm_down_cursor(scr, x); break; case 'C': parm_right_cursor(scr, x); break; case 'D': parm_left_cursor(scr, x); break; case 'G': column_address(scr, (x-1)); break; case 'L': parm_insert_line(scr, x); break; case 'M': parm_delete_line(scr, x); break; case 'P': parm_dch(scr, x); break; case 'S': parm_index(scr, x); break; case 'T': parm_rindex(scr, x); break; case 'X': erase_chars(scr, x); break; case '@': parm_ich(scr, x); break; case 'd': row_address(scr, (x-1)); break; case ';': { int y; if (getnum(getf, &y, &c)) { switch (c) { case 'm': mode(scr, x); mode(scr, y); break; case 'H': cursor_address(scr, mkpos(y-1, x-1)); break; default: fprintf(stderr, "unhandled: ESC[%i;%i%c\n", x, y, c); break; } } else { fprintf(stderr, "unhandled: ESC[%i;%c\n", x, c); } } break; default: fprintf(stderr, "unahndled: ESC[%i%c\n", x, c); break; } } } else { switch (c) { case '@': insert_character(scr); break; case 'A': cursor_up(scr); break; case 'B': cursor_down(scr); break; case 'C': cursor_right(scr); break; case 'D': cursor_left(scr); break; case 'H': cursor_home(scr); break; case 'I': tab(scr); break; case 'J': clr_eos(scr); break; case 'K': clr_eol(scr); break; case 'L': insert_line(scr); break; case 'M': delete_line(scr); break; case 'P': delete_character(scr); break; case 'm': exit_attribute_mode(scr); break; default: fprintf(stderr, "unhandled: ESC[%c\n", c); break; } } } break; case 'M': scroll_reverse(scr); break; default: fprintf(stderr, "unhandled: ESC%c\n", c); break; } } break; default: { wchar_t wc; if ((c & 0x80) == 0x00) { wc = c; } else if ((c & 0xE0) == 0xC0) { char c1 = 0x1F & c; char c2 = 0x3F & getf(); wc = (c1 << 6) | c2; } else if ((c & 0xF0) == 0xE0) { char c1 = 0x0F & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); wc = (c1 << 12) | (c2 << 6) | c3; } else if ((c & 0xF8) == 0xF0) { char c1 = 0x07 & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); char c4 = 0x3F & getf(); wc = (c1 << 18) | (c2 << 12) | (c3 << 6) | c4; } else if ((c & 0xFC) == 0xF8) { char c1 = 0x03 & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); char c4 = 0x3F & getf(); char c5 = 0x3F & getf(); wc = (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | c5; } else if ((c & 0xFE) == 0xFC) { char c1 = 0x01 & c; char c2 = 0x3F & getf(); char c3 = 0x3F & getf(); char c4 = 0x3F & getf(); char c5 = 0x3F & getf(); char c6 = 0x3F & getf(); wc = (c1 << 30) | (c2 << 24) | (c3 << 18) | (c4 << 12) | (c5 < 6) | c6; } else { fprintf(stderr, "bad utf-8 sequence: c=0x%02x\n", c); wc = '\0'; } put_char(scr, wc); } break; } } }
std::string Ciphersuite::to_string() const { if(m_cipher_keylen == 0) throw Exception("Ciphersuite::to_string - no value set"); std::ostringstream out; out << "TLS_"; if(kex_algo() != "RSA") { if(kex_algo() == "DH") out << "DHE"; else if(kex_algo() == "ECDH") out << "ECDHE"; else out << kex_algo(); out << '_'; } if(sig_algo() == "DSA") out << "DSS_"; else if(sig_algo() != "") out << sig_algo() << '_'; out << "WITH_"; if(cipher_algo() == "RC4") { out << "RC4_128_"; } else if(cipher_algo() == "ChaCha20Poly1305") { out << "CHACHA20_POLY1305_"; } else { if(cipher_algo() == "3DES") out << "3DES_EDE"; else if(cipher_algo().find("Camellia") == 0) out << "CAMELLIA_" << std::to_string(8*cipher_keylen()); else { if(cipher_algo().find("OCB(12)") != std::string::npos) out << replace_chars(cipher_algo().substr(0, cipher_algo().size() - 4), {'-', '/'}, '_'); else out << replace_chars(cipher_algo(), {'-', '/'}, '_'); } if(cipher_algo().find("/") != std::string::npos) out << "_"; // some explicit mode already included else out << "_CBC_"; } if(mac_algo() == "SHA-1") out << "SHA"; else if(mac_algo() == "AEAD") out << erase_chars(prf_algo(), {'-'}); else out << erase_chars(mac_algo(), {'-'}); return out.str(); }
static void InpProcess(char **ppbuf, int *plen) { int len, x; char *pbuf; char ch; struct inpdata *inpdata; struct display *inpdisplay; int prev, next, search = 0; inpdata = (struct inpdata *)flayer->l_data; inpdisplay = display; #define RESET_SEARCH { if (inpdata->search) Free(inpdata->search); } LGotoPos(flayer, inpdata->inpstringlen + (inpdata->inpmode & INP_NOECHO ? 0 : inpdata->inp.pos), INPUTLINE); if (ppbuf == 0) { InpAbort(); return; } x = inpdata->inpstringlen + inpdata->inp.pos; len = *plen; pbuf = *ppbuf; while (len) { char *p = inpdata->inp.buf + inpdata->inp.pos; ch = *pbuf++; len--; if (inpdata->inpmode & INP_EVERY) { inpdata->inp.buf[inpdata->inp.len] = ch; if (ch) { display = inpdisplay; (*inpdata->inpfinfunc)(inpdata->inp.buf, inpdata->inp.len, inpdata->priv); ch = inpdata->inp.buf[inpdata->inp.len]; } } else if (inpdata->inpmode & INP_RAW) { display = inpdisplay; (*inpdata->inpfinfunc)(&ch, 1, inpdata->priv); /* raw */ if (ch) continue; } if (((unsigned char)ch & 0177) >= ' ' && ch != 0177 && inpdata->inp.len < inpdata->inpmaxlen) { if (inpdata->inp.len > inpdata->inp.pos) memmove(p+1, p, inpdata->inp.len - inpdata->inp.pos); inpdata->inp.buf[inpdata->inp.pos++] = ch; inpdata->inp.len++; if (!(inpdata->inpmode & INP_NOECHO)) { struct mchar mc; mc = mchar_so; mc.image = *p++; LPutChar(flayer, &mc, x, INPUTLINE); x++; if (p < inpdata->inp.buf+inpdata->inp.len) { while (p < inpdata->inp.buf+inpdata->inp.len) { mc.image = *p++; LPutChar(flayer, &mc, x++, INPUTLINE); } x = inpdata->inpstringlen + inpdata->inp.pos; LGotoPos(flayer, x, INPUTLINE); } } RESET_SEARCH; } else if ((ch == '\b' || ch == 0177) && inpdata->inp.pos > 0) { erase_chars(inpdata, p-1, p, x, 1); RESET_SEARCH; } else if (ch == '\025') /* CTRL-U */ { x = inpdata->inpstringlen; if (inpdata->inp.len && !(inpdata->inpmode & INP_NOECHO)) { LClearArea(flayer, x, INPUTLINE, x + inpdata->inp.len - 1, INPUTLINE, 0, 0); LGotoPos(flayer, x, INPUTLINE); } inpdata->inp.len = inpdata->inp.pos = 0; } else if (ch == '\013') /* CTRL-K */ { x = inpdata->inpstringlen + inpdata->inp.pos; if (inpdata->inp.len > inpdata->inp.pos && !(inpdata->inpmode & INP_NOECHO)) { LClearArea(flayer, x, INPUTLINE, x + inpdata->inp.len - inpdata->inp.pos - 1, INPUTLINE, 0, 0); LGotoPos(flayer, x, INPUTLINE); } inpdata->inp.len = inpdata->inp.pos; } else if (ch == '\027' && inpdata->inp.pos > 0) /* CTRL-W */ { char *oldp = p--; while (p > inpdata->inp.buf && *p == ' ') p--; while (p > inpdata->inp.buf && *(p - 1) != ' ') p--; erase_chars(inpdata, p, oldp, x, 1); RESET_SEARCH; } else if (ch == '\004' && inpdata->inp.pos < inpdata->inp.len) /* CTRL-D */ { erase_chars(inpdata, p, p+1, x, 0); RESET_SEARCH; } else if (ch == '\001' || (unsigned char)ch == 0201) /* CTRL-A */ { LGotoPos(flayer, x -= inpdata->inp.pos, INPUTLINE); inpdata->inp.pos = 0; } else if ((ch == '\002' || (unsigned char)ch == 0202) && inpdata->inp.pos > 0) /* CTRL-B */ { LGotoPos(flayer, --x, INPUTLINE); inpdata->inp.pos--; } else if (ch == '\005' || (unsigned char)ch == 0205) /* CTRL-E */ { LGotoPos(flayer, x += inpdata->inp.len - inpdata->inp.pos, INPUTLINE); inpdata->inp.pos = inpdata->inp.len; } else if ((ch == '\006' || (unsigned char)ch == 0206) && inpdata->inp.pos < inpdata->inp.len) /* CTRL-F */ { LGotoPos(flayer, ++x, INPUTLINE); inpdata->inp.pos++; } else if ((prev = ((ch == '\020' || (unsigned char)ch == 0220) && /* CTRL-P */ inpdata->inp.prev)) || (next = ((ch == '\016' || (unsigned char)ch == 0216) && /* CTRL-N */ inpdata->inp.next)) || (search = ((ch == '\022' || (unsigned char)ch == 0222) && inpdata->inp.prev))) { struct mchar mc; struct inpline *sel; int pos = -1; mc = mchar_so; if (prev) sel = inpdata->inp.prev; else if (next) sel = inpdata->inp.next; else { /* search */ inpdata->inp.buf[inpdata->inp.len] = 0; /* Remove the ctrl-r from the end */ if (!inpdata->search) inpdata->search = SaveStr(inpdata->inp.buf); for (sel = inpdata->inp.prev; sel; sel = sel->prev) { char *f; if ((f = strstr(sel->buf, inpdata->search))) { pos = f - sel->buf; break; } } if (!sel) continue; /* Did not find a match. Process the next input. */ } if (inpdata->inp.len && !(inpdata->inpmode & INP_NOECHO)) LClearArea(flayer, inpdata->inpstringlen, INPUTLINE, inpdata->inpstringlen + inpdata->inp.len - 1, INPUTLINE, 0, 0); if ((prev || search) && !inpdata->inp.next) inphist = inpdata->inp; memcpy(&inpdata->inp, sel, sizeof(struct inpline)); if (pos != -1) inpdata->inp.pos = pos; if (inpdata->inp.len > inpdata->inpmaxlen) inpdata->inp.len = inpdata->inpmaxlen; if (inpdata->inp.pos > inpdata->inp.len) inpdata->inp.pos = inpdata->inp.len; x = inpdata->inpstringlen; p = inpdata->inp.buf; if (!(inpdata->inpmode & INP_NOECHO)) { while (p < inpdata->inp.buf+inpdata->inp.len) { mc.image = *p++; LPutChar(flayer, &mc, x++, INPUTLINE); } } x = inpdata->inpstringlen + inpdata->inp.pos; LGotoPos(flayer, x, INPUTLINE); } else if (ch == '\003' || ch == '\007' || ch == '\033' || ch == '\000' || ch == '\n' || ch == '\r') { if (ch != '\n' && ch != '\r') inpdata->inp.len = 0; inpdata->inp.buf[inpdata->inp.len] = 0; if (inpdata->inp.len && !(inpdata->inpmode & (INP_NOECHO | INP_RAW))) { struct inpline *store; /* Look for a duplicate first */ for (store = inphist.prev; store; store = store->prev) { if (strcmp(store->buf, inpdata->inp.buf) == 0) { if (store->next) store->next->prev = store->prev; if (store->prev) store->prev->next = store->next; store->pos = inpdata->inp.pos; break; } } if (!store) { store = malloc(sizeof(struct inpline)); memcpy(store, &inpdata->inp, sizeof(struct inpline)); } store->next = &inphist; store->prev = inphist.prev; if (inphist.prev) inphist.prev->next = store; inphist.prev = store; } flayer->l_data = 0; /* so inpdata does not get freed */ InpAbort(); /* redisplays... */ *ppbuf = pbuf; *plen = len; display = inpdisplay; if ((inpdata->inpmode & INP_RAW) == 0) (*inpdata->inpfinfunc)(inpdata->inp.buf, inpdata->inp.len, inpdata->priv); else (*inpdata->inpfinfunc)(pbuf - 1, 0, inpdata->priv); if (inpdata->search) free(inpdata->search); free(inpdata); return; } else { /* The user was searching, and then pressed some non-control input. So reset * the search string. */ RESET_SEARCH; } } if (!(inpdata->inpmode & INP_RAW)) { flayer->l_x = inpdata->inpstringlen + (inpdata->inpmode & INP_NOECHO ? 0 : inpdata->inp.pos); flayer->l_y = INPUTLINE; } *ppbuf = pbuf; *plen = len; }