diff --git a/plugin-build/plugin/src/main/java/ru/litres/publish/samsung/utils/rsa/Asn1Object.kt b/plugin-build/plugin/src/main/java/ru/litres/publish/samsung/utils/rsa/Asn1Object.kt index e2609cb..62a9d6e 100644 --- a/plugin-build/plugin/src/main/java/ru/litres/publish/samsung/utils/rsa/Asn1Object.kt +++ b/plugin-build/plugin/src/main/java/ru/litres/publish/samsung/utils/rsa/Asn1Object.kt @@ -32,12 +32,10 @@ import java.math.BigInteger * * * @param tag Tag or Identifier - * @param length Length of the field * @param value Encoded octet string for the field. */ open class Asn1Object( private val tag: Int, - private val length: Int, private val value: ByteArray ) { val type: Int = tag and 0x1F @@ -88,10 +86,18 @@ open class Asn1Object( get() { val encoding = when (type) { - DerParser.NUMERIC_STRING, DerParser.PRINTABLE_STRING, DerParser.VIDEOTEX_STRING, DerParser.IA5_STRING, DerParser.GRAPHIC_STRING, DerParser.ISO646_STRING, DerParser.GENERAL_STRING -> "ISO-8859-1" // $NON-NLS-1$ + DerParser.NUMERIC_STRING, + DerParser.PRINTABLE_STRING, + DerParser.VIDEOTEX_STRING, + DerParser.IA5_STRING, + DerParser.GRAPHIC_STRING, + DerParser.ISO646_STRING, + DerParser.GENERAL_STRING -> "ISO-8859-1" // $NON-NLS-1$ DerParser.BMP_STRING -> "UTF-16BE" // $NON-NLS-1$ DerParser.UTF8_STRING -> "UTF-8" // $NON-NLS-1$ - DerParser.UNIVERSAL_STRING -> throw IOException("Invalid DER: can't handle UCS-4 string") // $NON-NLS-1$ + DerParser.UNIVERSAL_STRING -> { + throw IOException("Invalid DER: can't handle UCS-4 string") + } // $NON-NLS-1$ else -> throw IOException("Invalid DER: object is not a string") // $NON-NLS-1$ } return String(value, charset(encoding)) diff --git a/plugin-build/plugin/src/main/java/ru/litres/publish/samsung/utils/rsa/DerParser.kt b/plugin-build/plugin/src/main/java/ru/litres/publish/samsung/utils/rsa/DerParser.kt index 1545dbc..49d7ae7 100644 --- a/plugin-build/plugin/src/main/java/ru/litres/publish/samsung/utils/rsa/DerParser.kt +++ b/plugin-build/plugin/src/main/java/ru/litres/publish/samsung/utils/rsa/DerParser.kt @@ -35,19 +35,20 @@ import java.math.BigInteger * * @author zhang */ +@Suppress("MagicNumber") open class DerParser /** * Create a new DER decoder from an input stream. * - * @param in The DER encoded stream - */(private var `in`: InputStream) { + * @param input The DER encoded stream + */(private var input: InputStream) { /** * Create a new DER decoder from a byte array. * * @param The encoded bytes * @throws IOException */ - constructor(bytes: ByteArray?) : this(ByteArrayInputStream(bytes)) {} + constructor(bytes: ByteArray?) : this(ByteArrayInputStream(bytes)) /** * Read next object. If it's constructed, the value holds @@ -59,13 +60,13 @@ open class DerParser */ @Throws(IOException::class) fun read(): Asn1Object { - val tag = `in`.read() + val tag = input.read() if (tag == -1) throw IOException("Invalid DER: stream too short, missing tag") // $NON-NLS-1$ val length = length val value = ByteArray(length) - val n = `in`.read(value) + val n = input.read(value) if (n < length) throw IOException("Invalid DER: stream too short, missing value") // $NON-NLS-1$ - return Asn1Object(tag, length, value) + return Asn1Object(tag, value) } // $NON-NLS-1$ // $NON-NLS-1$ @@ -97,7 +98,7 @@ open class DerParser @get:Throws(IOException::class) private val length: Int get() { - val i = `in`.read() + val i = input.read() if (i == -1) throw IOException("Invalid DER: length missing") // $NON-NLS-1$ // A single byte short length @@ -107,7 +108,7 @@ open class DerParser // We can't handle length longer than 4 bytes if (i >= 0xFF || num > 4) throw IOException("Invalid DER: length field too big ( $i )") // $NON-NLS-1$ val bytes = ByteArray(num) - val n = `in`.read(bytes) + val n = input.read(bytes) if (n < num) throw IOException("Invalid DER: length too short") // $NON-NLS-1$ return BigInteger(1, bytes).toInt() }