parse_ek_token::parse_ek_token(const ek_token& value) : parse_ek_prefix(slice<0, 8>(value)), entropy_(slice<8, 16>(value)), sign_(slice<16, 17>(value)), data_(slice<17, 49>(value)) { valid(verify_magic() && verify_context() && verify_checksum(value)); }
int db::find(enum pki_type type, QString name) { while (!eof()) { if (ntohs(head.type) == type) { if (name.isEmpty()) { /* only compare type */ return 0; } else if (QString::fromUtf8(head.name) == name) { return 0; } } if (!verify_magic()) { return -1; } next(); } return 1; }
void db::first(int flag) { int ret; memset(&head, 0, sizeof(db_header_t) ); head_offset = 0; file.seek(0); ret = file.read((char*)&head, sizeof(db_header_t) ); if (ret < 0 ) fileIOerr("read"); if (ret==0) { head_offset = file.size(); return; } if (!verify_magic()) return; if (ntohs(head.flags) & flag) next(flag); }
int db::next(int flag) { qint64 ret; qint64 garbage = -1; int result = 1; if (eof()) return 1; head_offset += ntohl(head.len); if (head_offset >= file.size()) { head_offset = file.size(); return 1; } while (1) { file.seek(head_offset); ret = file.read((char*)&head, sizeof head); if (ret==0) { head_offset = file.size(); break; } if (ret < 0) { fileIOerr("read"); return -1; } if (ret != sizeof head) { qWarning("next(): Short read: 0x%s of 0x%s @ 0x%s", XNUM(ret), XNUM(sizeof head), XNUM(head_offset)); if (garbage != -1) { ret += head_offset - garbage; head_offset = garbage; } qWarning("next(): Truncating 0x%s garbage bytes @ 0x%s", XNUM(ret), XNUM(head_offset)); if (backup()) file.resize(head_offset); head_offset = file.size(); return -1; } qint64 hlen = ntohl(head.len); if (!verify_magic()) { if (garbage == -1) garbage = head_offset; head_offset += 1; continue; } else { if (garbage != -1) { qWarning("next(): 0x%s bytes garbage skipped at 0x%s", XNUM(head_offset - garbage), XNUM(garbage)); } garbage = -1; if (file.size() < head_offset + hlen) { qWarning("next(): Short item (%s of %s) at 0x%s", XNUM(ntohl(head.len)), XNUM(file.size() - head_offset), XNUM(head_offset)); garbage = head_offset; /* invalidate the header */ qWarning("Invalidate short item @ 0x%s\n", XNUM(head_offset)); file.seek(head_offset); char inval = 0xcb; // 0xca +1 file.write(&inval, 1); head_offset += 4; continue; } } if (!(ntohs(head.flags) & flag)) { result = 0; break; } else { head_offset += hlen; } } if (garbage != -1) { qWarning("next(): 0x%s bytes garbage skipped at 0x%s", XNUM(head_offset - garbage), XNUM(garbage)); } return result; }