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,10 +12,14 @@ 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))))
if (key == null) {
algKey = Files.readAllBytes((Paths.get(alg.defaultKey)))
}
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 {
@ -24,18 +28,6 @@ class Blob {
return encodedKey
}
fun encodePubKey(alg: Algorithm, key: ByteArray): ByteArray {
var encodedKey = byteArrayOf()
if (alg.public_key_num_bytes > 0) {
encodedKey = Helper.encodeRSAkey(key)
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")
}
return encodedKey
}
//TODO: support pkmd_blob
//encoded_descriptors + encoded_key + pkmd_blob + (padding)
fun getAuxDataBlob(encodedDesc: ByteArray, encodedKey: ByteArray): ByteArray {

Loading…
Cancel
Save