QByteArray CompositeIntegerGroup::GetByteArray() const { QByteArray out; QDataStream stream(&out, QIODevice::WriteOnly); stream << _p << _s << _n << ElementToByteArray(_g); return out; }
bool ByteGroup::DecodeBytes(const Element &a, QByteArray &out) const { QByteArray data = ElementToByteArray(a); if(data.count() != _n_bytes) { qWarning() << "Tried to decode invalid plaintext (wrong length):" << data.toHex(); return false; } const int len = Utils::Serialization::ReadInt(data, 0); out = data.mid(4, len); return true; }
bool CompositeIntegerGroup::DecodeBytes(const Element &a, QByteArray &out) const { QByteArray data = ElementToByteArray(a); if(data.count() < 2) { qWarning() << "Tried to decode invalid plaintext (too short):" << data.toHex(); return false; } const unsigned char cfirst = data[0]; const unsigned char clast = data.right(1)[0]; if(cfirst != 0xff || clast != 0xff) { qWarning() << "Tried to decode invalid plaintext (bad padding)"; return false; } out = data.mid(1, data.count()-2); return true; }