Add more tests, fix array when input is aligned
This commit is contained in:
parent
7d3fe70d4d
commit
7e2b52a193
@ -24,4 +24,32 @@ class LibsodiumUtilTest {
|
||||
input.contentEquals(unpadded)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPaddingAligned() {
|
||||
val input = ubyteArrayOf(1U, 2U)
|
||||
val blocksize = 2
|
||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||
println(padded.hexColumsPrint())
|
||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||
println(unpadded.hexColumsPrint())
|
||||
|
||||
assertTrue {
|
||||
input.contentEquals(unpadded)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPaddingMultiblock() {
|
||||
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 6U)
|
||||
val blocksize = 4
|
||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||
println(padded.hexColumsPrint())
|
||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||
println(unpadded.hexColumsPrint())
|
||||
|
||||
assertTrue {
|
||||
input.contentEquals(unpadded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ actual object LibsodiumUtil {
|
||||
val resultingSize = if (unpaddedData.size % blocksize != 0 ) {
|
||||
((unpaddedData.size / blocksize) + 1 ) * blocksize
|
||||
} else {
|
||||
unpaddedData.size + 1
|
||||
unpaddedData.size
|
||||
}
|
||||
val paddedData = UByteArray(resultingSize)
|
||||
unpaddedData.copyInto(paddedData, 0, 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user