@ -5,9 +5,11 @@ import dev.openrs2.asm.classpath.Library
import dev.openrs2.crypto.Pkcs12KeyStore
import dev.openrs2.util.io.DeterministicJarOutputStream
import dev.openrs2.util.io.entries
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.nio.file.Files
import java.nio.file.Path
import java.util.jar.JarInputStream
import java.util.jar.Manifest
@ -22,24 +24,24 @@ class SignedJarLibraryWriter(
ManifestJarLibraryWriter ( manifest ) . write ( unsignedOutput , classPath , library )
}
val signedJar = Files . createTempFile ( TEMP _PREFIX , JAR _SUFFIX )
try {
keyStore . signJar ( unsignedJar , signedJar )
repack ( signedJar , output )
} finally {
Files . deleteIfExists ( signedJar )
ByteArrayOutputStream ( ) . use { signedOutput ->
keyStore . signJar ( unsignedJar , signedOutput )
return ByteArrayInputStream ( signedOutput . toByteArray ( ) ) . use { signedInput ->
repack ( signedInput , output )
}
}
} finally {
Files . deleteIfExists ( unsignedJar )
}
}
private fun repack ( signedJar : Path , output : OutputStream ) {
JarInputStream ( F iles . newI nputStream ( signedJar ) ) . use { i nput ->
DeterministicJarOutputStream ( output , i nput. manifest ) . use { o utput ->
for ( entry in i nput. entries ) {
o utput. putNextEntry ( entry )
i nput. copyTo ( o utput)
private fun repack ( input : InputStream , output : OutputStream ) {
JarInputStream ( input ) . use { jarI nput ->
DeterministicJarOutputStream ( output , jarI nput. manifest ) . use { jarO utput ->
for ( entry in jarI nput. entries ) {
jarO utput. putNextEntry ( entry )
jarI nput. copyTo ( jarO utput)
}
}
}