mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 15:17:29 +00:00
Add V5 parameters to EncryptionData
This commit is contained in:
parent
68447bb556
commit
3101955ac0
@ -230,6 +230,8 @@ class QPDF
|
||||
// This class holds data read from the encryption dictionary.
|
||||
EncryptionData(int V, int R, int Length_bytes, int P,
|
||||
std::string const& O, std::string const& U,
|
||||
std::string const& OE, std::string const& UE,
|
||||
std::string const& Perms,
|
||||
std::string const& id1, bool encrypt_metadata) :
|
||||
V(V),
|
||||
R(R),
|
||||
@ -237,6 +239,9 @@ class QPDF
|
||||
P(P),
|
||||
O(O),
|
||||
U(U),
|
||||
OE(OE),
|
||||
UE(UE),
|
||||
Perms(Perms),
|
||||
id1(id1),
|
||||
encrypt_metadata(encrypt_metadata)
|
||||
{
|
||||
@ -248,11 +253,19 @@ class QPDF
|
||||
int getP() const;
|
||||
std::string const& getO() const;
|
||||
std::string const& getU() const;
|
||||
std::string const& getOE() const;
|
||||
std::string const& getUE() const;
|
||||
std::string const& getPerms() const;
|
||||
std::string const& getId1() const;
|
||||
bool getEncryptMetadata() const;
|
||||
|
||||
void setO(std::string const&);
|
||||
void setU(std::string const&);
|
||||
void setV5EncryptionParameters(std::string const& O,
|
||||
std::string const& OE,
|
||||
std::string const& U,
|
||||
std::string const& UE,
|
||||
std::string const& Perms);
|
||||
|
||||
private:
|
||||
EncryptionData(EncryptionData const&);
|
||||
@ -264,6 +277,9 @@ class QPDF
|
||||
int P;
|
||||
std::string O;
|
||||
std::string U;
|
||||
std::string OE;
|
||||
std::string UE;
|
||||
std::string Perms;
|
||||
std::string id1;
|
||||
bool encrypt_metadata;
|
||||
};
|
||||
|
@ -295,6 +295,7 @@ class QPDFWriter
|
||||
void setEncryptionParametersInternal(
|
||||
int V, int R, int key_len, long P,
|
||||
std::string const& O, std::string const& U,
|
||||
std::string const& OE, std::string const& UE, std::string const& Perms,
|
||||
std::string const& id1, std::string const& user_password);
|
||||
void setDataKey(int objid);
|
||||
int openObject(int objid = 0);
|
||||
|
@ -406,7 +406,7 @@ QPDFWriter::setEncryptionParameters(
|
||||
user_password, owner_password, V, R, key_len, P,
|
||||
this->encrypt_metadata, this->id1, O, U);
|
||||
setEncryptionParametersInternal(
|
||||
V, R, key_len, P, O, U, this->id1, user_password);
|
||||
V, R, key_len, P, O, U, "", "", "", this->id1, user_password);
|
||||
}
|
||||
|
||||
void
|
||||
@ -467,6 +467,9 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf)
|
||||
encrypt.getKey("/P").getIntValue(),
|
||||
encrypt.getKey("/O").getStringValue(),
|
||||
encrypt.getKey("/U").getStringValue(),
|
||||
"", // XXXX OE
|
||||
"", // XXXX UE
|
||||
"", // XXXX Perms
|
||||
this->id1, // this->id1 == the other file's id1
|
||||
qpdf.getPaddedUserPassword());
|
||||
}
|
||||
@ -569,8 +572,11 @@ void
|
||||
QPDFWriter::setEncryptionParametersInternal(
|
||||
int V, int R, int key_len, long P,
|
||||
std::string const& O, std::string const& U,
|
||||
std::string const& OE, std::string const& UE, std::string const& Perms,
|
||||
std::string const& id1, std::string const& user_password)
|
||||
{
|
||||
// XXXX OE, UE, Perms, V=5
|
||||
|
||||
encryption_dictionary["/Filter"] = "/Standard";
|
||||
encryption_dictionary["/V"] = QUtil::int_to_string(V);
|
||||
encryption_dictionary["/Length"] = QUtil::int_to_string(key_len * 8);
|
||||
@ -606,7 +612,7 @@ QPDFWriter::setEncryptionParametersInternal(
|
||||
|
||||
this->encrypted = true;
|
||||
QPDF::EncryptionData encryption_data(
|
||||
V, R, key_len, P, O, U, id1, this->encrypt_metadata);
|
||||
V, R, key_len, P, O, U, OE, UE, Perms, id1, this->encrypt_metadata);
|
||||
this->encryption_key = QPDF::compute_encryption_key(
|
||||
user_password, encryption_data);
|
||||
}
|
||||
|
@ -62,6 +62,24 @@ QPDF::EncryptionData::getU() const
|
||||
return this->U;
|
||||
}
|
||||
|
||||
std::string const&
|
||||
QPDF::EncryptionData::getOE() const
|
||||
{
|
||||
return this->OE;
|
||||
}
|
||||
|
||||
std::string const&
|
||||
QPDF::EncryptionData::getUE() const
|
||||
{
|
||||
return this->UE;
|
||||
}
|
||||
|
||||
std::string const&
|
||||
QPDF::EncryptionData::getPerms() const
|
||||
{
|
||||
return this->Perms;
|
||||
}
|
||||
|
||||
std::string const&
|
||||
QPDF::EncryptionData::getId1() const
|
||||
{
|
||||
@ -86,6 +104,21 @@ QPDF::EncryptionData::setU(std::string const& U)
|
||||
this->U = U;
|
||||
}
|
||||
|
||||
void
|
||||
QPDF::EncryptionData::setV5EncryptionParameters(
|
||||
std::string const& O,
|
||||
std::string const& OE,
|
||||
std::string const& U,
|
||||
std::string const& UE,
|
||||
std::string const& Perms)
|
||||
{
|
||||
this->O = O;
|
||||
this->OE = OE;
|
||||
this->U = U;
|
||||
this->UE = UE;
|
||||
this->Perms = Perms;
|
||||
}
|
||||
|
||||
static void
|
||||
pad_or_truncate_password(std::string const& password, char k1[key_bytes])
|
||||
{
|
||||
@ -557,7 +590,8 @@ QPDF::initializeEncryption()
|
||||
" a bug report that includes this file.");
|
||||
}
|
||||
}
|
||||
EncryptionData data(V, R, Length / 8, P, O, U, id1, this->encrypt_metadata);
|
||||
EncryptionData data(V, R, Length / 8, P, O, U, "", "", "",
|
||||
id1, this->encrypt_metadata);
|
||||
if (check_owner_password(
|
||||
this->user_password, this->provided_password, data))
|
||||
{
|
||||
@ -779,7 +813,8 @@ QPDF::compute_encryption_O_U(
|
||||
int V, int R, int key_len, int P, bool encrypt_metadata,
|
||||
std::string const& id1, std::string& O, std::string& U)
|
||||
{
|
||||
EncryptionData data(V, R, key_len, P, "", "", id1, encrypt_metadata);
|
||||
EncryptionData data(V, R, key_len, P, "", "", "", "", "",
|
||||
id1, encrypt_metadata);
|
||||
data.setO(compute_O_value(user_password, owner_password, data));
|
||||
O = data.getO();
|
||||
data.setU(compute_U_value(user_password, data));
|
||||
|
Loading…
Reference in New Issue
Block a user