Skip to content

Commit 221aad8

Browse files
updated currentkey variable names
1 parent 1e5b6bb commit 221aad8

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

src/main/java/com/uid2/admin/salt/SaltRotation.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ private SaltEntry updateSalt(SaltEntry oldBucket, TargetDate targetDate, boolean
135135
);
136136
}
137137

138-
private long calculateRefreshFrom(SaltEntry salt, TargetDate targetDate) {
139-
long multiplier = targetDate.saltAgeInDays(salt) / 30 + 1;
140-
return Instant.ofEpochMilli(salt.lastUpdated()).truncatedTo(ChronoUnit.DAYS).toEpochMilli() + (multiplier * THIRTY_DAYS_IN_MS);
138+
private long calculateRefreshFrom(SaltEntry bucket, TargetDate targetDate) {
139+
long multiplier = targetDate.saltAgeInDays(bucket) / 30 + 1;
140+
return Instant.ofEpochMilli(bucket.lastUpdated()).truncatedTo(ChronoUnit.DAYS).toEpochMilli() + (multiplier * THIRTY_DAYS_IN_MS);
141141
}
142142

143-
private String calculateCurrentSalt(SaltEntry salt, boolean shouldRotate) throws Exception {
143+
private String calculateCurrentSalt(SaltEntry bucket, boolean shouldRotate) throws Exception {
144144
if (shouldRotate) {
145145
if (ENABLE_V4_RAW_UID) {
146146
return null;
@@ -149,15 +149,15 @@ private String calculateCurrentSalt(SaltEntry salt, boolean shouldRotate) throws
149149
return this.keyGenerator.generateRandomKeyString(32);
150150
}
151151
}
152-
return salt.currentSalt();
152+
return bucket.currentSalt();
153153
}
154154

155-
private String calculatePreviousSalt(SaltEntry salt, boolean shouldRotate, TargetDate targetDate) {
155+
private String calculatePreviousSalt(SaltEntry bucket, boolean shouldRotate, TargetDate targetDate) {
156156
if (shouldRotate) {
157-
return salt.currentSalt();
157+
return bucket.currentSalt();
158158
}
159-
if (targetDate.saltAgeInDays(salt) < 90) {
160-
return salt.previousSalt();
159+
if (targetDate.saltAgeInDays(bucket) < 90) {
160+
return bucket.previousSalt();
161161
}
162162
return null;
163163
}

src/test/java/com/uid2/admin/salt/SaltRotationTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,10 @@ void testKeyRotationKeyIdWrap(int[] existingIds, int[] nextIds) throws Exception
553553
var willNotRefresh = targetDate().plusDays(30);
554554
var lastSnapshot = SaltSnapshotBuilder.start()
555555
.entries(
556-
SaltBuilder.start().lastUpdated(targetDate().minusDays(90)).refreshFrom(willNotRefresh).currentKey(existingIds[0]),
557-
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKey(existingIds[1]),
558-
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKey(existingIds[2]),
559-
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKey(existingIds[3]),
556+
SaltBuilder.start().lastUpdated(targetDate().minusDays(90)).refreshFrom(willNotRefresh).currentKeySalt(existingIds[0]),
557+
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKeySalt(existingIds[1]),
558+
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKeySalt(existingIds[2]),
559+
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKeySalt(existingIds[3]),
560560
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willRefresh).currentSalt(),
561561
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willRefresh).currentSalt(),
562562
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willRefresh).currentSalt())
@@ -585,9 +585,9 @@ void testKeyRotationPopulatePreviousKey() throws Exception {
585585
var willRefresh = targetDate();
586586
var willNotRefresh = targetDate().plusDays(30);
587587
var lastSnapshot = SaltSnapshotBuilder.start()
588-
.entries(SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willRefresh).currentKey(0, "keyKey", "keySalt"),
589-
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKey(1),
590-
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKey(2))
588+
.entries(SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willRefresh).currentKeySalt(0, "keyKey", "keySalt"),
589+
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKeySalt(1),
590+
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentKeySalt(2))
591591
.build();
592592

