Ensure that every CheatingSecurityProvider has a unique name. (#3835)

This commit is contained in:
Chris Rankin 2018-08-22 11:09:52 +01:00 committed by GitHub
parent 1d05c16942
commit 004ea45a05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,14 +5,15 @@ import java.security.Provider
import java.security.SecureRandom
import java.security.SecureRandomSpi
import java.security.Security
import java.util.concurrent.atomic.AtomicInteger
/**
* Temporarily restore Sun's [SecureRandom] provider.
* This is ONLY for allowing us to generate test data, e.g. signatures.
*/
class CheatingSecurityProvider : Provider(NAME, 1.8, "$NAME security provider"), AutoCloseable {
class CheatingSecurityProvider : Provider("Cheat-${counter.getAndIncrement()}", 1.8, "Cheat security provider"), AutoCloseable {
private companion object {
private const val NAME = "Cheat!"
private val counter = AtomicInteger()
}
init {
@ -21,7 +22,7 @@ class CheatingSecurityProvider : Provider(NAME, 1.8, "$NAME security provider"),
}
override fun close() {
Security.removeProvider(NAME)
Security.removeProvider(name)
}
private class SunSecureRandom : SecureRandom(sun.security.provider.SecureRandom(), null)