mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
EncryptionMethod class moved to zlibrary
This commit is contained in:
parent
bf559f0e4f
commit
24d3813d5b
13 changed files with 58 additions and 30 deletions
|
@ -20,6 +20,7 @@
|
|||
#include <AndroidUtil.h>
|
||||
#include <JniEnvelope.h>
|
||||
#include <ZLFileImage.h>
|
||||
#include <FileEncryptionInfo.h>
|
||||
|
||||
#include "fbreader/src/bookmodel/BookModel.h"
|
||||
#include "fbreader/src/formats/FormatPlugin.h"
|
||||
|
@ -134,7 +135,7 @@ extern "C"
|
|||
JNIEXPORT jstring JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readEncryptionMethod(JNIEnv* env, jobject thiz, jobject javaBook) {
|
||||
shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz);
|
||||
if (plugin.isNull()) {
|
||||
return AndroidUtil::createJavaString(env, FormatPlugin::EncryptionMethod::UNSUPPORTED);
|
||||
return AndroidUtil::createJavaString(env, EncryptionMethod::UNSUPPORTED);
|
||||
}
|
||||
|
||||
shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook);
|
||||
|
|
|
@ -28,10 +28,6 @@
|
|||
|
||||
#include "../library/Book.h"
|
||||
|
||||
const std::string FormatPlugin::EncryptionMethod::NONE = "none";
|
||||
const std::string FormatPlugin::EncryptionMethod::UNSUPPORTED = "unsupported";
|
||||
const std::string FormatPlugin::EncryptionMethod::MARLIN = "marlin";
|
||||
|
||||
bool FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream, bool force) {
|
||||
std::string language = book.language();
|
||||
std::string encoding = book.encoding();
|
||||
|
|
|
@ -46,15 +46,6 @@ public:
|
|||
|
||||
class FormatPlugin {
|
||||
|
||||
public:
|
||||
class EncryptionMethod {
|
||||
|
||||
public:
|
||||
static const std::string NONE;
|
||||
static const std::string UNSUPPORTED;
|
||||
static const std::string MARLIN;
|
||||
};
|
||||
|
||||
protected:
|
||||
FormatPlugin();
|
||||
|
||||
|
|
|
@ -75,16 +75,16 @@ private:
|
|||
std::string OEBEncryptionReader::readEncryptionMethod(const ZLFile &epubFile) {
|
||||
shared_ptr<ZLDir> epubDir = epubFile.directory();
|
||||
if (epubDir.isNull()) {
|
||||
return FormatPlugin::EncryptionMethod::UNSUPPORTED;
|
||||
return EncryptionMethod::UNSUPPORTED;
|
||||
}
|
||||
|
||||
const ZLFile rightsFile(epubDir->itemPath("META-INF/rights.xml"));
|
||||
const ZLFile encryptionFile(epubDir->itemPath("META-INF/encryption.xml"));
|
||||
if (!rightsFile.exists() && !encryptionFile.exists()) {
|
||||
return FormatPlugin::EncryptionMethod::NONE;
|
||||
return EncryptionMethod::NONE;
|
||||
}
|
||||
if (!rightsFile.exists() || !encryptionFile.exists()) {
|
||||
return FormatPlugin::EncryptionMethod::UNSUPPORTED;
|
||||
return EncryptionMethod::UNSUPPORTED;
|
||||
}
|
||||
|
||||
EpubRightsFileReader reader;
|
||||
|
@ -94,7 +94,7 @@ std::string OEBEncryptionReader::readEncryptionMethod(const ZLFile &epubFile) {
|
|||
|
||||
std::vector<shared_ptr<FileEncryptionInfo> > OEBEncryptionReader::readEncryptionInfos(const ZLFile &epubFile) {
|
||||
const std::string method = readEncryptionMethod(epubFile);
|
||||
if (method == FormatPlugin::EncryptionMethod::MARLIN) {
|
||||
if (method == EncryptionMethod::MARLIN) {
|
||||
shared_ptr<ZLDir> epubDir = epubFile.directory();
|
||||
if (!epubDir.isNull()) {
|
||||
const ZLFile encryptionFile(epubDir->itemPath("META-INF/encryption.xml"));
|
||||
|
@ -106,7 +106,7 @@ std::vector<shared_ptr<FileEncryptionInfo> > OEBEncryptionReader::readEncryption
|
|||
return std::vector<shared_ptr<FileEncryptionInfo> >();
|
||||
}
|
||||
|
||||
EpubRightsFileReader::EpubRightsFileReader() : myMethod(FormatPlugin::EncryptionMethod::UNSUPPORTED) {
|
||||
EpubRightsFileReader::EpubRightsFileReader() : myMethod(EncryptionMethod::UNSUPPORTED) {
|
||||
}
|
||||
|
||||
std::string EpubRightsFileReader::method() const {
|
||||
|
@ -115,7 +115,7 @@ std::string EpubRightsFileReader::method() const {
|
|||
|
||||
void EpubRightsFileReader::startElementHandler(const char *tag, const char **attributes) {
|
||||
if (testTag(ZLXMLNamespace::MarlinEpub, "Marlin", tag)) {
|
||||
myMethod = FormatPlugin::EncryptionMethod::MARLIN;
|
||||
myMethod = EncryptionMethod::MARLIN;
|
||||
}
|
||||
interrupt();
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ void EpubEncryptionFileReader::endElementHandler(const char *tag) {
|
|||
break;
|
||||
case READ_ENCRYPTED_DATA:
|
||||
if (testTag(ZLXMLNamespace::XMLEncryption, "EncryptedData", tag)) {
|
||||
myInfos.push_back(new FileEncryptionInfo(myUri, myAlgorithm, myKeyName));
|
||||
myInfos.push_back(new FileEncryptionInfo(myUri, EncryptionMethod::MARLIN, myAlgorithm, myKeyName));
|
||||
myState = READ_ENCRYPTION;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -21,7 +21,11 @@
|
|||
|
||||
#include "FileEncryptionInfo.h"
|
||||
|
||||
FileEncryptionInfo::FileEncryptionInfo(const std::string &uri, const std::string &algorithm, const std::string &contentId) : Uri(uri), Algorithm(algorithm), ContentId(contentId) {
|
||||
const std::string EncryptionMethod::NONE = "none";
|
||||
const std::string EncryptionMethod::UNSUPPORTED = "unsupported";
|
||||
const std::string EncryptionMethod::MARLIN = "marlin";
|
||||
|
||||
FileEncryptionInfo::FileEncryptionInfo(const std::string &uri, const std::string &method, const std::string &algorithm, const std::string &contentId) : Uri(uri), Method(method), Algorithm(algorithm), ContentId(contentId) {
|
||||
}
|
||||
|
||||
void EncryptionMap::addInfo(const ZLDir &dir, shared_ptr<FileEncryptionInfo> info) {
|
||||
|
|
|
@ -26,13 +26,22 @@
|
|||
#include <shared_ptr.h>
|
||||
#include <ZLDir.h>
|
||||
|
||||
class EncryptionMethod {
|
||||
|
||||
public:
|
||||
static const std::string NONE;
|
||||
static const std::string UNSUPPORTED;
|
||||
static const std::string MARLIN;
|
||||
};
|
||||
|
||||
class FileEncryptionInfo {
|
||||
|
||||
public:
|
||||
FileEncryptionInfo(const std::string &uri, const std::string &algorithm, const std::string &contentId);
|
||||
FileEncryptionInfo(const std::string &uri, const std::string &method, const std::string &algorithm, const std::string &contentId);
|
||||
|
||||
public:
|
||||
const std::string Uri;
|
||||
const std::string Method;
|
||||
const std::string Algorithm;
|
||||
const std::string ContentId;
|
||||
};
|
||||
|
|
|
@ -100,6 +100,9 @@ shared_ptr<ZLInputStream> ZLFile::inputStream(shared_ptr<EncryptionMap> encrypti
|
|||
shared_ptr<FileEncryptionInfo> encryptionInfo =
|
||||
encryptionMap.isNull() ? 0 : encryptionMap->info(myPath);
|
||||
ZLLogger::Instance().println("MARLIN", myPath + " :: " + (encryptionInfo.isNull() ? "not encrypted" : "encrypted"));
|
||||
if (!encryptionInfo.isNull()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
shared_ptr<ZLInputStream> stream;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.geometerplus.fbreader.fbreader;
|
|||
import java.util.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.application.*;
|
||||
import org.geometerplus.zlibrary.core.drm.EncryptionMethod;
|
||||
import org.geometerplus.zlibrary.core.library.ZLibrary;
|
||||
import org.geometerplus.zlibrary.core.options.*;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
@ -282,7 +283,7 @@ public final class FBReaderApp extends ZLApplication {
|
|||
|
||||
try {
|
||||
final String method = book.getPlugin().readEncryptionMethod(book);
|
||||
if (!FormatPlugin.EncryptionMethod.NONE.equals(method)) {
|
||||
if (!EncryptionMethod.NONE.equals(method)) {
|
||||
System.err.println("UNSUPPORTED ALGORITHM: " + method);
|
||||
/*
|
||||
UIUtil.showErrorMessage(
|
||||
|
|
|
@ -28,12 +28,6 @@ import org.geometerplus.fbreader.bookmodel.BookModel;
|
|||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
|
||||
public abstract class FormatPlugin {
|
||||
public interface EncryptionMethod {
|
||||
String NONE = "none";
|
||||
String UNSUPPORTED = "unsupported";
|
||||
String MARLIN = "marlin";
|
||||
}
|
||||
|
||||
private final String myFileType;
|
||||
|
||||
protected FormatPlugin(String fileType) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.geometerplus.fbreader.formats.fb2;
|
||||
|
||||
import org.geometerplus.zlibrary.core.drm.EncryptionMethod;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.geometerplus.fbreader.formats.oeb;
|
||||
|
||||
import org.geometerplus.zlibrary.core.drm.EncryptionMethod;
|
||||
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.geometerplus.fbreader.formats.pdb;
|
|||
|
||||
import java.io.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.drm.EncryptionMethod;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.image.*;
|
||||
import org.geometerplus.zlibrary.core.encodings.Encoding;
|
||||
|
|
26
src/org/geometerplus/zlibrary/core/drm/EncryptionMethod.java
Normal file
26
src/org/geometerplus/zlibrary/core/drm/EncryptionMethod.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2014 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.zlibrary.core.drm;
|
||||
|
||||
public interface EncryptionMethod {
|
||||
String NONE = "none";
|
||||
String UNSUPPORTED = "unsupported";
|
||||
String MARLIN = "marlin";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue