All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jetbrains.kotlin.statistics.AnonymizerUtils.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-Beta1
Show newest version
/*
 * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package org.jetbrains.kotlin.statistics

import java.security.MessageDigest

internal interface ValueAnonymizer {

    fun anonymize(t: T): T

    fun anonymizeOnIdeSize(): Boolean = false

}

internal val salt: String by lazy {
    val env = System.getenv()
    "${env["HOSTNAME"]}${env["COMPUTERNAME"]}"
}

fun anonymizeComponentVersion(version: String): String {
    return version.replace('-', '.')
        .split(".")
        .plus(listOf("0", "0")) // pad with zeros
        .take(3)
        .map { s -> s.toIntOrNull() ?: "0" }
        .joinToString(".")
}

internal fun sha256(s: String): String {
    val md = MessageDigest.getInstance("SHA-256")
    val digest = md.digest(s.toByteArray())
    return digest.fold("", { str, it -> str + "%02x".format(it) })
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy