Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 0.0.4

* Switch to the official contentauth c2pa-android and c2pa-ios 0.0.9 releases (from the redaranj forks)
* Add `getRemoteUrl` and `isManifestEmbedded` to the reader API
* Add `addIngredientFromFile` to the builder, reading the ingredient natively instead of passing bytes through Dart
* Add a typed `C2paSettingsDefinition`, with `C2paSettings.fromDefinition` and `updateFromDefinition`
* Support `settingsSetValue` on iOS
* Align `PredefinedAction` with the C2PA spec action list, adding the font and watermark actions
* **Breaking:** remove `Action.aiGenerated`, `PredefinedAction.aiGenerated` and other non-spec actions; tag AI-generated content with `Action.created(sourceType: DigitalSourceType.trainedAlgorithmicMedia)` instead
* iOS returns `NOT_IMPLEMENTED_IOS` for the hashed-signing and key-import/CSR/hardware-enrollment calls, which are not yet available there

## 0.0.3

* Fix Android OOM crashes in file-based signing by replacing readBytes()/ByteArrayStream with FileStream
Expand Down
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ android {
}

dependencies {
api("com.github.redaranj:c2pa-android:0.0.9-beta.7")
api("com.github.contentauth:c2pa-android:0.0.9")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.mockito:mockito-core:5.0.0")
}
Expand Down
56 changes: 53 additions & 3 deletions android/src/main/kotlin/org/guardianproject/c2pa/C2paPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonPrimitive

class C2paPlugin : FlutterPlugin, MethodCallHandler {
private lateinit var channel: MethodChannel
Expand Down Expand Up @@ -94,6 +96,8 @@ class C2paPlugin : FlutterPlugin, MethodCallHandler {
"readBytesDetailed" -> handleReadBytesDetailed(call, result)
"extractResource" -> handleExtractResource(call, result)
"readIngredientFile" -> handleReadIngredientFile(call, result)
"getRemoteUrl" -> handleGetRemoteUrl(call, result)
"isManifestEmbedded" -> handleIsManifestEmbedded(call, result)
"getSupportedReadMimeTypes" -> handleGetSupportedReadMimeTypes(result)
"getSupportedSignMimeTypes" -> handleGetSupportedSignMimeTypes(result)

Expand Down Expand Up @@ -309,6 +313,52 @@ class C2paPlugin : FlutterPlugin, MethodCallHandler {
}
}

private fun handleGetRemoteUrl(call: MethodCall, result: Result) {
val path = call.argument<String>("path")
if (path == null) {
result.error("INVALID_ARGUMENT", "Path is required", null)
return
}
val mimeType = call.argument<String>("mimeType") ?: getMimeTypeFromPath(path)
try {
val stream = FileStream(File(path), FileStream.Mode.READ, createIfNeeded = false)
val reader = Reader.fromStream(mimeType, stream)
try {
result.success(reader.remoteUrl())
} finally {
reader.close()
stream.close()
}
} catch (e: C2PAError) {
result.error("C2PA_ERROR", e.message, null)
} catch (e: Exception) {
result.error("ERROR", e.message, null)
}
}

private fun handleIsManifestEmbedded(call: MethodCall, result: Result) {
val path = call.argument<String>("path")
if (path == null) {
result.error("INVALID_ARGUMENT", "Path is required", null)
return
}
val mimeType = call.argument<String>("mimeType") ?: getMimeTypeFromPath(path)
try {
val stream = FileStream(File(path), FileStream.Mode.READ, createIfNeeded = false)
val reader = Reader.fromStream(mimeType, stream)
try {
result.success(reader.isEmbedded())
} finally {
reader.close()
stream.close()
}
} catch (e: C2PAError) {
result.error("C2PA_ERROR", e.message, null)
} catch (e: Exception) {
result.error("ERROR", e.message, null)
}
}

private fun handleGetSupportedReadMimeTypes(result: Result) {
// Return common supported MIME types - the C2PA library supports these formats
val mimeTypes = listOf(
Expand Down Expand Up @@ -747,20 +797,20 @@ class C2paPlugin : FlutterPlugin, MethodCallHandler {
val digitalSourceType = json.optString("digitalSourceType", null)

// Parse parameters if present
val parameters = mutableMapOf<String, String>()
val parameters = mutableMapOf<String, JsonElement>()
if (json.has("parameters")) {
val paramsJson = json.getJSONObject("parameters")
val keys = paramsJson.keys()
while (keys.hasNext()) {
val key = keys.next()
parameters[key] = paramsJson.optString(key, "")
parameters[key] = JsonPrimitive(paramsJson.optString(key, ""))
}
}

val action = Action(
actionName,
digitalSourceType,
softwareAgent,
softwareAgent?.let { JsonPrimitive(it) },
if (parameters.isEmpty()) null else parameters
)

Expand Down
11 changes: 8 additions & 3 deletions example/integration_test/plugin_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ void main() {

final json = manifest.toJsonString();
expect(json, contains('AI Art'));
expect(json, contains('c2pa.ai_generated'));
// AI-generated content is a created action with the
// trainedAlgorithmicMedia source type; there is no dedicated action.
expect(json, contains('c2pa.created'));
expect(json, contains('trainedAlgorithmicMedia'));
expect(json, contains('c2pa.training-mining'));
});
Expand All @@ -207,10 +209,13 @@ void main() {
final cropped = Action.cropped();
expect(cropped.action, 'c2pa.cropped');

final aiGenerated = Action.aiGenerated(
// AI-generated content is tagged via DigitalSourceType on a created
// action (spec-compliant), not via a custom action string.
final aiGenerated = Action.created(
sourceType: DigitalSourceType.trainedAlgorithmicMedia,
);
expect(aiGenerated.action, 'c2pa.ai_generated');
expect(aiGenerated.action, 'c2pa.created');
expect(aiGenerated.digitalSourceType, contains('trainedAlgorithmicMedia'));
});

testWidgets('Ingredient factories create correct ingredients', (tester) async {
Expand Down
2 changes: 0 additions & 2 deletions example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>13.0</string>
</dict>
</plist>
18 changes: 9 additions & 9 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.2"
version: "0.0.3"
camera:
dependency: "direct main"
description:
Expand Down Expand Up @@ -76,10 +76,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803
sha256: faf38497bda5ead2a8c7615f4f7939df04333478bf32e4173fcb06d428b5716b
url: "https://pub.dev"
source: hosted
version: "1.4.0"
version: "1.4.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -354,18 +354,18 @@ packages:
dependency: transitive
description:
name: matcher
sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
url: "https://pub.dev"
source: hosted
version: "0.12.17"
version: "0.12.19"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
sha256: "9c337007e82b1889149c82ed242ed1cb24a66044e30979c44912381e9be4c48b"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
version: "0.13.0"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -655,10 +655,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
url: "https://pub.dev"
source: hosted
version: "0.7.7"
version: "0.7.10"
typed_data:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion ios/c2pa_flutter/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let package = Package(
.library(name: "c2pa-flutter", targets: ["c2pa_flutter"])
],
dependencies: [
.package(url: "https://github.com/redaranj/c2pa-ios.git", exact: "0.0.9-beta.7")
.package(url: "https://github.com/contentauth/c2pa-ios.git", exact: "0.0.9")
],
targets: [
.target(
Expand Down
Loading
Loading