aboutsummaryrefslogtreecommitdiff
path: root/back-end/libs/NVault.Crypto.Secp256k1/src/Secp256HashFuncState.cs
blob: 4ee745cac164dbada67f12e1dcc4b7c3f416feae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (C) 2023 Vaughn Nugent
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

using System;
using System.Runtime.InteropServices;

namespace NVault.Crypto.Secp256k1
{
    [StructLayout(LayoutKind.Sequential)]
    public unsafe readonly ref struct Secp256HashFuncState
    {

        /// <summary>
        /// The opaque pointer passed to the hash function
        /// </summary>
        public readonly IntPtr Opaque { get; }

        private readonly byte* _output;
        private readonly byte* _xCoord;
        private readonly int _outputLength;
        private readonly int _xCoordLength;

        internal Secp256HashFuncState(byte* output, int outputLength, byte* xCoord, int xCoordLength, IntPtr opaque)
        {
            Opaque = opaque;
            _output = output;
            _outputLength = outputLength;
            _xCoord = xCoord;
            _xCoordLength = xCoordLength;
        }

        /// <summary>
        /// Gets the output buffer as a span
        /// </summary>
        /// <returns>The output buffer span</returns>
        public readonly Span<byte> GetOutput() => new(_output, _outputLength);

        /// <summary>
        /// Gets the x coordinate argument as a span
        /// </summary>
        /// <returns>The xcoordinate buffer span</returns>
        public readonly ReadOnlySpan<byte> GetXCoordArg() => new(_xCoord, _xCoordLength);
    }
}