1
1
package io .opentdf .platform ;
2
2
3
+ import com .google .gson .JsonSyntaxException ;
3
4
import com .nimbusds .jose .JOSEException ;
4
5
import io .opentdf .platform .sdk .*;
5
6
import io .opentdf .platform .sdk .TDF ;
6
7
8
+ import com .google .gson .Gson ;
7
9
import org .apache .commons .codec .DecoderException ;
8
10
import picocli .CommandLine ;
9
11
import picocli .CommandLine .HelpCommand ;
@@ -64,7 +66,9 @@ void encrypt(
64
66
@ Option (names = { "-a" , "--attr" }, defaultValue = Option .NULL_VALUE ) Optional <String > attributes ,
65
67
@ Option (names = { "-c" ,
66
68
"--autoconfigure" }, defaultValue = Option .NULL_VALUE ) Optional <Boolean > autoconfigure ,
67
- @ Option (names = { "--mime-type" }, defaultValue = Option .NULL_VALUE ) Optional <String > mimeType )
69
+ @ Option (names = { "--mime-type" }, defaultValue = Option .NULL_VALUE ) Optional <String > mimeType ,
70
+ @ Option (names = { "--with-assertions" }, defaultValue = Option .NULL_VALUE ) Optional <String > assertion )
71
+
68
72
throws IOException , JOSEException , AutoConfigureException , InterruptedException , ExecutionException {
69
73
70
74
var sdk = buildSDK ();
@@ -79,6 +83,21 @@ void encrypt(
79
83
metadata .map (Config ::withMetaData ).ifPresent (configs ::add );
80
84
autoconfigure .map (Config ::withAutoconfigure ).ifPresent (configs ::add );
81
85
mimeType .map (Config ::withMimeType ).ifPresent (configs ::add );
86
+
87
+ if (assertion .isPresent ()) {
88
+ var assertionConfig = assertion .get ();
89
+ Gson gson = new Gson ();
90
+
91
+ AssertionConfig [] assertionConfigs ;
92
+ try {
93
+ assertionConfigs = gson .fromJson (assertionConfig , AssertionConfig [].class );
94
+ } catch (JsonSyntaxException e ) {
95
+ throw new RuntimeException ("Failed to parse assertion, expects an list of assertions" , e );
96
+ }
97
+
98
+ configs .add (Config .withAssertionConfig (assertionConfigs ));
99
+ }
100
+
82
101
if (attributes .isPresent ()) {
83
102
configs .add (Config .withDataAttributes (attributes .get ().split ("," )));
84
103
}
0 commit comments