1313import java .security .KeyStoreException ;
1414import java .security .NoSuchAlgorithmException ;
1515import java .security .SecureRandom ;
16+ import java .time .OffsetDateTime ;
1617import java .util .List ;
1718import java .util .Objects ;
1819import java .util .Optional ;
2627import org .slf4j .Logger ;
2728import org .slf4j .LoggerFactory ;
2829
30+
2931/**
3032 * Client for creating and getting CDOC2 key capsules from key server. Provides Builder to initialize mutual TLS
3133 * from PKCS11 (smart-card) or PKCS12 (software) key stores.
3234 */
3335public final class Cdoc2KeyCapsuleApiClient {
36+
3437 private static final Logger log = LoggerFactory .getLogger (Cdoc2KeyCapsuleApiClient .class );
3538
3639 public static final int DEFAULT_CONNECT_TIMEOUT_MS = 1000 ;
@@ -76,7 +79,7 @@ private Builder() {
7679 /**
7780 * Init server base url
7881 * @param url server base url, example https://host:8443
79- * @return
82+ * @return client builder
8083 */
8184 public Builder withBaseUrl (String url ) {
8285 this .baseUrl = url ;
@@ -86,7 +89,7 @@ public Builder withBaseUrl(String url) {
8689 /**
8790 * Client keystore used for mutual TLS
8891 * @param clientKS client key store containing client keys for mutual TLS or null, if mTLS is not used
89- * @return
92+ * @return client builder
9093 */
9194 public Builder withClientKeyStore (@ Nullable KeyStore clientKS ) {
9295 this .clientKeyStore = clientKS ;
@@ -111,7 +114,7 @@ public Builder withClientKeyStoreProtectionParameter(KeyStore.ProtectionParamete
111114 * "passwd".toCharArray());
112115 *</code>
113116 * @param trustKS initialized trusted key store to be used by TLS
114- * @return
117+ * @return client builder
115118 */
116119 public Builder withTrustKeyStore (KeyStore trustKS ) {
117120 this .trustKeyStore = trustKS ;
@@ -172,7 +175,7 @@ protected void customizeClientBuilder(ClientBuilder clientBuilder) {
172175
173176 apiClient .setDebugging (debug );
174177 apiClient .addDefaultHeader ("Accept" , "application/json" );
175- apiClient .selectHeaderAccept (new String []{ "application/json" } );
178+ apiClient .selectHeaderAccept ("application/json" );
176179
177180 apiClient .setUserAgent (userAgent );
178181
@@ -226,11 +229,21 @@ public static Builder builder() {
226229 }
227230
228231 /**
229- * @param capsule
232+ * @param capsule key capsule
230233 * @return transactionId
231- * @throws ApiException
234+ * @throws ApiException if capsule creation has failed
232235 */
233236 public String createCapsule (Capsule capsule ) throws ApiException {
237+ return createCapsule (capsule , null );
238+ }
239+
240+ /**
241+ * @param capsule key capsule
242+ * @param xExpiryTime capsule expiry time (optional)
243+ * @return transactionId
244+ * @throws ApiException if capsule creation has failed
245+ */
246+ public String createCapsule (Capsule capsule , @ Nullable OffsetDateTime xExpiryTime ) throws ApiException {
234247
235248 Objects .requireNonNull (capsule );
236249 Objects .requireNonNull (capsule .getCapsuleType ());
@@ -240,7 +253,7 @@ public String createCapsule(Capsule capsule) throws ApiException {
240253 Objects .requireNonNull (capsule .getRecipientId ());
241254 Objects .requireNonNull (capsule .getEphemeralKeyMaterial ());
242255
243- ApiResponse <Void > response = capsulesApi .createCapsuleWithHttpInfo (capsule );
256+ ApiResponse <Void > response = capsulesApi .createCapsuleWithHttpInfo (capsule , xExpiryTime );
244257 String locationHeaderValue = null ;
245258 if (response .getStatusCode () == 201
246259 && response .getHeaders () != null
@@ -267,17 +280,16 @@ public String createCapsule(Capsule capsule) throws ApiException {
267280 }
268281
269282 /**
270- *
271- * @param id
283+ * @param transactionId transaction ID
272284 * @return Optional with value, if server returned 200 or empty Optional if 404
273285 * @throws ApiException if http response code is something else that 200 or 404
274286 */
275- public Optional <Capsule > getCapsule (String id ) throws ApiException {
276- if (id == null ) {
287+ public Optional <Capsule > getCapsule (String transactionId ) throws ApiException {
288+ if (transactionId == null ) {
277289 throw new IllegalArgumentException ("transactionId cannot be null" );
278290 }
279291
280- ApiResponse <Capsule > response = capsulesApi .getCapsuleByTransactionIdWithHttpInfo (id );
292+ ApiResponse <Capsule > response = capsulesApi .getCapsuleByTransactionIdWithHttpInfo (transactionId );
281293
282294 switch (response .getStatusCode ()) {
283295 case 200 :
0 commit comments