-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): adds Collections API (#212)
Adds Collection API to NanoTDF. Decrypt: NanoTDF Client constructor will have a option to enable `CollectionStore` or pass in a custom `CollectionStore` implementation. Encrypt: NanoTDFConfig will have an option `WithCollection` to enable writing as a Collection rather as individual NanoTDF's. Examples for Collection are made in `ExampleEncryptCollection` and `ExampleDecryptCollection` and will successfully encrypt/decrypt with default OpenTDF Platform Fixtures. ExampleDecryptCollection will have only 1 Unwrap Request to Platform.
- Loading branch information
1 parent
32825b0
commit 1ee1367
Showing
7 changed files
with
336 additions
and
26 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
examples/src/main/java/io/opentdf/platform/DecryptCollectionExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.opentdf.platform; | ||
|
||
import io.opentdf.platform.sdk.Config; | ||
import io.opentdf.platform.sdk.NanoTDF; | ||
import io.opentdf.platform.sdk.SDK; | ||
import io.opentdf.platform.sdk.SDKBuilder; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
public class DecryptCollectionExample { | ||
public static void main(String[] args) throws IOException, NanoTDF.NanoTDFMaxSizeLimit, NanoTDF.UnsupportedNanoTDFFeature, NanoTDF.InvalidNanoTDFConfig, NoSuchAlgorithmException, InterruptedException { | ||
String clientId = "opentdf-sdk"; | ||
String clientSecret = "secret"; | ||
String platformEndpoint = "localhost:8080"; | ||
|
||
SDKBuilder builder = new SDKBuilder(); | ||
SDK sdk = builder.platformEndpoint(platformEndpoint) | ||
.clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) | ||
.build(); | ||
|
||
var kasInfo = new Config.KASInfo(); | ||
kasInfo.URL = "http://localhost:8080/kas"; | ||
|
||
|
||
// Convert String to InputStream | ||
NanoTDF nanoTDFClient = new NanoTDF(true); | ||
|
||
for (int i = 0; i < 50; i++) { | ||
FileInputStream fis = new FileInputStream(String.format("out/my.%d_ciphertext", i)); | ||
nanoTDFClient.readNanoTDF(ByteBuffer.wrap(fis.readAllBytes()), System.out, sdk.getServices().kas()); | ||
fis.close(); | ||
} | ||
|
||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
examples/src/main/java/io/opentdf/platform/EncryptCollectionExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.opentdf.platform; | ||
|
||
import io.opentdf.platform.sdk.Config; | ||
import io.opentdf.platform.sdk.NanoTDF; | ||
import io.opentdf.platform.sdk.SDK; | ||
import io.opentdf.platform.sdk.SDKBuilder; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
public class EncryptCollectionExample { | ||
public static void main(String[] args) throws IOException, NanoTDF.NanoTDFMaxSizeLimit, NanoTDF.UnsupportedNanoTDFFeature, NanoTDF.InvalidNanoTDFConfig, NoSuchAlgorithmException, InterruptedException { | ||
String clientId = "opentdf-sdk"; | ||
String clientSecret = "secret"; | ||
String platformEndpoint = "localhost:8080"; | ||
|
||
SDKBuilder builder = new SDKBuilder(); | ||
SDK sdk = builder.platformEndpoint(platformEndpoint) | ||
.clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) | ||
.build(); | ||
|
||
var kasInfo = new Config.KASInfo(); | ||
kasInfo.URL = "http://localhost:8080/kas"; | ||
|
||
var tdfConfig = Config.newNanoTDFConfig( | ||
Config.withNanoKasInformation(kasInfo), | ||
Config.witDataAttributes("https://example.com/attr/attr1/value/value1"), | ||
Config.withCollection() | ||
); | ||
|
||
String str = "Hello, World!"; | ||
|
||
// Convert String to InputStream | ||
var in = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8)); | ||
NanoTDF nanoTDFClient = new NanoTDF(); | ||
|
||
for (int i = 0; i < 50; i++) { | ||
FileOutputStream fos = new FileOutputStream(String.format("out/my.%d_ciphertext", i)); | ||
nanoTDFClient.createNanoTDF(ByteBuffer.wrap(str.getBytes()), fos, tdfConfig, | ||
sdk.getServices().kas()); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.