Skip to content

Commit 04df580

Browse files
committed
fix(sdk): encapsulate fields with getters and setters in sdk classes
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
1 parent fb132c4 commit 04df580

File tree

23 files changed

+1348
-549
lines changed

23 files changed

+1348
-549
lines changed

checkstyle-suppressions.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
<suppress checks="DesignForExtension" />
1212
<suppress checks="MagicNumber" />
13-
<!-- <suppress checks="VisibilityModifier" />-->
13+
<suppress checks="VisibilityModifier" />
1414
<suppress checks="RedundantModifier" />
1515
<suppress checks="WhitespaceAround" />
1616
<suppress checks="FinalParameters" />
1717
<suppress checks="FinalClass" />
18-
<!-- <suppress checks="MissingJavadocMethod" />-->
19-
<!-- <suppress checks="JavadocStyle" />-->
20-
<!-- <suppress checks="JavadocVariable" />-->
21-
<!-- <suppress checks="JavadocMethod" />-->
18+
<suppress checks="MissingJavadocMethod" />
19+
<suppress checks="JavadocStyle" />
20+
<suppress checks="JavadocVariable" />
21+
<suppress checks="JavadocMethod" />
2222
<suppress checks="HideUtilityClassConstructor" />
2323
<suppress checks="ModifierOrder" />
2424
<suppress checks="RegexpSingleline" />
@@ -43,5 +43,7 @@
4343
<suppress checks="LocalVariableName" />
4444
<suppress checks="MethodLength" />
4545
<suppress checks="ParameterNumber" />
46-
<!-- <suppress checks="JavadocPackage" />-->
46+
<suppress checks="JavadocPackage" />
47+
<suppress checks="LeftCurly" />
48+
<suppress checks="ParameterName" />
4749
</suppressions>

cmdline/src/main/java/io/opentdf/platform/Command.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void encrypt(
165165
var sdk = buildSDK();
166166
var kasInfos = kas.stream().map(k -> {
167167
var ki = new Config.KASInfo();
168-
ki.URL = k;
168+
ki.setURL(k);
169169
return ki;
170170
}).toArray(Config.KASInfo[]::new);
171171

@@ -274,7 +274,7 @@ void decrypt(@Option(names = { "-f", "--file" }, required = true) Path tdfPath,
274274
}
275275
}
276276

