functions/private/Initialize-SodiumType.ps1

function Initialize-SodiumType {
    if (-not $script:libSodiumPath) {
        $script:libSodiumPath = Find-SodiumLibrary
    }

    if (-not ([System.Management.Automation.PSTypeName]'PSSodium.Sodium').Type) {
        $csharp = @"
using System;
using System.Runtime.InteropServices;
namespace PSSodium {
    public static class Sodium {
        [DllImport("$($script:libSodiumPath)", CallingConvention = CallingConvention.Cdecl)]
        public static extern int crypto_secretbox_easy(byte[] c, byte[] m, ulong mlen, byte[] n, byte[] k);

        [DllImport("$($script:libSodiumPath)", CallingConvention = CallingConvention.Cdecl)]
        public static extern int crypto_secretbox_open_easy(byte[] m, byte[] c, ulong clen, byte[] n, byte[] k);

        [DllImport("$($script:libSodiumPath)", CallingConvention = CallingConvention.Cdecl)]
        public static extern void randombytes_buf(byte[] buf, UIntPtr size);

        public const int NonceBytes = 24;
        public const int KeyBytes = 32;
        public const int MacBytes = 16;
    }
}
"@

        Add-Type -TypeDefinition $csharp -Language CSharp
    }
}