Package eu.europa.esig.dss.asic.common
Class ASiCUtils
java.lang.Object
eu.europa.esig.dss.asic.common.ASiCUtils
Contains utils for working with ASiC containers
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The ASiC Archive Manifest namestatic final String
The ASiC Manifest namestatic final String
The ASiC-E with XAdES Manifest namestatic final String
The default ASIC archive manifest filename for ASiC-E with CAdES containerstatic final String
The default ASIC manifest filename for ASiC-E with CAdES containerstatic final String
The default signature filename for ASiC-E with CAdES containerstatic final String
The default timestamp filename for ASiC-E with CAdES containerstatic final String
The default XML manifest filename (META-INF/manifest.xml)static final String
The default signature filename for ASiC-E with XAdES containerstatic final String
The signature file extensionstatic final String
The manifest namestatic final String
The META-INF folderstatic final String
The mimetype filenamestatic final String
The mimetype commentstatic final String
The ASiC-E with XAdES for OpenDocument signature file name (META-INF/documentsignatures.xml)static final String
The "package.zip" filenamestatic final String
The signature filenamestatic final String
The ASiC-S with CAdES signature document name (META-INF/signature.p7s)static final String
The signature filenamestatic final String
The ASiC-S with XAdES signature document name (META-INF/signatures.xml)static final String
The timestamp filenamestatic final String
The ASiC-S with CAdES timestamp document name (META-INF/timestamp.tst)static final String
The timestamp file extensionstatic final String
The XML file extension -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addOrReplaceDocument
(List<DSSDocument> documentList, DSSDocument newDocument) This method searches for a document in adocumentList
with a name ofnewDocumentVersion
and replaces the found entry with the updated version or adds the document to the given list if no such entry has been foundstatic boolean
areFilesContainMimetype
(List<String> filenames) Checks if the list of filenames contains a mimetype filestatic boolean
coversSignature
(ManifestFile manifestFile) Checks if the manifestFile covers a signaturestatic ASiCContent
ensureMimeTypeAndZipComment
(ASiCContent asicContent, ASiCParameters asicParameters) This method is used to ensure the mimetype file and zip-comment are present within the givenASiCContent
.static boolean
filesContainCorrectSignatureFileWithExtension
(List<String> filenames, String extension) Checks if the list of filenames contains a signature with the expectedextension
static boolean
filesContainSignatures
(List<String> filenames) Checks if the list of filenames contains a signature(s)static boolean
filesContainTimestamps
(List<String> filenames) Checks if the list of filenames contains a timestampstatic ASiCContainerType
getASiCContainerType
(MimeType asicMimeType) Returns relatedASiCContainerType
for the givenasicMimeType
static ASiCContainerType
getContainerType
(ASiCContent asicContent) Returns container typestatic ASiCContainerType
getContainerType
(DSSDocument archiveContainer) This method verifies type of the provided container documentstatic MimeType
getMimeType
(ASiCParameters asicParameters) Returns a relevant MimeType for the provided parametersstatic MimeType
getMimeType
(DSSDocument mimeTypeDocument) Extracts and returns MimeType from the documentstatic String
getMimeTypeString
(ASiCParameters asicParameters) Returns the target MimeType stringstatic List<DSSDocument>
getRootLevelDocuments
(List<DSSDocument> documents) This method returns root-level documents across the provided list of documentsstatic List<DSSDocument>
getRootLevelSignedDocuments
(ASiCContent asicContent) This method retrieves signed document from a root level of the container (used for ASiC-E container)static String
getZipComment
(ASiCParameters asicParameters) Returns a ZIP Comment String according to the given parametersstatic String
getZipComment
(MimeType mimeType) Returns a ZIP Comment String from the providedMimeType
static String
getZipComment
(DSSDocument archiveContainer) Returns a zip commentString
from the ASiC containerstatic String
getZipComment
(String mimeTypeString) Returns a ZIP Comment String from the providedmimeTypeString
static boolean
isArchiveManifest
(String fileName) Checks if the fileName matches to an Archive Manifest name standardstatic boolean
isASiCE
(ASiCParameters asicParameters) Checks if the parameters are configured for ASiCE creationstatic boolean
isASiCEContainer
(ASiCContent asicContent) This method verifies whether the givenASiCContent
is of ASiC-E format typestatic boolean
isASiCEContainer
(DSSDocument container) This method verifies whether the given container is of ASiC-E format typestatic boolean
isAsicFileContent
(List<String> filenames) Checks if the list of filenames represents an ASiC container contentstatic boolean
isASiCMimeType
(MimeType mimeType) Checks if the given MimeType is ASiC MimeTypestatic boolean
isASiCS
(ASiCParameters asicParameters) Checks if the parameters are configured for ASiCS creationstatic boolean
isASiCSContainer
(ASiCContent asicContent) This method verifies whether the givenASiCContent
is of ASiC-S format typestatic boolean
isASiCSContainer
(DSSDocument container) This method verifies whether the given container is of ASiC-S format typestatic boolean
isASiCWithCAdES
(List<String> filenames) Checks if the extracted filenames represent an ASiC with CAdES contentstatic boolean
isASiCWithXAdES
(List<String> filenames) Checks if the extracted filenames represent an ASiC with XAdES contentstatic boolean
Checks if the entryName is a relevant CAdES signaturestatic boolean
isContainerOpenDocument
(DSSDocument archiveContainer) Checks if the archive represents an OpenDocumentstatic boolean
isManifest
(String fileName) Checks if the fileName matches to a Manifest name standardstatic boolean
isMimetype
(String entryName) Checks if the given name is a "mimetype"static boolean
isOpenDocument
(DSSDocument mimeTypeDoc) Checks if the mimeType document defines an OpenDocumentstatic boolean
isOpenDocumentMimeType
(MimeType mimeType) Checks if the given MimeType is OpenDocument MimeTypestatic boolean
isSignature
(String entryName) Verifies if theentryName
represents a signature file namestatic boolean
isTimestamp
(String entryName) Verifies if theentryName
represents a timestamp file namestatic boolean
Checks if the entryName is a relevant XAdES signaturestatic boolean
isZip
(DSSDocument document) Checks if thedocument
is a ZIP containerstatic boolean
isZip
(InputStream is) Checks if the givenInputStream
contains a ZIP containerstatic List<ManifestEntry>
toSimpleManifestEntries
(List<DSSDocument> documents) Transforms a list of given documents to a list of "simple" (only basic information) manifest entries
-
Field Details
-
MANIFEST_FILENAME
The manifest name- See Also:
-
ASIC_MANIFEST_FILENAME
The ASiC Manifest name- See Also:
-
ASIC_ARCHIVE_MANIFEST_FILENAME
The ASiC Archive Manifest name- See Also:
-
ASIC_XAdES_MANIFEST_FILENAME
The ASiC-E with XAdES Manifest name- See Also:
-
MIME_TYPE
The mimetype filename- See Also:
-
MIME_TYPE_COMMENT
The mimetype comment- See Also:
-
META_INF_FOLDER
The META-INF folder- See Also:
-
PACKAGE_ZIP
The "package.zip" filename- See Also:
-
SIGNATURE_FILENAME
The signature filename- See Also:
-
SIGNATURES_FILENAME
The signature filename- See Also:
-
TIMESTAMP_FILENAME
The timestamp filename- See Also:
-
CADES_SIGNATURE_EXTENSION
The signature file extension- See Also:
-
TST_EXTENSION
The timestamp file extension- See Also:
-
XML_EXTENSION
The XML file extension- See Also:
-
SIGNATURES_XML
The ASiC-S with XAdES signature document name (META-INF/signatures.xml)- See Also:
-
OPEN_DOCUMENT_SIGNATURES
The ASiC-E with XAdES for OpenDocument signature file name (META-INF/documentsignatures.xml)- See Also:
-
ASICE_METAINF_MANIFEST
The default XML manifest filename (META-INF/manifest.xml)- See Also:
-
ASICE_METAINF_XADES_SIGNATURE
The default signature filename for ASiC-E with XAdES container- See Also:
-
ASICE_METAINF_CADES_SIGNATURE
The default signature filename for ASiC-E with CAdES container- See Also:
-
ASICE_METAINF_CADES_TIMESTAMP
The default timestamp filename for ASiC-E with CAdES container- See Also:
-
ASICE_METAINF_CADES_MANIFEST
The default ASIC manifest filename for ASiC-E with CAdES container- See Also:
-
ASICE_METAINF_CADES_ARCHIVE_MANIFEST
The default ASIC archive manifest filename for ASiC-E with CAdES container- See Also:
-
SIGNATURE_P7S
The ASiC-S with CAdES signature document name (META-INF/signature.p7s)- See Also:
-
TIMESTAMP_TST
The ASiC-S with CAdES timestamp document name (META-INF/timestamp.tst)- See Also:
-
-
Method Details
-
isSignature
Verifies if theentryName
represents a signature file name- Parameters:
entryName
-String
name to check- Returns:
- TRUE if the entryName represents a signature file name, FALSE otherwise
-
isTimestamp
Verifies if theentryName
represents a timestamp file name- Parameters:
entryName
-String
name to check- Returns:
- TRUE if the entryName represents a timestamp file name, FALSE otherwise
-
getMimeTypeString
Returns the target MimeType string- Parameters:
asicParameters
-ASiCParameters
- Returns:
String
MimeType
-
getZipComment
Returns a ZIP Comment String according to the given parameters- Parameters:
asicParameters
-ASiCParameters
- Returns:
String
zip comment
-
getZipComment
Returns a ZIP Comment String from the providedMimeType
-
getZipComment
Returns a ZIP Comment String from the providedmimeTypeString
-
isASiCMimeType
Checks if the given MimeType is ASiC MimeType- Parameters:
mimeType
-MimeType
to check- Returns:
- TRUE if the given MimeType is ASiC MimeType, FALSE otherwise
-
isOpenDocumentMimeType
Checks if the given MimeType is OpenDocument MimeType- Parameters:
mimeType
-MimeType
to check- Returns:
- TRUE if the given MimeType is OpenDocument MimeType, FALSE otherwise
-
getASiCContainerType
Returns relatedASiCContainerType
for the givenasicMimeType
- Parameters:
asicMimeType
-MimeType
to getASiCContainerType
for- Returns:
ASiCContainerType
-
isASiCE
Checks if the parameters are configured for ASiCE creation- Parameters:
asicParameters
-ASiCParameters
- Returns:
- TRUE if parameters are configured for ASiCE, FALSE otherwise
-
isASiCS
Checks if the parameters are configured for ASiCS creation- Parameters:
asicParameters
-ASiCParameters
- Returns:
- TRUE if parameters are configured for ASiCS, FALSE otherwise
-
getMimeType
Returns a relevant MimeType for the provided parameters- Parameters:
asicParameters
-ASiCParameters
- Returns:
MimeType
-
filesContainCorrectSignatureFileWithExtension
public static boolean filesContainCorrectSignatureFileWithExtension(List<String> filenames, String extension) Checks if the list of filenames contains a signature with the expectedextension
- Parameters:
filenames
- a list of file namesextension
-String
signature file extension to find- Returns:
- TRUE if the list of filename contains the expected signature file, FALSE otherwise
-
filesContainSignatures
Checks if the list of filenames contains a signature(s)- Parameters:
filenames
- a list of file names- Returns:
- TRUE if the list of filename contains a signature file(s)
-
isAsicFileContent
Checks if the list of filenames represents an ASiC container content- Parameters:
filenames
- a list ofString
file names- Returns:
- TRUE if the list of filenames represents an ASiC container content, FALSE otherwise
-
filesContainTimestamps
Checks if the list of filenames contains a timestamp- Parameters:
filenames
- a list of filenames to check- Returns:
- TRUE if the list of filenames contains the expected timestamp file, FALSE otherwise
-
isZip
Checks if thedocument
is a ZIP container- Parameters:
document
-DSSDocument
to check- Returns:
- TRUE if the
DSSDocument
is a ZIP container, FALSE otherwise
-
isZip
Checks if the givenInputStream
contains a ZIP container- Parameters:
is
-InputStream
to check- Returns:
- TRUE if the
InputStream
is a ZIP container, FALSE otherwise
-
isASiCWithXAdES
Checks if the extracted filenames represent an ASiC with XAdES content- Parameters:
filenames
- a list ofString
file names to check- Returns:
- TRUE if the filenames represent an ASiC with XAdES content, FALSE otherwise
-
isASiCWithCAdES
Checks if the extracted filenames represent an ASiC with CAdES content- Parameters:
filenames
- a list ofString
file names to check- Returns:
- TRUE if the filenames represent an ASiC with CAdES content, FALSE otherwise
-
isXAdES
Checks if the entryName is a relevant XAdES signature- Parameters:
entryName
-String
to check- Returns:
- TRUE if the entryName is a relevant XAdES signature, FALSE otherwise
-
isCAdES
Checks if the entryName is a relevant CAdES signature- Parameters:
entryName
-String
to check- Returns:
- TRUE if the entryName is a relevant CAdES signature, FALSE otherwise
-
isContainerOpenDocument
Checks if the archive represents an OpenDocument- Parameters:
archiveContainer
-DSSDocument
an archive to verify- Returns:
- TRUE if the archive contains an OpenDocument mimetype, FALSE otherwise
-
isOpenDocument
Checks if the mimeType document defines an OpenDocument- Parameters:
mimeTypeDoc
-DSSDocument
mimetype file extracted from an ASiC container- Returns:
- TRUE if the mimeTypeDoc file defines an OpenDocument, FALSE otherwise
-
areFilesContainMimetype
Checks if the list of filenames contains a mimetype file- Parameters:
filenames
- a list of filenames to check- Returns:
- TRUE if the list of filenames contains a mimetype file, FALSE otherwise
-
isMimetype
Checks if the given name is a "mimetype"- Parameters:
entryName
-String
document name- Returns:
- TRUE if the name is a "mimetype", FALSE otherwise
-
getMimeType
Extracts and returns MimeType from the document- Parameters:
mimeTypeDocument
-DSSDocument
to get a MimeType of- Returns:
MimeType
-
isASiCSContainer
This method verifies whether the given container is of ASiC-S format type- Parameters:
container
-DSSDocument
to verify- Returns:
- TRUE if the container is of ASiC-S type, FALSE otherwise
-
isASiCEContainer
This method verifies whether the given container is of ASiC-E format type- Parameters:
container
-DSSDocument
to verify- Returns:
- TRUE if the container is of ASiC-E type, FALSE otherwise
-
getContainerType
This method verifies type of the provided container document- Parameters:
archiveContainer
-DSSDocument
to verify- Returns:
ASiCContainerType
-
isASiCSContainer
This method verifies whether the givenASiCContent
is of ASiC-S format type- Parameters:
asicContent
-ASiCContent
to verify- Returns:
- TRUE if the ASiC Content is of ASiC-S type, FALSE otherwise
-
isASiCEContainer
This method verifies whether the givenASiCContent
is of ASiC-E format type- Parameters:
asicContent
-ASiCContent
to verify- Returns:
- TRUE if the ASiC Content is of ASiC-E type, FALSE otherwise
-
getContainerType
Returns container type- Parameters:
asicContent
-ASiCContent
- Returns:
ASiCContainerType
-
isManifest
Checks if the fileName matches to a Manifest name standard- Parameters:
fileName
-String
to check- Returns:
- TRUE if the given name matches Manifest filename, FALSE otherwise
-
isArchiveManifest
Checks if the fileName matches to an Archive Manifest name standard- Parameters:
fileName
-String
to check- Returns:
- TRUE if the given name matches ASiC Archive Manifest filename, FALSE otherwise
-
coversSignature
Checks if the manifestFile covers a signature- Parameters:
manifestFile
-ManifestFile
- Returns:
- TRUE if manifest entries contain a signature, FALSE otherwise
-
addOrReplaceDocument
This method searches for a document in adocumentList
with a name ofnewDocumentVersion
and replaces the found entry with the updated version or adds the document to the given list if no such entry has been found- Parameters:
documentList
- a list ofDSSDocument
snewDocument
-DSSDocument
to add
-
ensureMimeTypeAndZipComment
public static ASiCContent ensureMimeTypeAndZipComment(ASiCContent asicContent, ASiCParameters asicParameters) This method is used to ensure the mimetype file and zip-comment are present within the givenASiCContent
. If the entry is not defined, a new value if created fromASiCParameters
.- Parameters:
asicContent
-ASiCContent
to ensure a valid structure inasicParameters
-ASiCParameters
to use to create missing entries- Returns:
ASiCContent
-
getRootLevelSignedDocuments
This method retrieves signed document from a root level of the container (used for ASiC-E container)- Parameters:
asicContent
-ASiCContent
representing the container structure- Returns:
- a list of
DSSDocument
s
-
getRootLevelDocuments
This method returns root-level documents across the provided list of documents- Parameters:
documents
- list ofDSSDocument
to get root-level documents from- Returns:
- list of
DSSDocument
s
-
getZipComment
Returns a zip commentString
from the ASiC container- Parameters:
archiveContainer
-DSSDocument
representing an Archive container- Returns:
String
zip comment
-
toSimpleManifestEntries
Transforms a list of given documents to a list of "simple" (only basic information) manifest entries- Parameters:
documents
- list ofDSSDocument
s- Returns:
- list of
ManifestEntry
s
-