Experiment with asByteArray()
This commit is contained in:
		
							parent
							
								
									8fb4f91374
								
							
						
					
					
						commit
						9751f80347
					
				@ -5,3 +5,12 @@ package com.ionspin.kotlin.crypto.util
 | 
			
		||||
 * ugljesa.jovanovic@ionspin.com
 | 
			
		||||
 * on 22-Jun-2020
 | 
			
		||||
 */
 | 
			
		||||
@Suppress("CAST_NEVER_SUCCEEDS")
 | 
			
		||||
fun ByteArray.asUByteArray() : UByteArray {
 | 
			
		||||
    return this as UByteArray
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Suppress("CAST_NEVER_SUCCEEDS")
 | 
			
		||||
fun UByteArray.asByteArray() : ByteArray {
 | 
			
		||||
    return this as ByteArray
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -214,8 +214,8 @@ class XChaCha20Poly1305Test {
 | 
			
		||||
        val data = UByteArray(100) { 0U }
 | 
			
		||||
        val result = xcha.encrypt(data)
 | 
			
		||||
 | 
			
		||||
//        assertTrue {
 | 
			
		||||
//            expected.contentEquals(result)
 | 
			
		||||
//        }
 | 
			
		||||
        assertTrue {
 | 
			
		||||
            expected.contentEquals(result)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -79,17 +79,25 @@ actual class XChaCha20Poly1305Delegated internal actual constructor() {
 | 
			
		||||
        val ciphertext = ByteArray(1 + data.size + 16)
 | 
			
		||||
        sodium.crypto_secretstream_xchacha20poly1305_push(
 | 
			
		||||
            state, ciphertext, null,
 | 
			
		||||
            data.toByteArray(), data.size.toLong(),
 | 
			
		||||
            additionalData.toByteArray(), additionalData.size.toLong(),
 | 
			
		||||
            data.asByteArray(), data.size.toLong(),
 | 
			
		||||
            additionalData.asByteArray(), additionalData.size.toLong(),
 | 
			
		||||
            0
 | 
			
		||||
        )
 | 
			
		||||
        return ciphertext.toUByteArray()
 | 
			
		||||
        return ciphertext.asUByteArray()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    actual fun decrypt(data: UByteArray, additionalData: UByteArray): UByteArray {
 | 
			
		||||
        val plaintext = ByteArray(data.size - 17)
 | 
			
		||||
 | 
			
		||||
        TODO()
 | 
			
		||||
        sodium.crypto_secretstream_xchacha20poly1305_pull(
 | 
			
		||||
            state, plaintext, null,
 | 
			
		||||
            data.sliceArray(0 until 1).asByteArray(),
 | 
			
		||||
            data.sliceArray(1 until data.size).asByteArray(),
 | 
			
		||||
            (data.size - 17).toLong(),
 | 
			
		||||
            additionalData.asByteArray(),
 | 
			
		||||
            additionalData.size.toLong()
 | 
			
		||||
        )
 | 
			
		||||
        return plaintext.asUByteArray()
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user