Skip to content

Commit 99a8a13

Browse files
authored
Sharing - added javadocs; changed some public methods to package-private (#18)
1 parent 842be6a commit 99a8a13

File tree

5 files changed

+92
-7
lines changed

5 files changed

+92
-7
lines changed

src/main/java/com/uid2/client/DecryptionResponse.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,31 @@ public class DecryptionResponse {
99
private final Integer siteId;
1010
private final Integer siteKeySiteId;
1111

12-
public DecryptionResponse(DecryptionStatus status, String uid, Instant established, Integer siteId, Integer siteKeySiteId) {
12+
DecryptionResponse(DecryptionStatus status, String uid, Instant established, Integer siteId, Integer siteKeySiteId) {
1313
this.status = status;
1414
this.uid = uid;
1515
this.established = established;
1616
this.siteId = siteId;
1717
this.siteKeySiteId = siteKeySiteId;
1818
}
1919

20+
/**
21+
* @return whether the decryption was successful.
22+
*/
2023
public boolean isSuccess() {
2124
return status == DecryptionStatus.SUCCESS;
2225
}
2326

27+
/**
28+
* @return the decryption result status. See {@link DecryptionStatus}.
29+
*/
2430
public DecryptionStatus getStatus() {
2531
return status;
2632
}
2733

34+
/**
35+
* @return the raw UID.
36+
*/
2837
public String getUid() {
2938
return uid;
3039
}
@@ -37,11 +46,11 @@ public Instant getEstablished() {
3746

3847
public Integer getSiteKeySiteId() { return siteKeySiteId; }
3948

40-
public static DecryptionResponse makeError(DecryptionStatus status) {
49+
static DecryptionResponse makeError(DecryptionStatus status) {
4150
return new DecryptionResponse(status, null, Instant.MIN, null, null);
4251
}
4352

44-
public static DecryptionResponse makeError(DecryptionStatus status, Instant established, Integer siteId, Integer siteKeySiteId) {
53+
static DecryptionResponse makeError(DecryptionStatus status, Instant established, Integer siteId, Integer siteKeySiteId) {
4554
return new DecryptionResponse(status, null, established, siteId, siteKeySiteId);
4655
}
4756
}
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,47 @@
11
package com.uid2.client;
22

3+
/**
4+
* DecryptionStatus: Indicates the result of a decrypt() call.
5+
*/
36
public enum DecryptionStatus {
7+
48
SUCCESS,
5-
NOT_AUTHORIZED_FOR_MASTER_KEY, //note this error can occur for old tokens also, since old encryption keys are regularly deleted
9+
/**
10+
* NOT_AUTHORIZED_FOR_MASTER_KEY can occur for old tokens, when the master key used to encrypt it has been deleted (eg after 30 days).
11+
* It can also occur for participants that have been removed from the UID platform, and therefore no longer have access to master keys.
12+
*/
13+
NOT_AUTHORIZED_FOR_MASTER_KEY,
14+
/**
15+
* NOT_AUTHORIZED_FOR_KEY can occur when decrypting a token from a participant that has not granted sharing access to the receiver.
16+
*/
617
NOT_AUTHORIZED_FOR_KEY,
18+
/**
19+
* NOT_INITIALIZED: IUID2Client.refresh() has not been called or did not succeed.
20+
*/
721
NOT_INITIALIZED,
22+
/**
23+
* INVALID_PAYLOAD: The UID token passed to decrypt() was invalid.
24+
*/
825
INVALID_PAYLOAD,
26+
/**
27+
* EXPIRED_TOKEN: The token has expired and so must not be used. See also NOT_AUTHORIZED_FOR_MASTER_KEY.
28+
*/
929
EXPIRED_TOKEN,
30+
/**
31+
* KEYS_NOT_SYNCED: The encryption keys have expired. This can happen if IUID2Client.refresh() has not been called for a long time.
32+
*/
1033
KEYS_NOT_SYNCED,
11-
VERSION_NOT_SUPPORTED,
34+
/**
35+
* VERSION_NOT_SUPPORTED: The token version being decrypted is too new for this SDK. Ensure you have the latest version of the SDK.
36+
*/
37+
VERSION_NOT_SUPPORTED,
38+
/**
39+
* INVALID_PAYLOAD_TYPE: This is a value returned by the legacy decryptData() method. Use decrypt() instead.
40+
*/
1241
INVALID_PAYLOAD_TYPE,
42+
/**
43+
* INVALID_IDENTITY_SCOPE: Either UID2ClientFactory.create() was used to decrypt an EUID token, or EUIDClientFactory.create() was used
44+
* to decrypt a UID2 token. Ensure the factory class matches the token type you are decrypting.
45+
*/
1346
INVALID_IDENTITY_SCOPE,
1447
}

src/main/java/com/uid2/client/EncryptionDataResponse.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,29 @@ public class EncryptionDataResponse {
44
private final EncryptionStatus status;
55
private final String encryptedData;
66

7-
public EncryptionDataResponse(EncryptionStatus status, String encryptedData) {
7+
EncryptionDataResponse(EncryptionStatus status, String encryptedData) {
88
this.status = status;
99
this.encryptedData = encryptedData;
1010
}
1111

12+
/**
13+
* @return whether the encryption was successful.
14+
*/
1215
public boolean isSuccess() {
1316
return status == EncryptionStatus.SUCCESS;
1417
}
18+
19+
/**
20+
* @return the encryption result status. See {@link EncryptionStatus}
21+
*/
1522
public EncryptionStatus getStatus() { return status; }
23+
24+
/**
25+
* @return the UID token
26+
*/
1627
public String getEncryptedData() { return encryptedData; }
1728

18-
public static EncryptionDataResponse makeError(EncryptionStatus status) {
29+
static EncryptionDataResponse makeError(EncryptionStatus status) {
1930
return new EncryptionDataResponse(status, null);
2031
}
2132
}

src/main/java/com/uid2/client/EncryptionStatus.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,32 @@
22

33
public enum EncryptionStatus {
44
SUCCESS,
5+
/**
6+
* NOT_AUTHORIZED_FOR_MASTER_KEY: Indicates that the participant has been removed from the UID platform.
7+
*/
58
NOT_AUTHORIZED_FOR_MASTER_KEY,
9+
/**
10+
* NOT_AUTHORIZED_FOR_KEY: The participant has not been enabled for encryption.
11+
*/
612
NOT_AUTHORIZED_FOR_KEY,
13+
/**
14+
* NOT_INITIALIZED: IUID2Client.refresh() has not been called or did not succeed.
15+
*/
716
NOT_INITIALIZED,
17+
/**
18+
* KEYS_NOT_SYNCED: The encryption keys have expired. This can happen if IUID2Client.refresh() has not been called for a long time.
19+
*/
820
KEYS_NOT_SYNCED,
21+
/**
22+
* TOKEN_DECRYPT_FAILURE: This is a value returned by the legacy encryptData() method. Use encrypt() instead.
23+
*/
924
TOKEN_DECRYPT_FAILURE,
25+
/**
26+
* KEY_INACTIVE: This is a value returned by the legacy encryptData() method. Use encrypt() instead.
27+
*/
1028
KEY_INACTIVE,
29+
/**
30+
* ENCRYPTION_FAILURE: An exception was thrown during encryption.
31+
*/
1132
ENCRYPTION_FAILURE,
1233
}

src/main/java/com/uid2/client/IUID2Client.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
public interface IUID2Client {
66

7+
/**
8+
* Refreshes encryption keys. Call this regularly (eg every hour) to ensure keys are up to date.
9+
*/
710
void refresh() throws UID2ClientException;
811

912
DecryptionResponse decrypt(String token, Instant now) throws UID2ClientException;
1013

14+
/**
15+
* @param token The UID token to be decrypted into a raw UID
16+
* @return See {@link DecryptionResponse}
17+
*/
1118
default DecryptionResponse decrypt(String token) throws UID2ClientException
1219
{
1320
return decrypt(token, Instant.now());
@@ -20,6 +27,10 @@ default DecryptionResponse decrypt(String token) throws UID2ClientException
2027
@Deprecated
2128
EncryptionDataResponse encryptData(EncryptionDataRequest request) throws UID2ClientException;
2229

30+
/**
31+
* @param rawUid The raw UID to be encrypted into a UID token
32+
* @return An EncryptionDataResponse, containing success status and the UID token
33+
*/
2334
EncryptionDataResponse encrypt(String rawUid) throws UID2ClientException;
2435

2536
/**

0 commit comments

Comments
 (0)