Skip to content

Commit

Permalink
test: add TestChaCha20
Browse files Browse the repository at this point in the history
  • Loading branch information
netpyoung committed Nov 21, 2021
1 parent b670dd1 commit bade42f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
8 changes: 8 additions & 0 deletions unity.libsodium/Assets/unity.libsodium.test.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions unity.libsodium/Assets/unity.libsodium.test/TestSimple.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace unity.libsodium.test
{
public class TestSimple
{
[Test]
public void TestChaCha20()
{
int x = NativeLibsodium.sodium_init();
Assert.True(x == 0 || x == 1);

const string MESSAGE = "Test message to encrypt";
byte[] nonce = StreamEncryption.GenerateNonceChaCha20();
byte[] key = StreamEncryption.GenerateKey();

//encrypt it
byte[] encrypted = StreamEncryption.EncryptChaCha20(MESSAGE, nonce, key);


//decrypt it
byte[] decrypted = StreamEncryption.DecryptChaCha20(encrypted, nonce, key);

Assert.AreEqual(MESSAGE, decrypted);
}

}
}
11 changes: 11 additions & 0 deletions unity.libsodium/Assets/unity.libsodium.test/TestSimple.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "unity.libsodium.test",
"rootNamespace": "unity.libsodium.test",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"unity.libsodium"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bade42f

Please sign in to comment.