fix issue #3: packing error when "algorithm_type = 0"

pull/31/head
cfig 6 years ago
parent ec32a3750a
commit b4f5a2b5b3
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -321,7 +321,7 @@ class Avb {
val alg = Algorithms.get(ai.header!!.algorithm_type.toInt())!!
val encodedDesc = ai.auxBlob!!.encodeDescriptors()
//encoded pubkey
val encodedKey = Blob.encodePubKey(alg, Files.readAllBytes(Paths.get(alg.defaultKey)))
val encodedKey = Blob.encodePubKey(alg)
//3 - whole aux blob
var auxBlob = byteArrayOf()

@ -12,26 +12,18 @@ import java.security.MessageDigest
class Blob {
companion object {
fun encodePubKey(alg: Algorithm): ByteArray {
fun encodePubKey(alg: Algorithm, key: ByteArray? = null): ByteArray {
var encodedKey = byteArrayOf()
var algKey: ByteArray? = key
if (alg.public_key_num_bytes > 0) {
encodedKey = Helper.encodeRSAkey(Files.readAllBytes((Paths.get(alg.defaultKey))))
log.info("encodePubKey(): size = ${alg.public_key_num_bytes}, algorithm key size: ${encodedKey.size}")
Assert.assertEquals(alg.public_key_num_bytes, encodedKey.size)
} else {
log.info("encodePubKey(): No key to encode for algorithm " + alg.name)
}
return encodedKey
if (key == null) {
algKey = Files.readAllBytes((Paths.get(alg.defaultKey)))
}
fun encodePubKey(alg: Algorithm, key: ByteArray): ByteArray {
var encodedKey = byteArrayOf()
if (alg.public_key_num_bytes > 0) {
encodedKey = Helper.encodeRSAkey(key)
encodedKey = Helper.encodeRSAkey(algKey!!)
log.info("encodePubKey(): size = ${alg.public_key_num_bytes}, algorithm key size: ${encodedKey.size}")
Assert.assertEquals(alg.public_key_num_bytes, encodedKey.size)
} else {
log.info("encodePubKey(): No key to use")
log.info("encodePubKey(): No key to encode for algorithm " + alg.name)
}
return encodedKey
}

Loading…
Cancel
Save