277-
for (Map.Entry<String, AssertionConfig.AssertionKey> entry : assertionVerificationKeys.keys
277+
for (Map.Entry<String, AssertionConfig.AssertionKey> entry : assertionVerificationKeys.getKeys()
278278
.entrySet()) {
279279
try {
280280
Object correctedKey = correctKeyType(entry.getValue().alg, entry.getValue().key, true);
@@ -336,7 +336,7 @@ void createNanoTDF(
336336
var sdk = buildSDK();
337337
var kasInfos = kas.stream().map(k -> {
338338
var ki = new Config.KASInfo();
339-
ki.URL = k;
339+
ki.setURL(k);
340340
return ki;
341341
}).toArray(Config.KASInfo[]::new);
342342

examples/src/main/java/io/opentdf/platform/DecryptCollectionExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static void main(String[] args) throws IOException {
2020
.build();
2121

2222
var kasInfo = new Config.KASInfo();
23-
kasInfo.URL = "http://localhost:8080/kas";
23+
kasInfo.setURL("http://localhost:8080/kas");
2424

2525

2626
// Convert String to InputStream

examples/src/main/java/io/opentdf/platform/EncryptCollectionExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void main(String[] args) throws IOException {
2121
.build();
2222

2323
var kasInfo = new Config.KASInfo();
24-
kasInfo.URL = "http://localhost:8080/kas";
24+
kasInfo.setURL("http://localhost:8080/kas");
2525

2626
var tdfConfig = Config.newNanoTDFConfig(
2727
Config.withNanoKasInformation(kasInfo),

examples/src/main/java/io/opentdf/platform/EncryptExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void main(String[] args) throws IOException, ParseException {
3939
.build();
4040

4141
var kasInfo = new Config.KASInfo();
42-
kasInfo.URL = "http://localhost:8080/kas";
42+
kasInfo.setURL("http://localhost:8080/kas");
4343

4444
var wrappingKeyType = KeyType.fromString(keyEncapsulationAlgorithm.toLowerCase());
4545
var tdfConfig = Config.newTDFConfig(Config.withKasInformation(kasInfo),

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

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,26 @@ private Autoconfigure() {
6363
}
6464

6565
static class KeySplitTemplate {
66-
final String kas;
67-
final String splitID;
68-
final String kid;
69-
final KeyType keyType;
66+
private final String kas;
67+
private final String splitID;
68+
private final String kid;
69+
private final KeyType keyType;
70+
71+
public String getKas() {
72+
return kas;
73+
}
74+
75+
public String getSplitID() {
76+
return splitID;
77+
}
78+
79+
public String getKid() {
80+
return kid;
81+
}
82+
83+
public KeyType getKeyType() {
84+
return keyType;
85+
}
7086

7187
@Override
7288
public String toString() {
@@ -99,8 +115,16 @@ public KeySplitTemplate(String kas, String splitID, String kid, KeyType keyType)
99115
}
100116

101117
public static class KeySplitStep {
102-
final String kas;
103-
final String splitID;
118+
private final String kas;
119+
private final String splitID;
120+
121+
public String getKas() {
122+
return kas;
123+
}
124+
125+
public String getSplitID() {
126+
return splitID;
127+
}
104128

105129
KeySplitStep(String kas, String splitId) {
106130
this.kas = Objects.requireNonNull(kas);
@@ -289,8 +313,16 @@ String name() {
289313
}
290314

291315
static class KeyAccessGrant {
292-
public Attribute attr;
293-
public List<String> kases;
316+
private Attribute attr;
317+
private List<String> kases;
318+
319+
public Attribute getAttr() {
320+
return attr;
321+
}
322+
323+
public List<String> getKases() {
324+
return kases;
325+
}
294326

295327
public KeyAccessGrant(Attribute attr, List<String> kases) {
296328
this.attr = attr;
@@ -349,11 +381,11 @@ boolean addAllGrants(AttributeValueFQN fqn, List<KeyAccessServer> granted, List<
349381

350382
for (var cachedGrantKey: cachedGrantKeys) {
351383
var mappedKey = new Config.KASInfo();
352-
mappedKey.URL = grantedKey.getUri();
353-
mappedKey.KID = cachedGrantKey.getKid();
354-
mappedKey.Algorithm = KeyType.fromPublicKeyAlgorithm(cachedGrantKey.getAlg()).toString();
355-
mappedKey.PublicKey = cachedGrantKey.getPem();
356-
mappedKey.Default = false;
384+
mappedKey.setURL(grantedKey.getUri());
385+
mappedKey.setKID(cachedGrantKey.getKid());
386+
mappedKey.setAlgorithm(KeyType.fromPublicKeyAlgorithm(cachedGrantKey.getAlg()).toString());
387+
mappedKey.setPublicKey(cachedGrantKey.getPem());
388+
mappedKey.setDefault(false);
357389
mappedKeys.computeIfAbsent(fqn.key, k -> new ArrayList<>()).add(mappedKey);
358390
}
359391
}
@@ -512,11 +544,11 @@ BooleanKeyExpression assignKeysTo(AttributeBooleanExpression e) {
512544
continue;
513545
}
514546
for (var kasInfo : mapped) {
515-
if (kasInfo.URL == null || kasInfo.URL.isEmpty()) {
547+
if (kasInfo.getURL() == null || kasInfo.getURL().isEmpty()) {
516548
logger.warn("No KAS URL found for attribute value {}", value);
517549
continue;
518550
}
519-
keys.add(new PublicKeyInfo(kasInfo.URL, kasInfo.KID, kasInfo.Algorithm));
551+
keys.add(new PublicKeyInfo(kasInfo.getURL(), kasInfo.getKID(), kasInfo.getAlgorithm()));
520552
}
521553
}
522554

@@ -615,9 +647,17 @@ public String toString() {
615647
}
616648

617649
static class PublicKeyInfo implements Comparable<PublicKeyInfo> {
618-
final String kas;
619-
final String kid;
620-
final String algorithm;
650+
private final String kas;
651+
private final String kid;
652+
private final String algorithm;
653+
654+
public String getKas() {
655+
return kas;
656+
}
657+
658+
public String getKid() { return kid; }
659+
660+
public String getAlgorithm() { return algorithm; }
621661

622662
PublicKeyInfo(String kas) {
623663
this(kas, null, null);
@@ -629,10 +669,6 @@ static class PublicKeyInfo implements Comparable<PublicKeyInfo> {
629669
this.algorithm = algorithm;
630670
}
631671

632-
String getKas() {
633-
return kas;
634-
}
635-
636672
@Override
637673
public boolean equals(Object o) {
638674
if (o == null || getClass() != o.getClass()) return false;
@@ -884,11 +920,11 @@ static Granter newGranterFromService(AttributesServiceClientInterface as, KASKey
884920

885921
static Autoconfigure.Granter createGranter(SDK.Services services, Config.TDFConfig tdfConfig) {
886922
Autoconfigure.Granter granter = new Autoconfigure.Granter(new ArrayList<>());
887-
if (tdfConfig.attributeValues != null && !tdfConfig.attributeValues.isEmpty()) {
888-
granter = Autoconfigure.newGranterFromAttributes(services.kas().getKeyCache(), tdfConfig.attributeValues.toArray(new Value[0]));
889-
} else if (tdfConfig.attributes != null && !tdfConfig.attributes.isEmpty()) {
923+
if (tdfConfig.getAttributeValues() != null && !tdfConfig.getAttributeValues().isEmpty()) {
924+
granter = Autoconfigure.newGranterFromAttributes(services.kas().getKeyCache(), tdfConfig.getAttributeValues().toArray(new Value[0]));
925+
} else if (tdfConfig.getAttributes() != null && !tdfConfig.getAttributes().isEmpty()) {
890926
granter = Autoconfigure.newGranterFromService(services.attributes(), services.kas().getKeyCache(),
891-
tdfConfig.attributes.toArray(new Autoconfigure.AttributeValueFQN[0]));
927+
tdfConfig.getAttributes().toArray(new Autoconfigure.AttributeValueFQN[0]));
892928
}
893929
return granter;
894930
}

0 commit comments

Comments
 (0)