Skip to content

Commit 2de2d33

Browse files
authored
decrypt shortcut (#427)
1 parent dd80af9 commit 2de2d33

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

cli/src/meta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main(int argc, char **argv) {
2222

2323
if (document_file.password_encrypted() && has_password) {
2424
try {
25-
document_file = document_file.decrypt(password).document_file();
25+
document_file = document_file.decrypt(password);
2626
} catch (const WrongPasswordError &) {
2727
std::cerr << "wrong password" << std::endl;
2828
return 1;

src/odr/file.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ DocumentMeta DocumentFile::document_meta() const {
247247
return m_impl->document_meta();
248248
}
249249

250+
DocumentFile DocumentFile::decrypt(const std::string &password) const {
251+
return DecodedFile::decrypt(password).document_file();
252+
}
253+
250254
Document DocumentFile::document() const { return Document(m_impl->document()); }
251255

252256
std::shared_ptr<internal::abstract::DocumentFile> DocumentFile::impl() const {
@@ -256,6 +260,10 @@ std::shared_ptr<internal::abstract::DocumentFile> DocumentFile::impl() const {
256260
PdfFile::PdfFile(std::shared_ptr<internal::abstract::PdfFile> impl)
257261
: DecodedFile(impl), m_impl{std::move(impl)} {}
258262

263+
PdfFile PdfFile::decrypt(const std::string &password) const {
264+
return DecodedFile::decrypt(password).pdf_file();
265+
}
266+
259267
std::shared_ptr<internal::abstract::PdfFile> PdfFile::impl() const {
260268
return m_impl;
261269
}

src/odr/file.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ class DocumentFile final : public DecodedFile {
262262
[[nodiscard]] DocumentType document_type() const;
263263
[[nodiscard]] DocumentMeta document_meta() const;
264264

265+
[[nodiscard]] DocumentFile decrypt(const std::string &password) const;
266+
265267
[[nodiscard]] Document document() const;
266268

267269
[[nodiscard]] std::shared_ptr<internal::abstract::DocumentFile> impl() const;
@@ -275,6 +277,8 @@ class PdfFile final : public DecodedFile {
275277
public:
276278
explicit PdfFile(std::shared_ptr<internal::abstract::PdfFile>);
277279

280+
[[nodiscard]] PdfFile decrypt(const std::string &password) const;
281+
278282
[[nodiscard]] std::shared_ptr<internal::abstract::PdfFile> impl() const;
279283

280284
private:

test/src/document_test.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,8 @@ TEST(Document, edit_ods_diff) {
106106
R"({"modifiedText":{"/child:0/row:0/child:0/child:0/child:0":"Page 1 hi","/child:1/row:0/child:0/child:0/child:0":"Page 2 hihi","/child:2/row:0/child:0/child:0/child:0":"Page 3 hihihi","/child:3/row:0/child:0/child:0/child:0":"Page 4 hihihihi","/child:4/row:0/child:0/child:0/child:0":"Page 5 hihihihihi"}})";
107107
DocumentFile document_file(
108108
TestData::test_file_path("odr-public/ods/pages.ods"));
109-
document_file =
110-
document_file
111-
.decrypt(
112-
TestData::test_file("odr-public/ods/pages.ods").password.value())
113-
.document_file();
109+
document_file = document_file.decrypt(
110+
TestData::test_file("odr-public/ods/pages.ods").password.value());
114111
Document document = document_file.document();
115112

116113
html::edit(document, diff);

0 commit comments

Comments
 (0)