1
1
package com .uid2 .operator .service ;
2
2
3
3
import com .uid2 .operator .model .*;
4
+ import com .uid2 .operator .model .identities .DiiType ;
4
5
import com .uid2 .operator .model .identities .FirstLevelHash ;
6
+ import com .uid2 .operator .model .identities .IdentityScope ;
5
7
import com .uid2 .operator .model .identities .RawUid ;
6
8
import com .uid2 .operator .util .PrivacyBits ;
7
9
import com .uid2 .operator .vertx .ClientInputValidationException ;
@@ -69,7 +71,7 @@ private byte[] encodeIntoAdvertisingTokenV3(AdvertisingTokenRequest t, KeysetKey
69
71
masterPayload .appendBytes (AesGcm .encrypt (sitePayload .getBytes (), siteKey ).getPayload ());
70
72
71
73
final Buffer b = Buffer .buffer (164 );
72
- b .appendByte (encodeIdentityTypeV3 (t .rawUid .identityScope (), t .rawUid .identityType ()));
74
+ b .appendByte (encodeIdentityTypeV3 (t .rawUid .identityScope (), t .rawUid .diiType ()));
73
75
b .appendByte ((byte ) t .version .rawVersion );
74
76
b .appendInt (masterKey .getId ());
75
77
b .appendBytes (AesGcm .encrypt (masterPayload .getBytes (), masterKey ).getPayload ());
@@ -129,7 +131,7 @@ private TokenRefreshRequest decodeRefreshTokenV2(Buffer b) {
129
131
TokenVersion .V2 , createdAt , validTill ,
130
132
new OperatorIdentity (0 , OperatorType .Service , 0 , 0 ),
131
133
new SourcePublisher (siteId ),
132
- new FirstLevelHash (IdentityScope .UID2 , IdentityType .Email , identity ,
134
+ new FirstLevelHash (IdentityScope .UID2 , DiiType .Email , identity ,
133
135
Instant .ofEpochMilli (establishedMillis )),
134
136
privacyBits );
135
137
}
@@ -152,19 +154,19 @@ private TokenRefreshRequest decodeRefreshTokenV3(Buffer b, byte[] bytes) {
152
154
final PrivacyBits privacyBits = PrivacyBits .fromInt (b2 .getInt (45 ));
153
155
final Instant establishedAt = Instant .ofEpochMilli (b2 .getLong (49 ));
154
156
final IdentityScope identityScope = decodeIdentityScopeV3 (b2 .getByte (57 ));
155
- final IdentityType identityType = decodeIdentityTypeV3 (b2 .getByte (57 ));
157
+ final DiiType diiType = decodeIdentityTypeV3 (b2 .getByte (57 ));
156
158
final byte [] firstLevelHash = b2 .getBytes (58 , 90 );
157
159
158
160
if (identityScope != decodeIdentityScopeV3 (b .getByte (0 ))) {
159
161
throw new ClientInputValidationException ("Failed to decode refreshTokenV3: Identity scope mismatch" );
160
162
}
161
- if (identityType != decodeIdentityTypeV3 (b .getByte (0 ))) {
163
+ if (diiType != decodeIdentityTypeV3 (b .getByte (0 ))) {
162
164
throw new ClientInputValidationException ("Failed to decode refreshTokenV3: Identity type mismatch" );
163
165
}
164
166
165
167
return new TokenRefreshRequest (
166
168
TokenVersion .V3 , createdAt , expiresAt , operatorIdentity , sourcePublisher ,
167
- new FirstLevelHash (identityScope , identityType , firstLevelHash , establishedAt ),
169
+ new FirstLevelHash (identityScope , diiType , firstLevelHash , establishedAt ),
168
170
privacyBits );
169
171
}
170
172
@@ -233,7 +235,7 @@ public AdvertisingTokenRequest decodeAdvertisingTokenV2(Buffer b) {
233
235
Instant .ofEpochMilli (expiresMillis ),
234
236
new OperatorIdentity (0 , OperatorType .Service , 0 , masterKeyId ),
235
237
new SourcePublisher (siteId , siteKeyId , 0 ),
236
- new RawUid (IdentityScope .UID2 , IdentityType .Email , rawUid ),
238
+ new RawUid (IdentityScope .UID2 , DiiType .Email , rawUid ),
237
239
privacyBits ,
238
240
Instant .ofEpochMilli (establishedMillis )
239
241
);
@@ -262,21 +264,21 @@ public AdvertisingTokenRequest decodeAdvertisingTokenV3orV4(Buffer b, byte[] byt
262
264
final Instant refreshedAt = Instant .ofEpochMilli (sitePayload .getLong (28 ));
263
265
final byte [] rawUid = sitePayload .slice (36 , sitePayload .length ()).getBytes ();
264
266
final IdentityScope identityScope = rawUid .length == 32 ? IdentityScope .UID2 : decodeIdentityScopeV3 (rawUid [0 ]);
265
- final IdentityType identityType = rawUid .length == 32 ? IdentityType .Email : decodeIdentityTypeV3 (rawUid [0 ]);
267
+ final DiiType diiType = rawUid .length == 32 ? DiiType .Email : decodeIdentityTypeV3 (rawUid [0 ]);
266
268
267
269
if (rawUid .length > 32 )
268
270
{
269
271
if (identityScope != decodeIdentityScopeV3 (b .getByte (0 ))) {
270
272
throw new ClientInputValidationException ("Failed decoding advertisingTokenV3: Identity scope mismatch" );
271
273
}
272
- if (identityType != decodeIdentityTypeV3 (b .getByte (0 ))) {
274
+ if (diiType != decodeIdentityTypeV3 (b .getByte (0 ))) {
273
275
throw new ClientInputValidationException ("Failed decoding advertisingTokenV3: Identity type mismatch" );
274
276
}
275
277
}
276
278
277
279
return new AdvertisingTokenRequest (
278
280
tokenVersion , createdAt , expiresAt , operatorIdentity , sourcePublisher ,
279
- new RawUid (identityScope , identityType , rawUid ),
281
+ new RawUid (identityScope , diiType , rawUid ),
280
282
privacyBits , establishedAt
281
283
);
282
284
}
@@ -326,11 +328,11 @@ public byte[] encodeIntoRefreshTokenV3(TokenRefreshRequest t, KeysetKey serviceK
326
328
encodePublisherRequesterV3 (refreshPayload , t .sourcePublisher );
327
329
refreshPayload .appendInt (t .privacyBits .getAsInt ());
328
330
refreshPayload .appendLong (t .firstLevelHash .establishedAt ().toEpochMilli ());
329
- refreshPayload .appendByte (encodeIdentityTypeV3 (t .firstLevelHash .identityScope (), t .firstLevelHash .identityType ()));
331
+ refreshPayload .appendByte (encodeIdentityTypeV3 (t .firstLevelHash .identityScope (), t .firstLevelHash .diiType ()));
330
332
refreshPayload .appendBytes (t .firstLevelHash .firstLevelHash ());
331
333
332
334
final Buffer b = Buffer .buffer (124 );
333
- b .appendByte (encodeIdentityTypeV3 (t .firstLevelHash .identityScope (), t .firstLevelHash .identityType ()));
335
+ b .appendByte (encodeIdentityTypeV3 (t .firstLevelHash .identityScope (), t .firstLevelHash .diiType ()));
334
336
b .appendByte ((byte ) t .version .rawVersion );
335
337
b .appendInt (serviceKey .getId ());
336
338
b .appendBytes (AesGcm .encrypt (refreshPayload .getBytes (), serviceKey ).getPayload ());
@@ -402,17 +404,17 @@ private byte[] encryptIdentityV2(SourcePublisher sourcePublisher, byte[] id, Pri
402
404
}
403
405
}
404
406
405
- static private byte encodeIdentityTypeV3 (IdentityScope identityScope , IdentityType identityType ) {
406
- return (byte ) (TokenUtils .encodeIdentityScope (identityScope ) | (identityType .value << 2 ) | 3 );
407
+ static private byte encodeIdentityTypeV3 (IdentityScope identityScope , DiiType diiType ) {
408
+ return (byte ) (TokenUtils .encodeIdentityScope (identityScope ) | (diiType .value << 2 ) | 3 );
407
409
// "| 3" is used so that the 2nd char matches the version when V3 or higher. Eg "3" for V3 and "4" for V4
408
410
}
409
411
410
412
static private IdentityScope decodeIdentityScopeV3 (byte value ) {
411
413
return IdentityScope .fromValue ((value & 0x10 ) >> 4 );
412
414
}
413
415
414
- static private IdentityType decodeIdentityTypeV3 (byte value ) {
415
- return IdentityType .fromValue ((value & 0xf ) >> 2 );
416
+ static private DiiType decodeIdentityTypeV3 (byte value ) {
417
+ return DiiType .fromValue ((value & 0xf ) >> 2 );
416
418
}
417
419
418
420
static void encodePublisherRequesterV3 (Buffer b , SourcePublisher sourcePublisher ) {
0 commit comments