Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1171,11 +1171,12 @@ class LightsparkCoroutinesClient private constructor(
return digest.fold(StringBuilder()) { sb, it -> sb.append("%02x".format(it)) }.toString()
}

@OptIn(ExperimentalStdlibApi::class)
fun hashUmaIdentifier(identifier: String, signingPrivateKey: ByteArray): String {
val now = getUtcDateTime()
val input = identifier.toByteArray() + "${now.monthNumber}-${now.year}".toByteArray() + signingPrivateKey
val input = identifier + "${now.monthNumber}-${now.year}" + signingPrivateKey.toHexString()
val md = MessageDigest.getInstance("SHA-256")
val digest = md.digest(input)
val digest = md.digest(input.toByteArray())
return digest.fold(StringBuilder()) { sb, it -> sb.append("%02x".format(it)) }.toString()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class ClientIntegrationTests {

@Test
fun `test uma identifier hashing`() = runTest {
val privKeyBytes = Random.nextBytes(32)
val privKeyBytes = "xyz".toByteArray()
`when`(client.getUtcDateTime()).thenReturn(LocalDateTime(2021, 1, 1, 0, 0, 0))
val hashedUma = client.hashUmaIdentifier("user@domain.com", privKeyBytes)
val hashedUmaSameMonth = client.hashUmaIdentifier("user@domain.com", privKeyBytes)
Expand Down