593593
var result = saltRotation.rotateSalts(lastSnapshot, minAges, 1, targetDate());
@@ -622,8 +622,8 @@ void testKeyRotationPreviousKeyVisibleFor90Days(int lastUpdatedDaysAgo, boolean
622622
var willRefresh = targetDate();
623623
var willNotRefresh = targetDate().plusDays(30);
624624
var lastSnapshot = SaltSnapshotBuilder.start()
625-
.entries(SaltBuilder.start().lastUpdated(targetDate().minusDays(lastUpdatedDaysAgo)).refreshFrom(willNotRefresh).currentKey(2).previousKey(0),
626-
SaltBuilder.start().lastUpdated(targetDate().minusDays(lastUpdatedDaysAgo)).refreshFrom(willRefresh).currentKey(1)) // for sake of getting snapshot
625+
.entries(SaltBuilder.start().lastUpdated(targetDate().minusDays(lastUpdatedDaysAgo)).refreshFrom(willNotRefresh).currentKeySalt(2).previousKeySalt(0),
626+
SaltBuilder.start().lastUpdated(targetDate().minusDays(lastUpdatedDaysAgo)).refreshFrom(willRefresh).currentKeySalt(1)) // for sake of getting snapshot
627627
.build();
628628

629629
var result = saltRotation.rotateSalts(lastSnapshot, minAges, 1, targetDate());
@@ -644,7 +644,7 @@ void testKeyRotationKeyToSaltRotation() throws Exception {
644644
var willRefresh = targetDate();
645645
var willNotRefresh = targetDate().plusDays(30);
646646
var lastSnapshot = SaltSnapshotBuilder.start()
647-
.entries(SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willRefresh).currentKey(0, "keyKey1", "keySalt1"),
647+
.entries(SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willRefresh).currentKeySalt(0, "keyKey1", "keySalt1"),
648648
SaltBuilder.start().lastUpdated(targetDate().minusDays(60)).refreshFrom(willNotRefresh).currentSalt())
649649
.build();
650650

src/test/java/com/uid2/admin/salt/helper/SaltBuilder.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class SaltBuilder {
1414
private Instant refreshFrom = Instant.now();
1515
private String currentSalt = null;
1616
private String previousSalt = null;
17-
private SaltEntry.KeyMaterial currentKey = null;
18-
private SaltEntry.KeyMaterial previousKey = null;
17+
private SaltEntry.KeyMaterial currentKeySalt = null;
18+
private SaltEntry.KeyMaterial previousKeySalt = null;
1919

2020
private SaltBuilder() {
2121
}
@@ -64,21 +64,21 @@ public SaltBuilder previousSalt(String previousSalt) {
6464
return this;
6565
}
6666

67-
public SaltBuilder currentKey(int keyId) {
68-
return this.currentKey(keyId, "currentKeyKey" + id, "currentKeySalt" + id);
67+
public SaltBuilder currentKeySalt(int keyId) {
68+
return this.currentKeySalt(keyId, "currentKeyKey" + id, "currentKeySalt" + id);
6969
}
7070

71-
public SaltBuilder previousKey(int keyId) {
72-
return this.previousKey(keyId, "previousKeyKey" + id, "previousKeySalt" + id);
71+
public SaltBuilder previousKeySalt(int keyId) {
72+
return this.previousKeySalt(keyId, "previousKeyKey" + id, "previousKeySalt" + id);
7373
}
7474

75-
public SaltBuilder currentKey(int keyId, String key, String salt) {
76-
this.currentKey = new SaltEntry.KeyMaterial(keyId, key, salt);
75+
public SaltBuilder currentKeySalt(int keyId, String key, String salt) {
76+
this.currentKeySalt = new SaltEntry.KeyMaterial(keyId, key, salt);
7777
return this;
7878
}
7979

80-
public SaltBuilder previousKey(int keyId, String key, String salt) {
81-
this.previousKey = new SaltEntry.KeyMaterial(keyId, key, salt);
80+
public SaltBuilder previousKeySalt(int keyId, String key, String salt) {
81+
this.previousKeySalt = new SaltEntry.KeyMaterial(keyId, key, salt);
8282
return this;
8383
}
8484

@@ -90,8 +90,8 @@ public SaltEntry build() {
9090
currentSalt,
9191
refreshFrom.toEpochMilli(),
9292
previousSalt,
93-
currentKey,
94-
previousKey
93+
currentKeySalt,
94+
previousKeySalt
9595
);
9696
}
9797
}

0 commit comments

Comments
 (0)