Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin Base64-encoding #8317

Merged
merged 3 commits into from
Feb 20, 2024
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
14 changes: 0 additions & 14 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.gradle.accessors.dm.LibrariesForLibs

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

private val Project.libs: LibrariesForLibs
get() = extensions.getByType()
Expand Down Expand Up @@ -56,15 +54,3 @@ tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = maxKotlinJvmTarget.target
targetCompatibility = maxKotlinJvmTarget.target
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlin.ExperimentalStdlibApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
languageVersion = KotlinVersion.KOTLIN_1_9
jvmTarget = maxKotlinJvmTarget
}
}
16 changes: 10 additions & 6 deletions buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ detekt {

val javaVersion = JavaVersion.current()
val maxKotlinJvmTarget = runCatching { JvmTarget.fromTarget(javaVersion.majorVersion) }
.getOrDefault(JvmTarget.entries.max())
.getOrDefault(enumValues<JvmTarget>().max())

val mergeDetektReportsTaskName = "mergeDetektReports"
val mergeDetektReports = if (rootProject.tasks.findByName(mergeDetektReportsTaskName) != null) {
Expand Down Expand Up @@ -157,11 +157,15 @@ tasks.withType<JavaCompile>().configureEach {
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlin.contracts.ExperimentalContracts",
"-opt-in=kotlin.io.path.ExperimentalPathApi",
"-opt-in=kotlin.time.ExperimentalTime"
)
val hasSerialization = plugins.hasPlugin(libs.plugins.kotlinSerialization.get().pluginId)

val customCompilerArgs = buildList {
add("-opt-in=kotlin.contracts.ExperimentalContracts")
add("-opt-in=kotlin.io.encoding.ExperimentalEncodingApi")
add("-opt-in=kotlin.io.path.ExperimentalPathApi")
add("-opt-in=kotlin.time.ExperimentalTime")
if (hasSerialization) add("-opt-in=kotlinx.serialization.ExperimentalSerializationApi")
}

compilerOptions {
allWarningsAsErrors = true
Expand Down
12 changes: 0 additions & 12 deletions clients/clearly-defined/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -36,13 +34,3 @@ dependencies {
implementation(libs.retrofit.converter.kotlinxSerialization)
implementation(libs.retrofit.converter.scalars)
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
19 changes: 9 additions & 10 deletions clients/fossid-webapp/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
package org.ossreviewtoolkit.clients.fossid

import java.io.File
import java.util.Base64

import kotlin.io.encoding.Base64

import okio.buffer
import okio.sink
Expand All @@ -41,8 +42,6 @@ internal const val SCAN_GROUP = "scans"
private const val FILES_AND_FOLDERS_GROUP = "files_and_folders"
private const val PROJECT_GROUP = "projects"

private val base64Encoder = Base64.getEncoder()

/**
* Verify that a request for the given [operation] was successful. [operation] is a free label describing the operation.
* If [withDataCheck] is true, also the payload data is checked, otherwise that check is skipped.
Expand Down Expand Up @@ -260,7 +259,7 @@ suspend fun FossIdRestService.listSnippets(
scanCode: String,
path: String
): PolymorphicResponseBody<Snippet> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val base64Path = Base64.encode(path.toByteArray())
return listSnippets(
PostRequestBody(
"get_fossid_results",
Expand All @@ -285,7 +284,7 @@ suspend fun FossIdRestService.listMatchedLines(
path: String,
snippetId: Int
): EntityResponseBody<MatchedLines> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val base64Path = Base64.encode(path.toByteArray())
return listMatchedLines(
PostRequestBody(
"get_matched_lines",
Expand Down Expand Up @@ -463,7 +462,7 @@ suspend fun FossIdRestService.markAsIdentified(
path: String,
isDirectory: Boolean
): EntityResponseBody<Nothing> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val base64Path = Base64.encode(path.toByteArray())
val directoryFlag = if (isDirectory) "1" else "0"
return markAsIdentified(
PostRequestBody(
Expand All @@ -488,7 +487,7 @@ suspend fun FossIdRestService.unmarkAsIdentified(
path: String,
isDirectory: Boolean
): EntityResponseBody<Nothing> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val base64Path = Base64.encode(path.toByteArray())
val directoryFlag = if (isDirectory) "1" else "0"
return unmarkAsIdentified(
PostRequestBody(
Expand All @@ -515,7 +514,7 @@ suspend fun FossIdRestService.addLicenseIdentification(
identificationOn: LicenseMatchType,
isDirectory: Boolean
): EntityResponseBody<Nothing> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val base64Path = Base64.encode(path.toByteArray())
val directoryFlag = if (isDirectory) "1" else "0"
return addLicenseIdentification(
PostRequestBody(
Expand Down Expand Up @@ -552,7 +551,7 @@ suspend fun FossIdRestService.addComponentIdentification(
isDirectory: Boolean,
preserveExistingIdentifications: Boolean = true
): EntityResponseBody<Nothing> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val base64Path = Base64.encode(path.toByteArray())
val directoryFlag = if (isDirectory) "1" else "0"
val preserveExistingIdentificationsFlag = if (preserveExistingIdentifications) "1" else "0"
return addComponentIdentification(
Expand Down Expand Up @@ -587,7 +586,7 @@ suspend fun FossIdRestService.addFileComment(
isImportant: Boolean = false,
includeInReport: Boolean = false
): EntityResponseBody<Nothing> {
val base64Path = base64Encoder.encodeToString(path.toByteArray())
val base64Path = Base64.encode(path.toByteArray())
val isImportantFlag = if (isImportant) "1" else "0"
val includeInReportFlag = if (includeInReport) "1" else "0"
return addFileComment(
Expand Down
12 changes: 0 additions & 12 deletions clients/nexus-iq/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -34,13 +32,3 @@ dependencies {
implementation(libs.bundles.kotlinxSerialization)
implementation(libs.retrofit.converter.kotlinxSerialization)
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions clients/osv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -37,13 +35,3 @@ dependencies {

testImplementation(libs.kotest.assertions.json)
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions clients/scanoss/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -36,13 +34,3 @@ dependencies {

testImplementation(libs.wiremock)
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions clients/vulnerable-code/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -34,13 +32,3 @@ dependencies {
implementation(libs.bundles.kotlinxSerialization)
implementation(libs.retrofit.converter.kotlinxSerialization)
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions evaluator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import de.undercouch.gradle.tasks.download.Download

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -45,16 +43,6 @@ dependencies {
testImplementation(libs.mockk)
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}

tasks.register<Download>("updateOsadlMatrix") {
description = "Download the OSADL matrix in JSON format and add it as a resource."
group = "OSADL"
Expand Down
7 changes: 4 additions & 3 deletions model/src/main/kotlin/Hash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize
import com.fasterxml.jackson.databind.util.StdConverter

import java.io.File
import java.util.Base64

import kotlin.io.encoding.Base64

import org.ossreviewtoolkit.utils.common.decodeHex
import org.ossreviewtoolkit.utils.common.encodeHex
Expand Down Expand Up @@ -59,7 +60,7 @@ data class Hash(
// Support Subresource Integrity (SRI) hashes, see
// https://w3c.github.io/webappsec-subresource-integrity/
Hash(
value = Base64.getDecoder().decode(splitValue.last()).encodeHex(),
value = Base64.decode(splitValue.last()).encodeHex(),
algorithm = HashAlgorithm.fromString(splitValue.first())
)
} else {
Expand All @@ -82,7 +83,7 @@ data class Hash(
/**
* Return the hash in Support Subresource Integrity (SRI) format.
*/
fun toSri() = algorithm.name.lowercase() + "-" + Base64.getEncoder().encodeToString(value.decodeHex())
fun toSri() = algorithm.name.lowercase() + "-" + Base64.encode(value.decodeHex())

/**
* Verify that the [file] matches this hash.
Expand Down
12 changes: 0 additions & 12 deletions plugins/advisors/osv/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -35,13 +33,3 @@ dependencies {
implementation(libs.cvssCalculator)
implementation(libs.bundles.kotlinxSerialization)
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/package-managers/cargo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand Down Expand Up @@ -47,13 +45,3 @@ dependencies {

funTestImplementation(testFixtures(projects.analyzer))
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/package-managers/go/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand Down Expand Up @@ -47,13 +45,3 @@ dependencies {

funTestImplementation(testFixtures(projects.analyzer))
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
12 changes: 0 additions & 12 deletions plugins/package-managers/nuget/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* License-Filename: LICENSE
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply precompiled plugins.
id("ort-library-conventions")
Expand All @@ -41,13 +39,3 @@ dependencies {

funTestImplementation(testFixtures(projects.analyzer))
}

tasks.withType<KotlinCompile>().configureEach {
val customCompilerArgs = listOf(
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi"
)

compilerOptions {
freeCompilerArgs.addAll(customCompilerArgs)
}
}
Loading
Loading