Watermarker Library
The following page describes cross-cutting concepts regarding the watermarker library component.
Overview
Kotlin Multiplatform
Our library is developed as Kotlin Multiplatform Library with support for Kotlin, Java, and JavaScript. This allows the library to be used in any JVM compatible language (e.g., Java, Kotlin), Node.js, and in plain JavaScript (e.g., browsers).
In some cases, different code is required for different platforms. In such cases the expect and
actual
feature of Kotlin is used, or some features (like operating on files) are only available on some
platforms. Because of this, code in the same package can be in different paths, depending on the
compilation target. For this reason the following refers to packages instead of paths.
- Example: when compiling for JVM, the package
de.fraunhofer.isst.innamark.watermarker.typescontains*.ktfiles fromsrc/commonMain/kotlin/typesandsrc/jvmMain/kotlin/types.
Code Base
The watermarker library offers two main functionalities:
- Insert and extract watermarks: insert and extract additional information into/from files/data.
- Generate and parse watermarks: generate and parse information that is used in watermarks.
These tasks seem similar but are very independent of each other. The only requirement they share is the data format: the library inserts and extracts watermarks as bytes, therefore the generate and parse watermarks task must be able to generate and parse bytes.
Error Handling
We handle errors (and warnings) as values, not as exceptions. Our library
should not throw any exceptions, instead functions which can fail should return a Status or a
Result if they return a value. See Error Handling for details.
Insert and Extract Watermarks
The code in the package de.fraunhofer.isst.innamark.watermarker.types.files is responsible for parsing and
generating supported file types in memory:
- all classes adding support for a file type must implement the interface
WatermarkableFile - the classes should offer functions to modify the contents of the file when possible
- Example:
ZipFileoffers functions to add/remove extra fields into the header section of zip files
- Example:
The code in the package de.fraunhofer.isst.innamark.watermarker.watermarkers.file is responsible for
inserting and extracting watermarks into
WatermarkableFiles:
- for each instance of
WatermarkableFile, a class implementingFileWatermarkerfor that specific instance should exist (e.g.,ZipFileWatermarkerforZipFilewhich is responsible for inserting, extracting and removing watermarks into/from thatWatermarkableFilewhile maintaining a valid file.
Generate and Parse Watermarks
The code in the package de.fraunhofer.isst.innamark.watermarker.types.watermarks is responsible for
generating watermarks and parsing extracted watermarks:
- The class
Watermarkis the most basic watermark that offers very limited functionality but is used as a base class for many functions that expect a watermark as parameter as well as for more sophisticated watermarks. All watermarks should directly or indirectly inherit from this class. - The class
InnamarkTagimplements a watermark scheme that uses the first byte of the watermark as a tag to identify the format of the watermark. The format defines if additional information about the watermark (e.g., size, checksums, or hashes) is included in the watermark. The format of the content itself is not defined in detail (e.g., text, certificate, image, ...), but general information about the content is defined (currently only whether the content is compressed). For more details see the InnamarkTag documentation section. This implies that a user extracting anInnamarkTagmust know the type of content but not the format used to store the content.- To offer convenient functions to generate, modify, and parse
InnamarkTags with specific content (e.g., text, certificate, ...) the interfaceInnamarkTagBuildercan be used to implement a class with a builder-like pattern.
- To offer convenient functions to generate, modify, and parse