Skip to content

Commit 33c9513

Browse files
docs: JavaDoc (#196)
Added JavaDoc comments to multiple classes and methods across the SDK, providing detailed descriptions of their functionality and usage. This enhances the readability and maintainability of the code. DSP-119
1 parent 210a157 commit 33c9513

23 files changed

+150
-4
lines changed

sdk/src/main/java/io/opentdf/platform/sdk/AesGcm.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
import java.security.NoSuchAlgorithmException;
1313
import java.security.SecureRandom;
1414

15+
/**
16+
* The AesGcm class provides encryption and decryption methods using AES-GCM mode.
17+
* It includes methods to encrypt and decrypt byte arrays using a specified
18+
* symmetric key.
19+
*/
1520
public class AesGcm {
1621
public static final int GCM_NONCE_LENGTH = 12; // in bytes
1722
public static final int GCM_TAG_LENGTH = 16; // in bytes

sdk/src/main/java/io/opentdf/platform/sdk/AssertionConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
import java.util.Objects;
55

6+
/**
7+
* Represents the configuration for assertions, encapsulating various types, scopes, states, keys,
8+
* and statements involved in assertion handling.
9+
*/
610
public class AssertionConfig {
711

812
public enum Type {

sdk/src/main/java/io/opentdf/platform/sdk/AsymDecryption.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import java.security.spec.PKCS8EncodedKeySpec;
1010
import java.util.Base64;
1111

12+
/**
13+
* Class providing functionality for asymmetric decryption using an RSA private key.
14+
*/
1215
public class AsymDecryption {
1316
private final PrivateKey privateKey;
1417
private static final String PRIVATE_KEY_HEADER = "-----BEGIN PRIVATE KEY-----";

sdk/src/main/java/io/opentdf/platform/sdk/AsymEncryption.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
import java.util.Base64;
1616
import java.util.Objects;
1717

18+
/**
19+
* AsymEncryption class provides methods for asymmetric encryption and
20+
* handling public keys in PEM format.
21+
*/
1822
public class AsymEncryption {
1923
private final PublicKey publicKey;
2024
private static final String PUBLIC_KEY_HEADER = "-----BEGIN PUBLIC KEY-----";

sdk/src/main/java/io/opentdf/platform/sdk/AutoConfigureException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.opentdf.platform.sdk;
22

3+
/**
4+
* Exception thrown when automatic configuration fails.
5+
*/
36
public class AutoConfigureException extends RuntimeException {
47
public AutoConfigureException(String message) {
58
super(message);

sdk/src/main/java/io/opentdf/platform/sdk/Autoconfigure.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
import java.util.regex.Pattern;
3636
import java.util.stream.Collectors;
3737

38-
// Attribute rule types: operators!
38+
/**
39+
* The RuleType class defines a set of constants that represent various types of attribute rules.
40+
* These constants are used to specify the nature and behavior of attribute rules in the context
41+
* of key management and policy enforcement.
42+
*/
3943
class RuleType {
4044
public static final String HIERARCHY = "hierarchy";
4145
public static final String ALL_OF = "allOf";
@@ -44,6 +48,12 @@ class RuleType {
4448
public static final String EMPTY_TERM = "DEFAULT";
4549
}
4650

51+
/**
52+
* The Autoconfigure class provides methods for configuring and retrieving
53+
* grants related to attribute values and KAS (Key Access Server) keys.
54+
* This class includes functionality to create granter instances based on
55+
* attributes either from a list of attribute values or from a service.
56+
*/
4757
public class Autoconfigure {
4858

4959
public static Logger logger = LoggerFactory.getLogger(Autoconfigure.class);

sdk/src/main/java/io/opentdf/platform/sdk/Config.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import java.util.*;
1111
import java.util.function.Consumer;
1212

13+
/**
14+
* Configuration class for setting various configurations related to TDF.
15+
* Contains nested classes and enums for specific configuration settings.
16+
*/
1317
public class Config {
1418

1519
public static final int TDF3_KEY_SIZE = 2048;

sdk/src/main/java/io/opentdf/platform/sdk/CryptoUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import java.security.*;
66
import java.util.Base64;
77

8+
/**
9+
* Utility class for cryptographic operations such as generating RSA key pairs and calculating HMAC.
10+
*/
811
public class CryptoUtils {
912
private static final int KEYPAIR_SIZE = 2048;
1013

sdk/src/main/java/io/opentdf/platform/sdk/InvalidZipException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package io.opentdf.platform.sdk;
22

3+
/**
4+
* InvalidZipException is thrown to indicate that a ZIP file being read
5+
* is invalid or corrupted in some way. This exception extends RuntimeException,
6+
* allowing it to be thrown during the normal operation of the Java Virtual Machine.
7+
*/
38
public class InvalidZipException extends RuntimeException {
49
public InvalidZipException(String message) {
510
super(message);

sdk/src/main/java/io/opentdf/platform/sdk/KASClient.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030

3131
import static java.lang.String.format;
3232

33+
/**
34+
* A client implementation that communicates with a Key Access Service (KAS).
35+
* This class provides methods to retrieve public keys, unwrap encrypted keys,
36+
* and manage key caches.
37+
*/
3338
public class KASClient implements SDK.KAS {
3439

3540
private final Function<String, ManagedChannel> channelFactory;

sdk/src/main/java/io/opentdf/platform/sdk/KASKeyCache.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import java.util.HashMap;
99
import java.util.Map;
1010

11+
/**
12+
* Class representing a cache for KAS (Key Access Server) information.
13+
* It stores key information along with a timestamp to manage the freshness of cached data.
14+
*/
1115
public class KASKeyCache {
1216
private static final Logger log = LoggerFactory.getLogger(KASKeyCache.class);
1317
Map<KASKeyRequest, TimeStampedKASInfo> cache;
@@ -50,6 +54,17 @@ public void store(Config.KASInfo kasInfo) {
5054
}
5155
}
5256

57+
/**
58+
* A class representing Key Aggregation Service (KAS) information along with a timestamp.
59+
* <p>
60+
* This class holds information related to KAS, as well as a timestamp indicating when the
61+
* information was recorded or generated. It encapsulates two main attributes: {@code kasInfo}
62+
* and {@code timestamp}.
63+
* <p>
64+
* The {@code kasInfo} field is an instance of {@code Config.KASInfo}, which contains the KAS-specific
65+
* data. The {@code timestamp} field is an instance of {@code LocalDateTime}, representing
66+
* the date and time when the KAS information was recorded.
67+
*/
5368
class TimeStampedKASInfo {
5469
Config.KASInfo kasInfo;
5570
LocalDateTime timestamp;
@@ -60,6 +75,13 @@ public TimeStampedKASInfo(Config.KASInfo kasInfo, LocalDateTime timestamp) {
6075
}
6176
}
6277

78+
/**
79+
* Represents a request for a Key Access Server (KAS) key.
80+
* This class is used to request keys using a specified URL and algorithm.
81+
*
82+
* This class also overrides equals and hashCode methods
83+
* to ensure proper functioning within hash-based collections.
84+
*/
6385
class KASKeyRequest {
6486
private String url;
6587
private String algorithm;

sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
import java.util.List;
2828
import java.util.Objects;
2929

30+
/**
31+
* The Manifest class represents a detailed structure encapsulating various aspects
32+
* of data integrity, encryption, payload, and assertions within a certain context.
33+
*/
3034
public class Manifest {
3135

3236
private static final String kAssertionHash = "assertionHash";

sdk/src/main/java/io/opentdf/platform/sdk/NanoTDF.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
import org.slf4j.Logger;
1717
import org.slf4j.LoggerFactory;
1818

19+
/**
20+
* The NanoTDF class provides methods to create and read NanoTDF (Tiny Data Format) files.
21+
* The NanoTDF format is intended for securely encrypting small data payloads using elliptic-curve cryptography
22+
* and authenticated encryption.
23+
*/
1924
public class NanoTDF {
2025

2126
public static Logger logger = LoggerFactory.getLogger(NanoTDF.class);

sdk/src/main/java/io/opentdf/platform/sdk/PolicyObject.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import java.util.List;
44

5+
/**
6+
* The PolicyObject class represents a policy with a unique identifier and a body containing data attributes.
7+
*/
58
public class PolicyObject {
69
static public class AttributeObject {
710
public String attribute;

sdk/src/main/java/io/opentdf/platform/sdk/SDK.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,20 @@ public class SDK implements AutoCloseable {
3434

3535
private static final Logger log = LoggerFactory.getLogger(SDK.class);
3636

37+
/**
38+
* Closes the SDK, including its associated services.
39+
*
40+
* @throws Exception if an error occurs while closing the services.
41+
*/
3742
@Override
3843
public void close() throws Exception {
3944
services.close();
4045
}
4146

47+
/**
48+
* KAS (Key Access Service) interface to define methods related to key access and management.
49+
* This interface extends AutoCloseable to allow for resource management during close operations.
50+
*/
4251
public interface KAS extends AutoCloseable {
4352
Config.KASInfo getPublicKey(Config.KASInfo kasInfo);
4453

@@ -51,7 +60,10 @@ public interface KAS extends AutoCloseable {
5160
KASKeyCache getKeyCache();
5261
}
5362

54-
// TODO: add KAS
63+
/**
64+
* The Services interface provides access to various gRPC service stubs and a Key Authority Service (KAS).
65+
* It extends the AutoCloseable interface, allowing for the release of resources when no longer needed.
66+
*/
5567
public interface Services extends AutoCloseable {
5668
AuthorizationServiceFutureStub authorization();
5769

sdk/src/main/java/io/opentdf/platform/sdk/SDKBuilder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public SDKBuilder sslFactory(SSLFactory sslFactory) {
6969
* Add SSL Context with trusted certs from certDirPath
7070
*
7171
* @param certsDirPath Path to a directory containing .pem or .crt trusted certs
72-
* @return
7372
*/
7473
public SDKBuilder sslFactoryFromDirectory(String certsDirPath) throws Exception {
7574
File certsDir = new File(certsDirPath);
@@ -91,7 +90,6 @@ public SDKBuilder sslFactoryFromDirectory(String certsDirPath) throws Exception
9190
*
9291
* @param keystorePath Path to keystore
9392
* @param keystorePassword Password to keystore
94-
* @return
9593
*/
9694
public SDKBuilder sslFactoryFromKeyStore(String keystorePath, String keystorePassword) {
9795
this.sslFactory = SSLFactory.builder().withDefaultTrustMaterial().withSystemTrustMaterial()

sdk/src/main/java/io/opentdf/platform/sdk/SDKException.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package io.opentdf.platform.sdk;
22

3+
/**
4+
* SDKException serves as a custom exception class for handling errors
5+
* specific to the SDK's operations and processes. It extends
6+
* RuntimeException, making it an unchecked exception.
7+
*/
38
public class SDKException extends RuntimeException {
49
public SDKException(String message, Exception reason) {
510
super(message, reason);

sdk/src/main/java/io/opentdf/platform/sdk/TDF.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,23 @@
2828
import java.util.*;
2929
import java.util.concurrent.ExecutionException;
3030

31+
/**
32+
* The TDF class is responsible for handling operations related to
33+
* Trusted Data Format (TDF). It includes methods to create and load
34+
* TDF objects, as well as utility functions to handle cryptographic
35+
* operations and configurations.
36+
*/
3137
public class TDF {
3238

3339
private final long maximumSize;
3440

41+
/**
42+
* Constructs a new TDF instance using the default maximum input size defined by MAX_TDF_INPUT_SIZE.
43+
* <p>
44+
* This constructor is primarily used to initialize the TDF object with the standard maximum
45+
* input size, which controls the maximum size of the input data that can be processed.
46+
* For test purposes, an alternative constructor allows for setting a custom maximum input size.
47+
*/
3548
public TDF() {
3649
this(MAX_TDF_INPUT_SIZE);
3750
}

sdk/src/main/java/io/opentdf/platform/sdk/TDFReader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
import static io.opentdf.platform.sdk.TDFWriter.TDF_MANIFEST_FILE_NAME;
1313
import static io.opentdf.platform.sdk.TDFWriter.TDF_PAYLOAD_FILE_NAME;
1414

15+
/**
16+
* TDFReader is responsible for reading and processing Trusted Data Format (TDF) files.
17+
* The class initializes with a TDF file channel, extracts the manifest and payload entries,
18+
* and provides methods to retrieve the manifest content, read payload bytes, and read policy objects.
19+
*/
1520
public class TDFReader {
1621

1722
private final ZipReader.Entry manifestEntry;

sdk/src/main/java/io/opentdf/platform/sdk/TDFWriter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import java.io.OutputStream;
55
import java.nio.charset.StandardCharsets;
66

7+
/**
8+
* The TDFWriter class provides functionalities for creating a TDF (Trusted Data Format) archive.
9+
* This includes appending a manifest file and appending payload data to the archive.
10+
*/
711
public class TDFWriter {
812
public static final String TDF_PAYLOAD_FILE_NAME = "0.payload";
913
public static final String TDF_MANIFEST_FILE_NAME = "0.manifest.json";

sdk/src/main/java/io/opentdf/platform/sdk/ZipReader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
import java.util.ArrayList;
1313
import java.util.List;
1414

15+
/**
16+
* The ZipReader class provides functionality to read basic ZIP file
17+
* structures, such as the End of Central Directory Record and the
18+
* Local File Header. This class supports standard ZIP archives as well
19+
* as ZIP64 format.
20+
*/
1521
public class ZipReader {
1622

1723
public static final Logger logger = LoggerFactory.getLogger(ZipReader.class);

sdk/src/main/java/io/opentdf/platform/sdk/ZipWriter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import java.util.ArrayList;
1010
import java.util.zip.CRC32;
1111

12+
/**
13+
* The ZipWriter class provides functionalities to create ZIP archive files.
14+
* It writes files and data to an underlying output stream in the ZIP file format.
15+
*/
1216
public class ZipWriter {
1317

1418
private static final int ZIP_VERSION = 0x2D;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* The io.opentdf.platform.sdk package provides a comprehensive set of
3+
* classes, interfaces, enums, and exceptions designed for interacting with
4+
* the OpenTDF platform. At its core, the {@link io.opentdf.platform.sdk.SDK} class
5+
* serves as the centerpiece for this package, representing a software development kit
6+
* that facilitates integration with the OpenTDF services. The package also includes
7+
* classes for various encryption and decryption operations such as {@link io.opentdf.platform.sdk.AesGcm}
8+
* and its inner classes, as well as support for assertions and configurations through
9+
* classes like {@link io.opentdf.platform.sdk.AssertionConfig} and {@link io.opentdf.platform.sdk.Config}.
10+
* Additionally, utility classes such as {@link io.opentdf.platform.sdk.CryptoUtils} and
11+
* functionality for reading and writing TDF files are provided via {@link io.opentdf.platform.sdk.TDFReader}
12+
* and {@link io.opentdf.platform.sdk.TDFWriter}. The package also defines a collection of
13+
* enums for various configurations and state definitions, alongside a comprehensive
14+
* set of exceptions to handle different error scenarios, ensuring robust and secure
15+
* operations within the OpenTDF ecosystem.
16+
*
17+
* @since 1.0
18+
*/
19+
package io.opentdf.platform.sdk;

0 commit comments

Comments
 (0)