Rename class/method/variable names to improve token generation code readability#1080
Rename class/method/variable names to improve token generation code readability#1080
Conversation
…f variables which don't just include tokens
…LevelHashIdentity and RawUidIdentity as UserIdentity is a very vague term and one needs to read function calls to really understand whether the UserIdentity class has hashed DII, first level hash or raw Uid.
2. Rename RefreshToken class to RefreshTokenInput 3. Rename createAdvertisingToken/createRefreshToken methods to createAdvertisingTokenInput/createRefreshTokenInput
…ii/FirstLevelHash/RawUidIdentity sub-classes
…ertisingId to generateRawUid
2. Renamed AdvertisingId to RawUid in most operator codes (except optout store related)
| public IdentityScope identityScope; | ||
| public IdentityType identityType; | ||
| public int privacyBits; | ||
| public Instant establishedAt; | ||
| public Instant refreshedAt; |
There was a problem hiding this comment.
Can we make these final and set them in a protected ctor.
| public IdentityScope GetIdentityScope() { return identityScope; } | ||
| public IdentityType GetIdentityType() { return identityType; } | ||
| public Instant GetEstablishedAt() { return establishedAt; }; | ||
| public Instant GetIRefreshedAt() { return refreshedAt; } |
There was a problem hiding this comment.
- Should start with
get - Why no getter for
privacyBits? - Do we need getters if the fields are public? Or should we keep the getters and make the fields private?
- Typo in
GetIRefreshedAt
| this.identityV3Enabled | ||
| ? TokenUtils.getAdvertisingIdV3(firstLevelHashIdentity.identityScope, firstLevelHashIdentity.identityType, firstLevelHashIdentity.id, rotatingSalt.getSalt()) | ||
| : TokenUtils.getAdvertisingIdV2(firstLevelHashIdentity.id, rotatingSalt.getSalt()), | ||
| ? TokenUtils.getRawUidV3(firstLevelHashIdentity.identityScope, | ||
| firstLevelHashIdentity.identityType, firstLevelHashIdentity.firstLevelHash, rotatingSalt.getSalt()) | ||
| : TokenUtils.getRawUidV2(firstLevelHashIdentity.firstLevelHash, rotatingSalt.getSalt()), |
There was a problem hiding this comment.
Can we introduce a variable here? This is hard to read.
| public static final byte[] ValidateIdentityForEmailHash = EncodingUtils.getSha256Bytes(IdentityConst.ValidateIdentityForEmail); | ||
| public static final byte[] ValidateIdentityForPhoneHash = EncodingUtils.getSha256Bytes(IdentityConst.ValidateIdentityForPhone); | ||
|
|
||
| // DIIs to use when you want to generate a optout response in token generation or identity map |
There was a problem hiding this comment.
Maybe we can add some similar comments for the above/below groups of variables too?
|
|
||
| public IdentityScope GetIdentityScope() { return identityScope; } | ||
| public IdentityType GetIdentityType() { return identityType; } | ||
| public Instant GetEstablishedAt() { return establishedAt; }; |
There was a problem hiding this comment.
removed the get methods for now
| public IdentityScope GetIdentityScope() { return identityScope; } | ||
| public IdentityType GetIdentityType() { return identityType; } | ||
| public Instant GetEstablishedAt() { return establishedAt; }; | ||
| public Instant GetIRefreshedAt() { return refreshedAt; } |
There was a problem hiding this comment.
Extra I after Get
i.e. this should be GetRefreshedAfterAt()
|
|
||
| import java.time.Instant; | ||
|
|
||
| // Contains a hash computed from a raw email/phone number DII input or the hash is provided by the UID Participant |
There was a problem hiding this comment.
I think better to split this into two lines as such:
// Contains a hashed DII
// The hash can either be computed from a raw email/phone number DII input or provided by the UID Participant directly
| import java.time.Instant; | ||
|
|
||
| //base class for all other HshedDii/FirstLevelHash/RawUIDIdentity class and define the basic common fields | ||
| public class UserIdentity { |
There was a problem hiding this comment.
I don't think we're instantiating UserIdentity anymore, so I suggest making this an abstract class, i.e. public abstract class UserIdentity
As for the matches() method, you can also move matches() here as an abstract method and make other classes implement it, i.e. public abstract boolean matches(UserIdentity that);, or use generics on the class type so you can do public abstract boolean matches (T that); if you want to force the input parameter type to be the same as the derived class, but your call on this
There was a problem hiding this comment.
i have made UserIdentity abstract - regarding matches , let me see if i can refactor the codes of the various subclasses first
|
|
||
| // Contains the computed raw UID and its bucket ID from identity/map request | ||
| public class RawUidResult { | ||
| public static RawUidResult OptoutIdentity = new RawUidResult(new byte[33], ""); |
There was a problem hiding this comment.
For public static, the naming convention is capitalized snake case, i.e. public static RawUidResult OPT_OUT_IDENTITY
On a separate note, not a really big deal because I think both make sense, but I noticed we sometimes refer to "optout" as "OptOut" and sometimes as "Optout" - do we want this standardized too?
There was a problem hiding this comment.
i'll keep the convention for now due to reason given above.
I'll note down the Optout/OptOut point - seems they are split 50/50 ish. Not too important in context of this ticket work tho
| public static RefreshResponse Expired = new RefreshResponse(Status.Expired, IdentityTokens.LogoutToken); | ||
| public static RefreshResponse Deprecated = new RefreshResponse(Status.Deprecated, IdentityTokens.LogoutToken); | ||
| public static RefreshResponse NoActiveKey = new RefreshResponse(Status.NoActiveKey, IdentityTokens.LogoutToken); | ||
| public static RefreshResponse Invalid = new RefreshResponse(Status.Invalid, IdentityResponse.OptOutIdentityResponse); |
There was a problem hiding this comment.
Similar comment to the other public static comments, but it should be capitalized snake case here too
| this.webClient.get(remoteApiPort, remoteApiHost, remoteApiPath). | ||
| addQueryParam("identity_hash", EncodingUtils.toBase64String(firstLevelHashIdentity.id)) | ||
| addQueryParam("identity_hash", EncodingUtils.toBase64String(firstLevelHashIdentity.firstLevelHash)) | ||
| .addQueryParam("advertising_id", EncodingUtils.toBase64String(advertisingId)) |
There was a problem hiding this comment.
Do we want to add a comment here that advertising id is equivalent to raw UID?
| final int length = b3.getInt(4); | ||
|
|
||
| final byte[] advertisingId = EncodingUtils.fromBase64(b3.slice(8, 8 + length).getBytes()); | ||
| final byte[] getRawUid = EncodingUtils.fromBase64(b3.slice(8, 8 + length).getBytes()); |
There was a problem hiding this comment.
I think just rawUid is fine here
There was a problem hiding this comment.
fixed also renamed ``idtorawUid``` in decodeAdvertisingTokenV3orV4 method below
| private byte[] encryptIdentityV2(SourcePublisher sourcePublisher, FirstLevelHashIdentity firstLevelHashIdentity, KeysetKey key) { | ||
| return encryptIdentityV2(sourcePublisher, firstLevelHashIdentity.firstLevelHash, firstLevelHashIdentity.privacyBits, | ||
| firstLevelHashIdentity.establishedAt, key); | ||
|
|
2. Renamed RawUidResult to RawUidResponse 3. rename some id variable to rawUid to make it clearer 4. more comments
…xed the UserIdentity/FirstLevelHashIdentity class uses to HashedDiiIdentity instead in IdentityMapBenchmark and TokenEndecBenchmark
methods to encodeIntoAdvertisingToken or encodeIntoRefreshToken to make it clear what we are encoding into
Refer to ticket description on https://atlassian.thetradedesk.com/jira/browse/UID2-4159