diff --git a/pom.xml b/pom.xml
index 3a9c27b..c5d6652 100644
--- a/pom.xml
+++ b/pom.xml
@@ -49,7 +49,7 @@
UTF-8
UTF-8
- 1.82
+ 1.83
1.28.0
2.21.0
4.0.4
@@ -57,7 +57,7 @@
4.0.6
1.9.3
3.0.6
- 5.5.0
+ 5.5.1
1.16.0
2.0.17
2.11.5
@@ -65,7 +65,7 @@
3.0
2.13.1
5.11.4
- 2.25.2
+ 2.25.3
diff --git a/src/main/java/org/jadice/filetype/matchers/PKCS7Matcher.java b/src/main/java/org/jadice/filetype/matchers/PKCS7Matcher.java
new file mode 100644
index 0000000..2905339
--- /dev/null
+++ b/src/main/java/org/jadice/filetype/matchers/PKCS7Matcher.java
@@ -0,0 +1,53 @@
+package org.jadice.filetype.matchers;
+
+import java.io.IOException;
+import java.security.Security;
+import java.util.Base64;
+
+import org.bouncycastle.cms.CMSSignedData;
+import org.jadice.filetype.Context;
+import org.jadice.filetype.io.SeekableInputStream;
+
+public class PKCS7Matcher extends Matcher {
+
+ @Override
+ public boolean matches(final Context context) throws IOException {
+ SeekableInputStream sis = context.getStream();
+ return isPKCS7(sis, context.getStatedExtension());
+ }
+
+ public static boolean isPKCS7(SeekableInputStream sis, String extension) throws IOException {
+ byte[] buffer = new byte[5];
+ sis.readFully(buffer);
+ try {
+ if (looksLikeCms(buffer) || (extension != null && ("ps7".equals(extension) || extension.startsWith("p7")))) {
+ return readAsCMS(sis);
+ }
+ } catch (Exception e) {
+ // ignore – detection should be resilient
+ }
+ return false;
+ }
+
+ private static boolean looksLikeCms(byte[] data) {
+ // ASN.1 DER SEQUENCE
+ return data.length > 2 && (data[0] & 0xFF) == 0x30;
+ }
+
+ private static boolean readAsCMS(SeekableInputStream sis) throws Exception {
+ Security.addProvider(
+ new org.bouncycastle.jce.provider.BouncyCastleProvider());
+ sis.seek(0);
+ final byte[] data = sis.readAllBytes();
+ CMSSignedData cms;
+ try {
+ // first try to decode in case it is base64-encoded
+ byte[] decodedBytes = Base64.getDecoder().decode(data);
+ cms = new CMSSignedData(decodedBytes);
+ } catch (IllegalArgumentException e) {
+ cms = new CMSSignedData(data);
+ }
+ return cms.getSignedContent() != null;
+ }
+}
+
diff --git a/src/main/resources/magic.xml b/src/main/resources/magic.xml
index 09d1d9e..04a1366 100644
--- a/src/main/resources/magic.xml
+++ b/src/main/resources/magic.xml
@@ -761,6 +761,28 @@
X-Rechnung type CreditNote
x_rechnung
+
+ E-Rezept
+ e_rezept
+
+
+
+
+ application/json
+ json
+ JSON
+ ^(\{|\[)
+
+ E-Rezept
+ resourceType
+
+
+
+
+ application/pkcs7-mime
+ p7s
+ PKCS #7
+ org.jadice.filetype.matchers.PKCS7Matcher
@@ -770,7 +792,6 @@
ftypheif
-
image/heic
heic
diff --git a/src/test/resources/various_types/Bundle-72bd741c-7ad8-41d8-97c3-9aabbdd0f5b4--10483995.json b/src/test/resources/various_types/Bundle-72bd741c-7ad8-41d8-97c3-9aabbdd0f5b4--10483995.json
new file mode 100644
index 0000000..09a939b
--- /dev/null
+++ b/src/test/resources/various_types/Bundle-72bd741c-7ad8-41d8-97c3-9aabbdd0f5b4--10483995.json
@@ -0,0 +1,378 @@
+{
+ "resourceType": "Bundle",
+ "id": "72bd741c-7ad8-41d8-97c3-9aabbdd0f5b4",
+ "meta": {
+ "profile": [
+ "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-PR-ERP-AbgabedatenBundle|1.5"
+ ],
+ "tag": [
+ {
+ "display": "Beispiel für Abgabedaten für ein Fertigarzneimittel mit Erfüllung des Rabattvertrags"
+ },
+ {
+ "display": "ACHTUNG! Der fachlich korrekte Inhalt der Beispielinstanz kann nicht gewährleistet werden. Wir sind jederzeit dankbar für Hinweise auf Fehler oder für Verbesserungsvorschläge."
+ }
+ ]
+ },
+ "identifier": {
+ "system": "https://gematik.de/fhir/erp/NamingSystem/GEM_ERP_NS_PrescriptionId",
+ "value": "160.123.456.789.123.58"
+ },
+ "type": "document",
+ "timestamp": "2024-11-30T15:30:00+00:00",
+ "entry": [
+ {
+ "fullUrl": "urn:uuid:ac1e9724-f5ee-448b-a594-74259fd8a926",
+ "resource": {
+ "resourceType": "Composition",
+ "id": "ac1e9724-f5ee-448b-a594-74259fd8a926",
+ "meta": {
+ "profile": [
+ "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-PR-ERP-AbgabedatenComposition|1.5"
+ ]
+ },
+ "status": "final",
+ "type": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-CompositionTypes",
+ "code": "ERezeptAbgabedaten"
+ }
+ ]
+ },
+ "date": "2024-11-04T15:30:00Z",
+ "author": [
+ {
+ "reference": "urn:uuid:11ba8a7b-79f6-4b7a-8a29-0524c9e0ba41"
+ }
+ ],
+ "title": "ERezeptAbgabedaten",
+ "section": [
+ {
+ "title": "Abgabeinformationen",
+ "entry": [
+ {
+ "reference": "urn:uuid:1c7be124-8925-46db-9c44-717838ec767d"
+ }
+ ]
+ },
+ {
+ "title": "Apotheke",
+ "entry": [
+ {
+ "reference": "urn:uuid:11ba8a7b-79f6-4b7a-8a29-0524c9e0ba41"
+ }
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "fullUrl": "urn:uuid:11ba8a7b-79f6-4b7a-8a29-0524c9e0ba41",
+ "resource": {
+ "resourceType": "Organization",
+ "id": "11ba8a7b-79f6-4b7a-8a29-0524c9e0ba41",
+ "meta": {
+ "profile": [
+ "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-PR-ERP-Apotheke|1.5"
+ ]
+ },
+ "identifier": [
+ {
+ "system": "http://fhir.de/sid/arge-ik/iknr",
+ "value": "308412345"
+ }
+ ],
+ "name": "Adler-Apotheke",
+ "address": [
+ {
+ "type": "physical",
+ "line": [
+ "Taunusstraße 89"
+ ],
+ "_line": [
+ {
+ "extension": [
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-streetName",
+ "valueString": "Taunusstraße"
+ },
+ {
+ "url": "http://hl7.org/fhir/StructureDefinition/iso21090-ADXP-houseNumber",
+ "valueString": "89"
+ }
+ ]
+ }
+ ],
+ "city": "Langen",
+ "postalCode": "63225",
+ "country": "D"
+ }
+ ]
+ }
+ },
+ {
+ "fullUrl": "urn:uuid:1c7be124-8925-46db-9c44-717838ec767d",
+ "resource": {
+ "resourceType": "MedicationDispense",
+ "id": "1c7be124-8925-46db-9c44-717838ec767d",
+ "meta": {
+ "profile": [
+ "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-PR-ERP-Abgabeinformationen|1.5"
+ ]
+ },
+ "extension": [
+ {
+ "url": "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-EX-ERP-Abrechnungszeilen",
+ "valueReference": {
+ "reference": "urn:uuid:4ee99e8d-6930-414e-9304-5ee3e6cd64bc"
+ }
+ }
+ ],
+ "status": "completed",
+ "medicationCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://terminology.hl7.org/CodeSystem/data-absent-reason",
+ "code": "not-applicable"
+ }
+ ]
+ },
+ "performer": [
+ {
+ "actor": {
+ "reference": "urn:uuid:11ba8a7b-79f6-4b7a-8a29-0524c9e0ba41"
+ }
+ }
+ ],
+ "authorizingPrescription": [
+ {
+ "identifier": {
+ "system": "https://gematik.de/fhir/erp/NamingSystem/GEM_ERP_NS_PrescriptionId",
+ "value": "160.123.456.789.123.58"
+ }
+ }
+ ],
+ "type": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-MedicationDispenseTyp",
+ "code": "Abgabeinformationen"
+ }
+ ]
+ },
+ "whenHandedOver": "2024-11-30"
+ }
+ },
+ {
+ "fullUrl": "urn:uuid:4ee99e8d-6930-414e-9304-5ee3e6cd64bc",
+ "resource": {
+ "resourceType": "Invoice",
+ "id": "4ee99e8d-6930-414e-9304-5ee3e6cd64bc",
+ "meta": {
+ "profile": [
+ "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-PR-ERP-Abrechnungszeilen|1.5"
+ ]
+ },
+ "status": "issued",
+ "type": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-InvoiceTyp",
+ "code": "Abrechnungszeilen"
+ }
+ ]
+ },
+ "lineItem": [
+ {
+ "extension": [
+ {
+ "extension": [
+ {
+ "extension": [
+ {
+ "extension": [
+ {
+ "url": "Schluessel",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-ZusatzattributFAMSchluesselMarkt",
+ "code": "1"
+ }
+ ]
+ }
+ },
+ {
+ "url": "Gruppe",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-ZusatzattributGruppe",
+ "code": "1"
+ }
+ ]
+ }
+ }
+ ],
+ "url": "Markt"
+ },
+ {
+ "extension": [
+ {
+ "url": "Gruppe",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-ZusatzattributGruppe",
+ "code": "2"
+ }
+ ]
+ }
+ },
+ {
+ "url": "Schluessel",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-ZusatzattributFAMSchluesselAbgaberangfolge",
+ "code": "1"
+ }
+ ]
+ }
+ }
+ ],
+ "url": "Rabattvertragserfuellung"
+ },
+ {
+ "extension": [
+ {
+ "url": "Gruppe",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-ZusatzattributGruppe",
+ "code": "3"
+ }
+ ]
+ }
+ },
+ {
+ "url": "Schluessel",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-ZusatzattributFAMSchluesselAbgaberangfolge",
+ "code": "0"
+ }
+ ]
+ }
+ }
+ ],
+ "url": "PreisguenstigesFAM"
+ },
+ {
+ "extension": [
+ {
+ "url": "Gruppe",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-ZusatzattributGruppe",
+ "code": "4"
+ }
+ ]
+ }
+ },
+ {
+ "url": "Schluessel",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-ZusatzattributFAMSchluesselImportFAM",
+ "code": "0"
+ }
+ ]
+ }
+ }
+ ],
+ "url": "ImportFAM"
+ }
+ ],
+ "url": "ZusatzattributFAM"
+ }
+ ],
+ "url": "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-EX-ERP-Zusatzattribute"
+ },
+ {
+ "url": "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-EX-ERP-Chargenbezeichnung",
+ "valueString": "A123456789-1"
+ }
+ ],
+ "sequence": 1,
+ "chargeItemCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.de/CodeSystem/ifa/pzn",
+ "code": "05454378"
+ }
+ ]
+ },
+ "priceComponent": [
+ {
+ "extension": [
+ {
+ "url": "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-EX-ERP-MwStSatz",
+ "valueDecimal": 19.00
+ },
+ {
+ "extension": [
+ {
+ "url": "Kategorie",
+ "valueCodeableConcept": {
+ "coding": [
+ {
+ "system": "http://fhir.abda.de/eRezeptAbgabedaten/CodeSystem/DAV-CS-ERP-KostenVersicherterKategorie",
+ "code": "0"
+ }
+ ]
+ }
+ },
+ {
+ "url": "Kostenbetrag",
+ "valueMoney": {
+ "value": 5.00,
+ "currency": "EUR"
+ }
+ }
+ ],
+ "url": "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-EX-ERP-KostenVersicherter"
+ }
+ ],
+ "type": "informational",
+ "factor": 1,
+ "amount": {
+ "value": 27.69,
+ "currency": "EUR"
+ }
+ }
+ ]
+ }
+ ],
+ "totalGross": {
+ "extension": [
+ {
+ "url": "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-EX-ERP-Gesamtzuzahlung",
+ "valueMoney": {
+ "value": 5.00,
+ "currency": "EUR"
+ }
+ }
+ ],
+ "value": 27.69,
+ "currency": "EUR"
+ }
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/various_types/Bundle-72bd741c-7ad8-41d8-97c3-9aabbdd0f5b4.json.xml b/src/test/resources/various_types/Bundle-72bd741c-7ad8-41d8-97c3-9aabbdd0f5b4.json.xml
new file mode 100644
index 0000000..4cb1559
--- /dev/null
+++ b/src/test/resources/various_types/Bundle-72bd741c-7ad8-41d8-97c3-9aabbdd0f5b4.json.xml
@@ -0,0 +1,267 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file