diff --git a/Cargo.lock b/Cargo.lock index dce94446..0a09f10b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -475,11 +475,10 @@ dependencies = [ [[package]] name = "diplomat" -version = "0.5.2" -source = "git+https://github.com/CBenoit/diplomat.git?rev=f4d93d57e93025c57e75e9711d2418faa9311a42#f4d93d57e93025c57e75e9711d2418faa9311a42" +version = "0.15.0" +source = "git+https://github.com/irvingoujAtDevolution/diplomat.git?rev=68bccfd8d61e146673ccdb2b24bd9f89dc25431c#68bccfd8d61e146673ccdb2b24bd9f89dc25431c" dependencies = [ "diplomat_core", - "lazy_static", "proc-macro2", "quote", "syn 2.0.117", @@ -487,20 +486,19 @@ dependencies = [ [[package]] name = "diplomat-runtime" -version = "0.5.2" -source = "git+https://github.com/CBenoit/diplomat.git?rev=f4d93d57e93025c57e75e9711d2418faa9311a42#f4d93d57e93025c57e75e9711d2418faa9311a42" +version = "0.15.1" +source = "git+https://github.com/irvingoujAtDevolution/diplomat.git?rev=68bccfd8d61e146673ccdb2b24bd9f89dc25431c#68bccfd8d61e146673ccdb2b24bd9f89dc25431c" [[package]] name = "diplomat_core" -version = "0.5.2" -source = "git+https://github.com/CBenoit/diplomat.git?rev=f4d93d57e93025c57e75e9711d2418faa9311a42#f4d93d57e93025c57e75e9711d2418faa9311a42" +version = "0.15.0" +source = "git+https://github.com/irvingoujAtDevolution/diplomat.git?rev=68bccfd8d61e146673ccdb2b24bd9f89dc25431c#68bccfd8d61e146673ccdb2b24bd9f89dc25431c" dependencies = [ - "lazy_static", "proc-macro2", "quote", "serde", "smallvec", - "strck_ident", + "strck", "syn 2.0.117", ] @@ -1139,12 +1137,6 @@ dependencies = [ "cpufeatures 0.3.0", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "leb128fmt" version = "0.1.0" @@ -2119,17 +2111,10 @@ checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" [[package]] name = "strck" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be91090ded9d8f979d9fe921777342d37e769e0b6b7296843a7a38247240e917" - -[[package]] -name = "strck_ident" -version = "0.1.2" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1c3802b169b3858a44667f221c9a0b3136e6019936ea926fc97fbad8af77202" +checksum = "42316e70da376f3d113a68d138a60d8a9883c604fe97942721ec2068dab13a9f" dependencies = [ - "strck", "unicode-ident", ] diff --git a/ffi/Cargo.toml b/ffi/Cargo.toml index 7d31c4b6..cf5edff3 100644 --- a/ffi/Cargo.toml +++ b/ffi/Cargo.toml @@ -25,8 +25,8 @@ rand = "0.10" rand_core = "0.10" # FFI -diplomat = { git = "https://github.com/CBenoit/diplomat.git", rev = "f4d93d57e93025c57e75e9711d2418faa9311a42" } -diplomat-runtime = { git = "https://github.com/CBenoit/diplomat.git", rev = "f4d93d57e93025c57e75e9711d2418faa9311a42" } +diplomat = { git = "https://github.com/irvingoujAtDevolution/diplomat.git", rev = "68bccfd8d61e146673ccdb2b24bd9f89dc25431c" } +diplomat-runtime = { git = "https://github.com/irvingoujAtDevolution/diplomat.git", rev = "68bccfd8d61e146673ccdb2b24bd9f89dc25431c" } time = "0.3" hex = "0.4" diff --git a/ffi/dotnet-interop-conf.toml b/ffi/dotnet-interop-conf.toml index 4c8f9e37..ab717ef0 100644 --- a/ffi/dotnet-interop-conf.toml +++ b/ffi/dotnet-interop-conf.toml @@ -1,10 +1,7 @@ +[dotnet] namespace = "Devolutions.Picky" -native_lib = "DevolutionsPicky" - -[exceptions] -trim_suffix = "Error" -error_message_method = "ToDisplay" - -[properties] -setters_prefix = "set_" -getters_prefix = "get_" +native-lib = "DevolutionsPicky" +exception-trim-suffix = "Error" +exception-message-method = "ToDisplay" +getters-prefix = "get_" +setters-prefix = "set_" diff --git a/ffi/dotnet/Devolutions.Picky.Net48Tests/Devolutions.Picky.Net48Tests.csproj b/ffi/dotnet/Devolutions.Picky.Net48Tests/Devolutions.Picky.Net48Tests.csproj new file mode 100644 index 00000000..89e9f2da --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky.Net48Tests/Devolutions.Picky.Net48Tests.csproj @@ -0,0 +1,54 @@ + + + + + + net48;net10.0 + latest + enable + false + true + x64 + x64 + Devolutions.Picky.Net48Tests + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + Generated\%(Filename)%(Extension) + + + Addons\%(Filename)%(Extension) + + + + + + + DevolutionsPicky.dll + PreserveNewest + + + + diff --git a/ffi/dotnet/Devolutions.Picky.Net48Tests/FfiMarshallingTests.cs b/ffi/dotnet/Devolutions.Picky.Net48Tests/FfiMarshallingTests.cs new file mode 100644 index 00000000..9bcf169e --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky.Net48Tests/FfiMarshallingTests.cs @@ -0,0 +1,217 @@ +using System; + +using Xunit; + +namespace Devolutions.Picky.Net48Tests; + +// These tests deliberately run on .NET Framework 4.8. The point isn't to +// re-test picky's crypto — it's to prove that every *shape* of value crossing +// the FFI boundary marshals correctly under the legacy CLR, which is where the +// old by-value Result struct used to break. Each test is labelled with the +// marshalling shape it exercises. +public class FfiMarshallingTests +{ + // A real RSA key so we can exercise the RSA-only paths without paying for key generation. + private const string RsaPrivateKeyPem = @"-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDkrPiL/5dmGIT5 +/KuC3H/jIjeLoLoddsLhAlikO5JQQo3Zs71GwT4Wd2z8WLMe0lVZu/Jr2S28p0M8 +F3Lnz4IgzjocQomFgucFWWQRyD03ZE2BHfEeelFsp+/4GZaM6lKZauYlIMtjR1vD +lflgvxNTr0iaii4JR9K3IKCunCRy1HQYPcZ9waNtlG5xXtW9Uf1tLWPJpP/3I5HL +M85JPBv4r286vpeUlfQIa/NB4g5w6KZ6MfEAIU4KeEQpeLAyyYvwUzPR2uQZ4y4I +4Nj84dWYB1cMTlSGugvSgOFKYit1nwLGeA7EevVYPbILRfSMBU/+avGNJJ8HCaaq +FIyY42W9AgMBAAECggEBAImsGXcvydaNrIFUvW1rkxML5qUJfwN+HJWa9ALsWoo3 +h28p5ypR7S9ZdyP1wuErgHcl0C1d80tA6BmlhGhLZeyaPCIHbQQUa0GtL7IE+9X9 +bSvu+tt+iMcB1FdqEFmGOXRkB2sS82Ax9e0qvZihcOFRBkUEK/MqapIV8qctGkSG +wIE6yn5LHRls/fJU8BJeeqJmYpuWljipwTkp9hQ7SdRYFLNjwjlz/b0hjmgFs5QZ +LUNMyTHdHtXQHNsf/GayRUAKf5wzN/jru+nK6lMob2Ehfx9/RAfgaDHzy5BNFMj0 +i9+sAycgIW1HpTuDvSEs3qP26NeQ82GbJzATmdAKa4ECgYEA9Vti0YG+eXJI3vdS +uXInU0i1SY4aEG397OlGMwh0yQnp2KGruLZGkTvqxG/Adj1ObDyjFH9XUhMrd0za +Nk/VJFybWafljUPcrfyPAVLQLjsBfMg3Y34sTF6QjUnhg49X2jfvy9QpC5altCtA +46/KVAGREnQJ3wMjfGGIFP8BUZsCgYEA7phYE/cYyWg7a/o8eKOFGqs11ojSqG3y +0OE7kvW2ugUuy3ex+kr19Q/8pOWEc7M1UEV8gmc11xgB70EhIFt9Jq379H0X4ahS ++mgLiPzKAdNCRPpkxwwN9HxFDgGWoYcgMplhoAmg9lWSDuE1Exy8iu5inMWuF4MT +/jG+cLnUZ4cCgYAfMIXIUjDvaUrAJTp73noHSUfaWNkRW5oa4rCMzjdiUwNKCYs1 +yN4BmldGr1oM7dApTDAC7AkiotM0sC1RGCblH2yUIha5NXY5G9Dl/yv9pHyU6zK3 +UBO7hY3kmA611aP6VoACLi8ljPn1hEYUa4VR1n0llmCm29RH/HH7EUuOnwKBgExH +OCFp5eq+AAFNRvfqjysvgU7M/0wJmo9c8obRN1HRRlyWL7gtLuTh74toNSgoKus2 +y8+E35mce0HaOJT3qtMq3FoVhAUIoz6a9NUevBZJS+5xfraEDBIViJ4ps9aANLL4 +hlV7vpICWWeYaDdsAHsKK0yjhjzOEx45GQFA578RAoGBAOB42BG53tL0G9pPeJPt +S2LM6vQKeYx+gXTk6F335UTiiC8t0CgNNQUkW105P/SdpCTTKojAsOPMKOF7z4mL +lj/bWmNq7xu9uVOcBKrboVFGO/n6FXyWZxHPOTdjTkpe8kvvmSwl2iaTNllvSr46 +Z/fDKMxHxeXla54kfV+HiGkH +-----END PRIVATE KEY-----"; + + // Result, E> returning an opaque object — the shape that used to + // break: a by-value struct carrying a pointer union + discriminant. + [Fact] + public void ResultReturningObject_Ec() + { + using PrivateKey key = PrivateKey.GenerateEc(EcCurve.NistP256); + Assert.Equal(KeyKind.Ec, key.Kind); + Assert.Equal(KeyKind.Ec, key.GetKind()); + } + + [Fact] + public void ResultReturningObject_Ed() + { + using PrivateKey key = PrivateKey.GenerateEd(EdAlgorithm.Ed25519, false); + Assert.Equal(KeyKind.Ed, key.Kind); + } + + [Fact] + public void ResultReturningObject_FromPem_Rsa() + { + using Pem pem = Pem.Parse(RsaPrivateKeyPem); + using PrivateKey key = PrivateKey.FromPem(pem); + Assert.Equal(KeyKind.Rsa, key.Kind); + + using PublicKey pub = key.ToPublicKey(); + Assert.Equal(KeyKind.Rsa, pub.Kind); + } + + // Result<(), E> — the void-success arm. + [Fact] + public void ResultReturningVoid_SignatureVerifyFailsCleanly() + { + using Pem pem = Pem.Parse(RsaPrivateKeyPem); + using PrivateKey priv = PrivateKey.FromPem(pem); + using PublicKey pub = priv.ToPublicKey(); + using SignatureAlgorithm alg = SignatureAlgorithm.NewRsaPkcs1v15(HashAlgorithm.Sha2256); + + // A bogus signature must surface as a PickyException, not a crash. + Assert.Throws(() => + alg.Verify(pub, new byte[] { 1, 2, 3 }, new byte[] { 9, 9, 9 })); + } + + // Result — a scalar success arm (long). + [Fact] + public void ResultReturningPrimitive_UtcDateTimestamp() + { + using UtcDate date = UtcDate.FromTimestamp(1_600_000_000); + Assert.Equal(1_600_000_000, date.Timestamp); + Assert.Equal(1_600_000_000, date.GetTimestamp()); + } + + // Result via a DiplomatWrite out-param — the string-return shape. + [Fact] + public void ResultReturningString_PemRoundTrip() + { + byte[] payload = { 0xDE, 0xAD, 0xBE, 0xEF }; + using Pem pem = Pem.New("TEST DATA", payload); + + string repr = pem.ToRepr(); + Assert.Contains("TEST DATA", repr); + + Assert.Equal("TEST DATA", pem.Label); + Assert.Equal("TEST DATA", pem.GetLabel()); + } + + // Hand-written addon returning byte[] (Pem.ToData / PublicKey.ToPkcs1). + [Fact] + public void AddonReturningByteArray_RoundTrip() + { + byte[] payload = { 1, 2, 3, 4, 5 }; + using Pem pem = Pem.New("BLOB", payload); + Assert.Equal(payload, pem.ToData()); + Assert.Equal((ulong)payload.Length, pem.DataLength); + } + + [Fact] + public void AddonReturningByteArray_Pkcs1() + { + using Pem pem = Pem.Parse(RsaPrivateKeyPem); + using PrivateKey priv = PrivateKey.FromPem(pem); + using PublicKey pub = priv.ToPublicKey(); + byte[] pkcs1 = pub.ToPkcs1(); + Assert.NotEmpty(pkcs1); + } + + // Option> — nullable opaque return. + [Fact] + public void OptionReturningObject_UtcDateYmd() + { + UtcDate? valid = UtcDate.Ymd(2020, 1, 1); + Assert.NotNull(valid); + using (valid) + { + Assert.Equal((ushort)2020, valid!.Year); + } + + UtcDate? invalid = UtcDate.Ymd(2020, 13, 40); + Assert.Null(invalid); + } + + // Enum passed in and returned by value across the boundary. + [Fact] + public void EnumByValue_HashAlgorithm() + { + using SignatureAlgorithm ecdsa = SignatureAlgorithm.NewEcdsa(HashAlgorithm.Sha2256); + Assert.NotNull(ecdsa); + } + + // Result through a longer pipeline (Argon2 password hashing). + [Fact] + public void ResultReturningString_Argon2() + { + using Argon2Params parameters = Argon2Params.New(); + parameters.SetMCost(8); + parameters.SetTCost(1); + parameters.SetPCost(1); + parameters.SetOutputLen(32); + + using Argon2 argon2 = Argon2.New(Argon2Algorithm.Argon2id, parameters); + string hash = argon2.HashPassword("correct horse battery staple"); + Assert.StartsWith("$argon2", hash); + } + + // Full JWT encode/decode: builder setters (now methods), string returns, + // and object Results all in one flow. + [Fact] + public void JwtEncodeDecodeRoundTrip() + { + const string claims = "{\"sub\":\"net48\",\"admin\":true}"; + + using PrivateKey priv = PrivateKey.GenerateEc(EcCurve.NistP256); + + using JwtSigBuilder builder = JwtSig.Builder(); + builder.SetAlgorithm(JwsAlg.Es256); + builder.SetContentType("AUTH"); + builder.SetClaims(claims); + + using JwtSig signed = builder.Build(); + string compact = signed.Encode(priv); + Assert.False(string.IsNullOrEmpty(compact)); + + using JwtSig decoded = JwtSig.DecodeUnchecked(compact); + Assert.Equal("AUTH", decoded.ContentType); + Assert.Contains("net48", decoded.Claims); + } + + // VecU8: FromBytes, a value-return property, and Fill into a caller buffer + // (Result<(), Box> — the buffer-too-small error path). + [Fact] + public void VecU8_FillAndLength() + { + byte[] source = { 10, 20, 30, 40 }; + using VecU8 vec = VecU8.FromBytes(source); + Assert.Equal((ulong)source.Length, (ulong)vec.Length); + + byte[] buffer = new byte[source.Length]; + vec.Fill(buffer); + Assert.Equal(source, buffer); + + Assert.Throws(() => vec.Fill(new byte[1])); + } + + // The error arm: a bad parse must come back as a typed PickyException whose + // payload (an opaque PickyError) is itself readable across the boundary. + [Fact] + public void ErrorArm_CarriesReadablePickyError() + { + PickyException ex = Assert.Throws(() => Pem.Parse("not a pem at all")); + Assert.NotNull(ex.Inner); + Assert.False(string.IsNullOrEmpty(ex.Inner.ToDisplay())); + // Kind is an enum getter property on the error opaque. + _ = ex.Inner.Kind; + } +} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AesAuthEncParams.cs b/ffi/dotnet/Devolutions.Picky/Generated/AesAuthEncParams.cs index 79f0e6e0..f67fdf2b 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AesAuthEncParams.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AesAuthEncParams.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,28 +10,60 @@ namespace Devolutions.Picky; public partial class AesAuthEncParams: IDisposable { - private unsafe Raw.AesAuthEncParams* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AesAuthEncParams.Destroy; /// /// Creates a managed AesAuthEncParams from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AesAuthEncParams(Raw.AesAuthEncParams* handle) + internal unsafe AesAuthEncParams(Raw.AesAuthEncParams* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AesAuthEncParams(Raw.AesAuthEncParams* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AesAuthEncParams(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AesAuthEncParams* AsFFI() + internal unsafe Raw.AesAuthEncParams* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -44,13 +73,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AesAuthEncParams.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -60,4 +90,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AesParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/AesParameters.cs index e7bebc98..cb5d312b 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AesParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AesParameters.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class AesParameters: IDisposable { - private unsafe Raw.AesParameters* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AesParameters.Destroy; public AesParametersType Type { @@ -27,29 +32,51 @@ public AesParametersType Type /// Creates a managed AesParameters from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AesParameters(Raw.AesParameters* handle) + internal unsafe AesParameters(Raw.AesParameters* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AesParameters(Raw.AesParameters* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AesParameters(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A AesParametersType allocated on C# side. - /// public AesParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AesParameters"); } - Raw.AesParametersType retVal = Raw.AesParameters.GetType(_inner); - return (AesParametersType)retVal; + var result = Raw.AesParameters.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -60,16 +87,13 @@ public AesParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AesParameters"); } - Raw.VecU8* retVal = Raw.AesParameters.ToInitializationVector(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.AesParameters.ToInitializationVector(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -80,25 +104,22 @@ public AesParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AesParameters"); } - Raw.AesAuthEncParams* retVal = Raw.AesParameters.ToAuthenticatedEncryptionParameters(_inner); - if (retVal == null) - { - return null; - } - return new AesAuthEncParams(retVal); + Raw.AesAuthEncParams* result = Raw.AesParameters.ToAuthenticatedEncryptionParameters(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new AesAuthEncParams(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AesParameters* AsFFI() + internal unsafe Raw.AesParameters* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -108,13 +129,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AesParameters.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -124,4 +146,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AesParametersType.cs b/ffi/dotnet/Devolutions.Picky/Generated/AesParametersType.cs index 70d957fc..0bbb95a4 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AesParametersType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AesParametersType.cs @@ -1,19 +1,8 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum AesParametersType +public enum AesParametersType : int { Null = 0, InitializationVector = 1, AuthenticatedEncryptionParameters = 2, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifier.cs b/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifier.cs index cc5e2f4b..59a9ad4e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifier.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifier.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class AlgorithmIdentifier: IDisposable { - private unsafe Raw.AlgorithmIdentifier* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AlgorithmIdentifier.Destroy; public string Oid { @@ -23,6 +28,10 @@ public string Oid } } + /// + /// Lifetime: the returned native-backed value may borrow from the receiver or one or more inputs. + /// The caller is responsible for keeping any borrowed backing storage alive and undisposed while the returned value is in use. + /// public AlgorithmIdentifierParameters Parameters { get @@ -35,14 +44,38 @@ public AlgorithmIdentifierParameters Parameters /// Creates a managed AlgorithmIdentifier from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AlgorithmIdentifier(Raw.AlgorithmIdentifier* handle) + internal unsafe AlgorithmIdentifier(Raw.AlgorithmIdentifier* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AlgorithmIdentifier(Raw.AlgorithmIdentifier* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AlgorithmIdentifier(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -50,91 +83,79 @@ public bool IsA(string other) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AlgorithmIdentifier"); } - byte[] otherBuf = DiplomatUtils.StringToUtf8(other); - nuint otherBufLength = (nuint)otherBuf.Length; - fixed (byte* otherBufPtr = otherBuf) + if (other == null) throw new ArgumentNullException(nameof(other)); + byte[] otherBytes = System.Text.Encoding.UTF8.GetBytes(other); + fixed (byte* otherPtr = otherBytes) { - IntPtr resultPtr = Raw.AlgorithmIdentifier.IsA(_inner, otherBufPtr, otherBufLength); - Raw.X509AlgorithmIdentifierFfiResultBoolBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AlgorithmIdentifierFfiResultBoolBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.AlgorithmIdentifier.IsA(AsFFI(), new DiplomatSliceU8 { Ptr = otherPtr, Len = (nuint)otherBytes.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - bool retVal = result.Ok; - return retVal; + return result.Ok; } } } /// - public void GetOid(DiplomatWriteable writable) + public string GetOid() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AlgorithmIdentifier"); } - IntPtr resultPtr = Raw.AlgorithmIdentifier.GetOid(_inner, &writable); - Raw.X509AlgorithmIdentifierFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AlgorithmIdentifierFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - public string GetOid() - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("AlgorithmIdentifier"); + var result = Raw.AlgorithmIdentifier.GetOid(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.AlgorithmIdentifier.GetOid(_inner, &writeable); - Raw.X509AlgorithmIdentifierFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AlgorithmIdentifierFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// A AlgorithmIdentifierParameters allocated on Rust side. /// + /// + /// Lifetime: the returned native-backed value may borrow from the receiver or one or more inputs. + /// The caller is responsible for keeping any borrowed backing storage alive and undisposed while the returned value is in use. + /// public AlgorithmIdentifierParameters GetParameters() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AlgorithmIdentifier"); } - Raw.AlgorithmIdentifierParameters* retVal = Raw.AlgorithmIdentifier.GetParameters(_inner); - return new AlgorithmIdentifierParameters(retVal); + Raw.AlgorithmIdentifierParameters* result = Raw.AlgorithmIdentifier.GetParameters(AsFFI()); + GC.KeepAlive(this); + return new AlgorithmIdentifierParameters(result, new object[] { this }); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AlgorithmIdentifier* AsFFI() + internal unsafe Raw.AlgorithmIdentifier* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -144,13 +165,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AlgorithmIdentifier.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -160,4 +182,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierIterator.cs index b355a5ce..3b486eba 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class AlgorithmIdentifierIterator: IDisposable { - private unsafe Raw.AlgorithmIdentifierIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AlgorithmIdentifierIterator.Destroy; /// /// Creates a managed AlgorithmIdentifierIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AlgorithmIdentifierIterator(Raw.AlgorithmIdentifierIterator* handle) + internal unsafe AlgorithmIdentifierIterator(Raw.AlgorithmIdentifierIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AlgorithmIdentifierIterator(Raw.AlgorithmIdentifierIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AlgorithmIdentifierIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe AlgorithmIdentifierIterator(Raw.AlgorithmIdentifierIterator* handl { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AlgorithmIdentifierIterator"); } - Raw.AlgorithmIdentifier* retVal = Raw.AlgorithmIdentifierIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new AlgorithmIdentifier(retVal); + Raw.AlgorithmIdentifier* result = Raw.AlgorithmIdentifierIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new AlgorithmIdentifier(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AlgorithmIdentifierIterator* AsFFI() + internal unsafe Raw.AlgorithmIdentifierIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AlgorithmIdentifierIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierParameters.cs index 40de6048..891671ab 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierParameters.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// TODO/FIXME: Is having a reference here safe? We perhaps need to clone the parameters. -/// public partial class AlgorithmIdentifierParameters: IDisposable { - private unsafe Raw.AlgorithmIdentifierParameters* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AlgorithmIdentifierParameters.Destroy; public AlgorithmIdentifierParametersType Type { @@ -30,29 +32,51 @@ public AlgorithmIdentifierParametersType Type /// Creates a managed AlgorithmIdentifierParameters from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AlgorithmIdentifierParameters(Raw.AlgorithmIdentifierParameters* handle) + internal unsafe AlgorithmIdentifierParameters(Raw.AlgorithmIdentifierParameters* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AlgorithmIdentifierParameters(Raw.AlgorithmIdentifierParameters* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AlgorithmIdentifierParameters(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A AlgorithmIdentifierParametersType allocated on C# side. - /// public AlgorithmIdentifierParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AlgorithmIdentifierParameters"); } - Raw.AlgorithmIdentifierParametersType retVal = Raw.AlgorithmIdentifierParameters.GetType(_inner); - return (AlgorithmIdentifierParametersType)retVal; + var result = Raw.AlgorithmIdentifierParameters.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -63,16 +87,13 @@ public AlgorithmIdentifierParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AlgorithmIdentifierParameters"); } - Raw.AesParameters* retVal = Raw.AlgorithmIdentifierParameters.ToAes(_inner); - if (retVal == null) - { - return null; - } - return new AesParameters(retVal); + Raw.AesParameters* result = Raw.AlgorithmIdentifierParameters.ToAes(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new AesParameters(result); } } @@ -83,16 +104,13 @@ public AlgorithmIdentifierParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AlgorithmIdentifierParameters"); } - Raw.EcParameters* retVal = Raw.AlgorithmIdentifierParameters.ToEc(_inner); - if (retVal == null) - { - return null; - } - return new EcParameters(retVal); + Raw.EcParameters* result = Raw.AlgorithmIdentifierParameters.ToEc(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new EcParameters(result); } } @@ -103,25 +121,22 @@ public AlgorithmIdentifierParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AlgorithmIdentifierParameters"); } - Raw.RsassaPssParameters* retVal = Raw.AlgorithmIdentifierParameters.ToRsassaPss(_inner); - if (retVal == null) - { - return null; - } - return new RsassaPssParameters(retVal); + Raw.RsassaPssParameters* result = Raw.AlgorithmIdentifierParameters.ToRsassaPss(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new RsassaPssParameters(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AlgorithmIdentifierParameters* AsFFI() + internal unsafe Raw.AlgorithmIdentifierParameters* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -131,13 +146,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AlgorithmIdentifierParameters.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -147,4 +163,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierParametersType.cs b/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierParametersType.cs index 7bee7da9..62a4fad3 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierParametersType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AlgorithmIdentifierParametersType.cs @@ -1,21 +1,10 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum AlgorithmIdentifierParametersType +public enum AlgorithmIdentifierParametersType : int { None = 0, Null = 1, Aes = 2, Ec = 3, RsassaPss = 4, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Argon2.cs b/ffi/dotnet/Devolutions.Picky/Generated/Argon2.cs index e64c772f..aceeb9b5 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Argon2.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Argon2.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class Argon2: IDisposable { - private unsafe Raw.Argon2* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Argon2.Destroy; /// /// Creates a managed Argon2 from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Argon2(Raw.Argon2* handle) + internal unsafe Argon2(Raw.Argon2* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Argon2(Raw.Argon2* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Argon2(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -37,74 +66,47 @@ public static Argon2 New(Argon2Algorithm algorithm, Argon2Params parameters) { unsafe { - Raw.Argon2Algorithm algorithmRaw; - algorithmRaw = (Raw.Argon2Algorithm)algorithm; - Raw.Argon2Params* parametersRaw; - parametersRaw = parameters.AsFFI(); - if (parametersRaw == null) - { - throw new ObjectDisposedException("Argon2Params"); - } - IntPtr resultPtr = Raw.Argon2.New(algorithmRaw, parametersRaw); - Raw.Argon2FfiResultBoxArgon2BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Argon2FfiResultBoxArgon2BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (parameters == null) throw new ArgumentNullException(nameof(parameters)); + Raw.Argon2Params* parametersRaw = parameters.AsFFI(); + if (parametersRaw == null) throw new ObjectDisposedException(nameof(Argon2Params)); + var result = Raw.Argon2.New(algorithm, parametersRaw); + GC.KeepAlive(parameters); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Argon2* retVal = result.Ok; - return new Argon2(retVal); + return new Argon2(result.Ok); } } /// - public void HashPassword(string password, DiplomatWriteable writeable) + public string HashPassword(string password) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Argon2"); } - byte[] passwordBuf = DiplomatUtils.StringToUtf8(password); - nuint passwordBufLength = (nuint)passwordBuf.Length; - fixed (byte* passwordBufPtr = passwordBuf) + if (password == null) throw new ArgumentNullException(nameof(password)); + byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(password); + fixed (byte* passwordPtr = passwordBytes) { - IntPtr resultPtr = Raw.Argon2.HashPassword(_inner, passwordBufPtr, passwordBufLength, &writeable); - Raw.Argon2FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Argon2FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); + var result = Raw.Argon2.HashPassword(AsFFI(), new DiplomatSliceU8 { Ptr = passwordPtr, Len = (nuint)passwordBytes.Length }, &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - } - } - } - - /// - public string HashPassword(string password) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("Argon2"); - } - byte[] passwordBuf = DiplomatUtils.StringToUtf8(password); - nuint passwordBufLength = (nuint)passwordBuf.Length; - fixed (byte* passwordBufPtr = passwordBuf) - { - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.Argon2.HashPassword(_inner, passwordBufPtr, passwordBufLength, &writeable); - Raw.Argon2FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Argon2FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } } @@ -112,9 +114,9 @@ public string HashPassword(string password) /// /// Returns the underlying raw handle. /// - public unsafe Raw.Argon2* AsFFI() + internal unsafe Raw.Argon2* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -124,13 +126,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Argon2.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -140,4 +143,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Argon2Algorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/Argon2Algorithm.cs index 533bd1fa..701510d0 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Argon2Algorithm.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Argon2Algorithm.cs @@ -1,19 +1,8 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum Argon2Algorithm +public enum Argon2Algorithm : int { Argon2d = 0, Argon2i = 1, Argon2id = 2, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Argon2Params.cs b/ffi/dotnet/Devolutions.Picky/Generated/Argon2Params.cs index 43f78368..e15d73e9 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Argon2Params.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Argon2Params.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,57 +10,54 @@ namespace Devolutions.Picky; public partial class Argon2Params: IDisposable { - private unsafe Raw.Argon2Params* _inner; - - public uint MCost - { - set - { - SetMCost(value); - } - } + private unsafe RustHandle _inner; - public nuint OutputLen - { - set - { - SetOutputLen(value); - } - } + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; - public uint PCost - { - set - { - SetPCost(value); - } - } - - public uint TCost - { - set - { - SetTCost(value); - } - } + private static readonly unsafe RustDestructor _destroy = Raw.Argon2Params.Destroy; /// /// Creates a managed Argon2Params from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Argon2Params(Raw.Argon2Params* handle) + internal unsafe Argon2Params(Raw.Argon2Params* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Argon2Params(Raw.Argon2Params* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Create new parameters. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe Argon2Params(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// A Argon2Params allocated on Rust side. /// @@ -71,77 +65,69 @@ public static Argon2Params New() { unsafe { - Raw.Argon2Params* retVal = Raw.Argon2Params.New(); - return new Argon2Params(retVal); + Raw.Argon2Params* result = Raw.Argon2Params.New(); + return new Argon2Params(result); } } - /// - /// Sets the memory size in 1 KiB blocks. Between 1 and (2^32)-1. - /// public void SetMCost(uint value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Argon2Params"); } - Raw.Argon2Params.SetMCost(_inner, value); + Raw.Argon2Params.SetMCost(AsFFI(), value); + GC.KeepAlive(this); } } - /// - /// Sets the number of iterations. Between 1 and (2^32)-1. - /// public void SetTCost(uint value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Argon2Params"); } - Raw.Argon2Params.SetTCost(_inner, value); + Raw.Argon2Params.SetTCost(AsFFI(), value); + GC.KeepAlive(this); } } - /// - /// Sets the degree of parallelism. Between 1 and 255. - /// public void SetPCost(uint value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Argon2Params"); } - Raw.Argon2Params.SetPCost(_inner, value); + Raw.Argon2Params.SetPCost(AsFFI(), value); + GC.KeepAlive(this); } } - /// - /// Sets the size of the KDF output in bytes. Default 32. - /// public void SetOutputLen(nuint value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Argon2Params"); } - Raw.Argon2Params.SetOutputLen(_inner, value); + Raw.Argon2Params.SetOutputLen(AsFFI(), value); + GC.KeepAlive(this); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Argon2Params* AsFFI() + internal unsafe Raw.Argon2Params* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -151,13 +137,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Argon2Params.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -167,4 +154,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Attribute.cs b/ffi/dotnet/Devolutions.Picky/Generated/Attribute.cs index e2093cf0..c31320b2 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Attribute.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Attribute.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class Attribute: IDisposable { - private unsafe Raw.Attribute* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Attribute.Destroy; public string Type { @@ -35,33 +40,38 @@ public AttributeValues Values /// Creates a managed Attribute from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Attribute(Raw.Attribute* handle) + internal unsafe Attribute(Raw.Attribute* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void GetType(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Attribute(Raw.Attribute* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("Attribute"); - } - IntPtr resultPtr = Raw.Attribute.GetType(_inner, &writable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Attribute(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -69,21 +79,25 @@ public string GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Attribute"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.Attribute.GetType(_inner, &writeable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.Attribute.GetType(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -94,21 +108,22 @@ public AttributeValues GetValues() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Attribute"); } - Raw.AttributeValues* retVal = Raw.Attribute.GetValues(_inner); - return new AttributeValues(retVal); + Raw.AttributeValues* result = Raw.Attribute.GetValues(AsFFI()); + GC.KeepAlive(this); + return new AttributeValues(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Attribute* AsFFI() + internal unsafe Raw.Attribute* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -118,13 +133,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Attribute.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -134,4 +150,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AttributeIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/AttributeIterator.cs index a589e204..0635525d 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AttributeIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AttributeIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class AttributeIterator: IDisposable { - private unsafe Raw.AttributeIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AttributeIterator.Destroy; /// /// Creates a managed AttributeIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AttributeIterator(Raw.AttributeIterator* handle) + internal unsafe AttributeIterator(Raw.AttributeIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AttributeIterator(Raw.AttributeIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AttributeIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe AttributeIterator(Raw.AttributeIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeIterator"); } - Raw.Attribute* retVal = Raw.AttributeIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new Attribute(retVal); + Raw.Attribute* result = Raw.AttributeIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new Attribute(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AttributeIterator* AsFFI() + internal unsafe Raw.AttributeIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AttributeIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValue.cs b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValue.cs index ae53d910..f7e53503 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValue.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValue.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class AttributeTypeAndValue: IDisposable { - private unsafe Raw.AttributeTypeAndValue* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AttributeTypeAndValue.Destroy; public string TypeId { @@ -35,33 +40,38 @@ public AttributeTypeAndValueParameters Value /// Creates a managed AttributeTypeAndValue from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AttributeTypeAndValue(Raw.AttributeTypeAndValue* handle) + internal unsafe AttributeTypeAndValue(Raw.AttributeTypeAndValue* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void GetTypeId(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AttributeTypeAndValue(Raw.AttributeTypeAndValue* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("AttributeTypeAndValue"); - } - IntPtr resultPtr = Raw.AttributeTypeAndValue.GetTypeId(_inner, &writable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AttributeTypeAndValue(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -69,21 +79,25 @@ public string GetTypeId() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValue"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.AttributeTypeAndValue.GetTypeId(_inner, &writeable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.AttributeTypeAndValue.GetTypeId(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -94,21 +108,22 @@ public AttributeTypeAndValueParameters GetValue() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValue"); } - Raw.AttributeTypeAndValueParameters* retVal = Raw.AttributeTypeAndValue.GetValue(_inner); - return new AttributeTypeAndValueParameters(retVal); + Raw.AttributeTypeAndValueParameters* result = Raw.AttributeTypeAndValue.GetValue(AsFFI()); + GC.KeepAlive(this); + return new AttributeTypeAndValueParameters(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AttributeTypeAndValue* AsFFI() + internal unsafe Raw.AttributeTypeAndValue* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -118,13 +133,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AttributeTypeAndValue.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -134,4 +150,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueIterator.cs index d5e8f1be..acc81c97 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class AttributeTypeAndValueIterator: IDisposable { - private unsafe Raw.AttributeTypeAndValueIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AttributeTypeAndValueIterator.Destroy; /// /// Creates a managed AttributeTypeAndValueIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AttributeTypeAndValueIterator(Raw.AttributeTypeAndValueIterator* handle) + internal unsafe AttributeTypeAndValueIterator(Raw.AttributeTypeAndValueIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AttributeTypeAndValueIterator(Raw.AttributeTypeAndValueIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AttributeTypeAndValueIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe AttributeTypeAndValueIterator(Raw.AttributeTypeAndValueIterator* h { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueIterator"); } - Raw.AttributeTypeAndValue* retVal = Raw.AttributeTypeAndValueIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new AttributeTypeAndValue(retVal); + Raw.AttributeTypeAndValue* result = Raw.AttributeTypeAndValueIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new AttributeTypeAndValue(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AttributeTypeAndValueIterator* AsFFI() + internal unsafe Raw.AttributeTypeAndValueIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AttributeTypeAndValueIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueNestedIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueNestedIterator.cs index 031e0190..f6789ae8 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueNestedIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueNestedIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class AttributeTypeAndValueNestedIterator: IDisposable { - private unsafe Raw.AttributeTypeAndValueNestedIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AttributeTypeAndValueNestedIterator.Destroy; /// /// Creates a managed AttributeTypeAndValueNestedIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AttributeTypeAndValueNestedIterator(Raw.AttributeTypeAndValueNestedIterator* handle) + internal unsafe AttributeTypeAndValueNestedIterator(Raw.AttributeTypeAndValueNestedIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AttributeTypeAndValueNestedIterator(Raw.AttributeTypeAndValueNestedIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AttributeTypeAndValueNestedIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe AttributeTypeAndValueNestedIterator(Raw.AttributeTypeAndValueNeste { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueNestedIterator"); } - Raw.AttributeTypeAndValueIterator* retVal = Raw.AttributeTypeAndValueNestedIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new AttributeTypeAndValueIterator(retVal); + Raw.AttributeTypeAndValueIterator* result = Raw.AttributeTypeAndValueNestedIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new AttributeTypeAndValueIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AttributeTypeAndValueNestedIterator* AsFFI() + internal unsafe Raw.AttributeTypeAndValueNestedIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AttributeTypeAndValueNestedIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueParameters.cs index 58553bde..6e07382c 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueParameters.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class AttributeTypeAndValueParameters: IDisposable { - private unsafe Raw.AttributeTypeAndValueParameters* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AttributeTypeAndValueParameters.Destroy; public AttributeTypeAndValueParametersType Type { @@ -27,29 +32,51 @@ public AttributeTypeAndValueParametersType Type /// Creates a managed AttributeTypeAndValueParameters from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AttributeTypeAndValueParameters(Raw.AttributeTypeAndValueParameters* handle) + internal unsafe AttributeTypeAndValueParameters(Raw.AttributeTypeAndValueParameters* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AttributeTypeAndValueParameters(Raw.AttributeTypeAndValueParameters* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AttributeTypeAndValueParameters(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A AttributeTypeAndValueParametersType allocated on C# side. - /// public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.AttributeTypeAndValueParametersType retVal = Raw.AttributeTypeAndValueParameters.GetType(_inner); - return (AttributeTypeAndValueParametersType)retVal; + var result = Raw.AttributeTypeAndValueParameters.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -60,16 +87,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToCommonName(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToCommonName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -80,16 +104,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToSurname(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToSurname(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -100,16 +121,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToSerialNumber(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToSerialNumber(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -120,16 +138,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToCountryName(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToCountryName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -140,16 +155,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToLocalityName(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToLocalityName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -160,16 +172,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToStateOrProvinceName(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToStateOrProvinceName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -180,16 +189,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToStreetName(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToStreetName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -200,16 +206,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToOrganizationName(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToOrganizationName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -220,16 +223,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToOrganizationalUnitName(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToOrganizationalUnitName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -240,16 +240,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.VecU8* retVal = Raw.AttributeTypeAndValueParameters.ToEmailAddress(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.AttributeTypeAndValueParameters.ToEmailAddress(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -260,16 +257,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToGivenName(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToGivenName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -280,16 +274,13 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.DirectoryString* retVal = Raw.AttributeTypeAndValueParameters.ToPhone(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.AttributeTypeAndValueParameters.ToPhone(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -300,25 +291,22 @@ public AttributeTypeAndValueParametersType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeTypeAndValueParameters"); } - Raw.VecU8* retVal = Raw.AttributeTypeAndValueParameters.ToCustom(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.AttributeTypeAndValueParameters.ToCustom(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AttributeTypeAndValueParameters* AsFFI() + internal unsafe Raw.AttributeTypeAndValueParameters* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -328,13 +316,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AttributeTypeAndValueParameters.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -344,4 +333,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueParametersType.cs b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueParametersType.cs index 4220cd30..06134d62 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueParametersType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AttributeTypeAndValueParametersType.cs @@ -1,17 +1,6 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum AttributeTypeAndValueParametersType +public enum AttributeTypeAndValueParametersType : int { CommonName = 0, Surname = 1, @@ -26,4 +15,4 @@ public enum AttributeTypeAndValueParametersType GivenName = 10, Phone = 11, Custom = 12, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AttributeValueType.cs b/ffi/dotnet/Devolutions.Picky/Generated/AttributeValueType.cs index 610de160..10113f77 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AttributeValueType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AttributeValueType.cs @@ -1,17 +1,6 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum AttributeValueType +public enum AttributeValueType : int { Extensions = 0, ContentType = 1, @@ -20,4 +9,4 @@ public enum AttributeValueType SigningTime = 4, SpcSpOpusInfo = 5, Custom = 6, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AttributeValues.cs b/ffi/dotnet/Devolutions.Picky/Generated/AttributeValues.cs index 0de0753c..534434a1 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AttributeValues.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AttributeValues.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class AttributeValues: IDisposable { - private unsafe Raw.AttributeValues* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AttributeValues.Destroy; public AttributeValueType Type { @@ -27,29 +32,51 @@ public AttributeValueType Type /// Creates a managed AttributeValues from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AttributeValues(Raw.AttributeValues* handle) + internal unsafe AttributeValues(Raw.AttributeValues* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AttributeValues(Raw.AttributeValues* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AttributeValues(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A AttributeValueType allocated on C# side. - /// public AttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeValues"); } - Raw.AttributeValueType retVal = Raw.AttributeValues.GetType(_inner); - return (AttributeValueType)retVal; + var result = Raw.AttributeValues.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -60,16 +87,13 @@ public AttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeValues"); } - Raw.VecU8* retVal = Raw.AttributeValues.ToCustom(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.AttributeValues.ToCustom(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -80,16 +104,13 @@ public AttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeValues"); } - Raw.ExtensionIterator* retVal = Raw.AttributeValues.ToExtensions(_inner); - if (retVal == null) - { - return null; - } - return new ExtensionIterator(retVal); + Raw.ExtensionIterator* result = Raw.AttributeValues.ToExtensions(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new ExtensionIterator(result); } } @@ -100,16 +121,13 @@ public AttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeValues"); } - Raw.StringIterator* retVal = Raw.AttributeValues.ToContentType(_inner); - if (retVal == null) - { - return null; - } - return new StringIterator(retVal); + Raw.StringIterator* result = Raw.AttributeValues.ToContentType(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new StringIterator(result); } } @@ -120,16 +138,13 @@ public AttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeValues"); } - Raw.StringNestedIterator* retVal = Raw.AttributeValues.ToSpcStatementType(_inner); - if (retVal == null) - { - return null; - } - return new StringNestedIterator(retVal); + Raw.StringNestedIterator* result = Raw.AttributeValues.ToSpcStatementType(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new StringNestedIterator(result); } } @@ -140,16 +155,13 @@ public AttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeValues"); } - Raw.StringIterator* retVal = Raw.AttributeValues.ToMessageDigest(_inner); - if (retVal == null) - { - return null; - } - return new StringIterator(retVal); + Raw.StringIterator* result = Raw.AttributeValues.ToMessageDigest(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new StringIterator(result); } } @@ -160,16 +172,13 @@ public AttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeValues"); } - Raw.UTCTimeIterator* retVal = Raw.AttributeValues.ToSigningTime(_inner); - if (retVal == null) - { - return null; - } - return new UTCTimeIterator(retVal); + Raw.UTCTimeIterator* result = Raw.AttributeValues.ToSigningTime(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new UTCTimeIterator(result); } } @@ -180,25 +189,22 @@ public AttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AttributeValues"); } - Raw.SpcSpOpusInfoIterator* retVal = Raw.AttributeValues.ToSpcSpOpusInfo(_inner); - if (retVal == null) - { - return null; - } - return new SpcSpOpusInfoIterator(retVal); + Raw.SpcSpOpusInfoIterator* result = Raw.AttributeValues.ToSpcSpOpusInfo(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new SpcSpOpusInfoIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AttributeValues* AsFFI() + internal unsafe Raw.AttributeValues* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -208,13 +214,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AttributeValues.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -224,4 +231,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeSignature.cs b/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeSignature.cs index 1fe1b0cd..0860034c 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeSignature.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeSignature.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class AuthenticodeSignature: IDisposable { - private unsafe Raw.AuthenticodeSignature* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AuthenticodeSignature.Destroy; /// /// Creates a managed AuthenticodeSignature from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AuthenticodeSignature(Raw.AuthenticodeSignature* handle) + internal unsafe AuthenticodeSignature(Raw.AuthenticodeSignature* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AuthenticodeSignature(Raw.AuthenticodeSignature* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AuthenticodeSignature(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -37,48 +66,27 @@ public static AuthenticodeSignature New(Pkcs7 pkcs7, VecU8 fileHash, ShaVariant { unsafe { - Raw.Pkcs7* pkcs7Raw; - pkcs7Raw = pkcs7.AsFFI(); - if (pkcs7Raw == null) - { - throw new ObjectDisposedException("Pkcs7"); - } - Raw.VecU8* fileHashRaw; - fileHashRaw = fileHash.AsFFI(); - if (fileHashRaw == null) - { - throw new ObjectDisposedException("VecU8"); - } - Raw.ShaVariant hashAlgorithmRaw; - hashAlgorithmRaw = (Raw.ShaVariant)hashAlgorithm; - Raw.PrivateKey* privateKeyRaw; - privateKeyRaw = privateKey.AsFFI(); - if (privateKeyRaw == null) - { - throw new ObjectDisposedException("PrivateKey"); - } - Raw.RsString* programNameRaw; - if (programName == null) - { - programNameRaw = null; - } - else - { - programNameRaw = programName.AsFFI(); - if (programNameRaw == null) - { - throw new ObjectDisposedException("RsString"); - } - } - IntPtr resultPtr = Raw.AuthenticodeSignature.New(pkcs7Raw, fileHashRaw, hashAlgorithmRaw, privateKeyRaw, programNameRaw); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (pkcs7 == null) throw new ArgumentNullException(nameof(pkcs7)); + Raw.Pkcs7* pkcs7Raw = pkcs7.AsFFI(); + if (pkcs7Raw == null) throw new ObjectDisposedException(nameof(Pkcs7)); + if (fileHash == null) throw new ArgumentNullException(nameof(fileHash)); + Raw.VecU8* fileHashRaw = fileHash.AsFFI(); + if (fileHashRaw == null) throw new ObjectDisposedException(nameof(VecU8)); + if (privateKey == null) throw new ArgumentNullException(nameof(privateKey)); + Raw.PrivateKey* privateKeyRaw = privateKey.AsFFI(); + if (privateKeyRaw == null) throw new ObjectDisposedException(nameof(PrivateKey)); + Raw.RsString* programNameRaw = programName == null ? null : programName.AsFFI(); + if (programName != null && programNameRaw == null) throw new ObjectDisposedException(nameof(RsString)); + var result = Raw.AuthenticodeSignature.New(pkcs7Raw, fileHashRaw, hashAlgorithm, privateKeyRaw, programNameRaw); + GC.KeepAlive(pkcs7); + GC.KeepAlive(fileHash); + GC.KeepAlive(privateKey); + GC.KeepAlive(programName); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.AuthenticodeSignature* retVal = result.Ok; - return new AuthenticodeSignature(retVal); + return new AuthenticodeSignature(result.Ok); } } @@ -87,25 +95,21 @@ public void Timestamp(AuthenticodeTimestamper timestamper, HashAlgorithm hashAlg { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeSignature"); } - Raw.AuthenticodeTimestamper* timestamperRaw; - timestamperRaw = timestamper.AsFFI(); - if (timestamperRaw == null) - { - throw new ObjectDisposedException("AuthenticodeTimestamper"); - } - Raw.HashAlgorithm hashAlgoRaw; - hashAlgoRaw = (Raw.HashAlgorithm)hashAlgo; - IntPtr resultPtr = Raw.AuthenticodeSignature.Timestamp(_inner, timestamperRaw, hashAlgoRaw); - Raw.X509AuthenticodeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (timestamper == null) throw new ArgumentNullException(nameof(timestamper)); + Raw.AuthenticodeTimestamper* timestamperRaw = timestamper.AsFFI(); + if (timestamperRaw == null) throw new ObjectDisposedException(nameof(AuthenticodeTimestamper)); + var result = Raw.AuthenticodeSignature.Timestamp(AsFFI(), timestamperRaw, hashAlgo); + GC.KeepAlive(this); + GC.KeepAlive(timestamper); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } + return; } } @@ -117,21 +121,16 @@ public static AuthenticodeSignature FromDer(VecU8 der) { unsafe { - Raw.VecU8* derRaw; - derRaw = der.AsFFI(); - if (derRaw == null) - { - throw new ObjectDisposedException("VecU8"); - } - IntPtr resultPtr = Raw.AuthenticodeSignature.FromDer(derRaw); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (der == null) throw new ArgumentNullException(nameof(der)); + Raw.VecU8* derRaw = der.AsFFI(); + if (derRaw == null) throw new ObjectDisposedException(nameof(VecU8)); + var result = Raw.AuthenticodeSignature.FromDer(derRaw); + GC.KeepAlive(der); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.AuthenticodeSignature* retVal = result.Ok; - return new AuthenticodeSignature(retVal); + return new AuthenticodeSignature(result.Ok); } } @@ -143,21 +142,16 @@ public static AuthenticodeSignature FromPem(Pem pem) { unsafe { - Raw.Pem* pemRaw; - pemRaw = pem.AsFFI(); - if (pemRaw == null) - { - throw new ObjectDisposedException("Pem"); - } - IntPtr resultPtr = Raw.AuthenticodeSignature.FromPem(pemRaw); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (pem == null) throw new ArgumentNullException(nameof(pem)); + Raw.Pem* pemRaw = pem.AsFFI(); + if (pemRaw == null) throw new ObjectDisposedException(nameof(Pem)); + var result = Raw.AuthenticodeSignature.FromPem(pemRaw); + GC.KeepAlive(pem); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.AuthenticodeSignature* retVal = result.Ok; - return new AuthenticodeSignature(retVal); + return new AuthenticodeSignature(result.Ok); } } @@ -169,19 +163,16 @@ public static AuthenticodeSignature FromPemStr(string pem) { unsafe { - byte[] pemBuf = DiplomatUtils.StringToUtf8(pem); - nuint pemBufLength = (nuint)pemBuf.Length; - fixed (byte* pemBufPtr = pemBuf) + if (pem == null) throw new ArgumentNullException(nameof(pem)); + byte[] pemBytes = System.Text.Encoding.UTF8.GetBytes(pem); + fixed (byte* pemPtr = pemBytes) { - IntPtr resultPtr = Raw.AuthenticodeSignature.FromPemStr(pemBufPtr, pemBufLength); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.AuthenticodeSignature.FromPemStr(new DiplomatSliceU8 { Ptr = pemPtr, Len = (nuint)pemBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.AuthenticodeSignature* retVal = result.Ok; - return new AuthenticodeSignature(retVal); + return new AuthenticodeSignature(result.Ok); } } } @@ -194,19 +185,17 @@ public VecU8 ToDer() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeSignature"); } - IntPtr resultPtr = Raw.AuthenticodeSignature.ToDer(_inner); - Raw.X509AuthenticodeFfiResultBoxVecU8BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultBoxVecU8BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.AuthenticodeSignature.ToDer(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.VecU8* retVal = result.Ok; - return new VecU8(retVal); + return new VecU8(result.Ok); } } @@ -218,19 +207,17 @@ public Pem ToPem() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeSignature"); } - IntPtr resultPtr = Raw.AuthenticodeSignature.ToPem(_inner); - Raw.X509AuthenticodeFfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.AuthenticodeSignature.ToPem(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } @@ -242,41 +229,42 @@ public Cert SigningCertificate(CertIterator cert) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeSignature"); } - Raw.CertIterator* certRaw; - certRaw = cert.AsFFI(); - if (certRaw == null) - { - throw new ObjectDisposedException("CertIterator"); - } - IntPtr resultPtr = Raw.AuthenticodeSignature.SigningCertificate(_inner, certRaw); - Raw.X509AuthenticodeFfiResultBoxCertBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultBoxCertBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (cert == null) throw new ArgumentNullException(nameof(cert)); + Raw.CertIterator* certRaw = cert.AsFFI(); + if (certRaw == null) throw new ObjectDisposedException(nameof(CertIterator)); + var result = Raw.AuthenticodeSignature.SigningCertificate(AsFFI(), certRaw); + GC.KeepAlive(this); + GC.KeepAlive(cert); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Cert* retVal = result.Ok; - return new Cert(retVal); + return new Cert(result.Ok); } } /// /// A AuthenticodeValidator allocated on Rust side. /// + /// + /// Lifetime: the returned native-backed value may borrow from the receiver or one or more inputs. + /// The caller is responsible for keeping any borrowed backing storage alive and undisposed while the returned value is in use. + /// public AuthenticodeValidator AuthenticodeVerifier() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeSignature"); } - Raw.AuthenticodeValidator* retVal = Raw.AuthenticodeSignature.AuthenticodeVerifier(_inner); - return new AuthenticodeValidator(retVal); + Raw.AuthenticodeValidator* result = Raw.AuthenticodeSignature.AuthenticodeVerifier(AsFFI()); + GC.KeepAlive(this); + return new AuthenticodeValidator(result, new object[] { this }); } } @@ -287,16 +275,13 @@ public AuthenticodeValidator AuthenticodeVerifier() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeSignature"); } - Raw.VecU8* retVal = Raw.AuthenticodeSignature.FileHash(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.AuthenticodeSignature.FileHash(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -307,12 +292,13 @@ public AttributeIterator AuthenticateAttributes() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeSignature"); } - Raw.AttributeIterator* retVal = Raw.AuthenticodeSignature.AuthenticateAttributes(_inner); - return new AttributeIterator(retVal); + Raw.AttributeIterator* result = Raw.AuthenticodeSignature.AuthenticateAttributes(AsFFI()); + GC.KeepAlive(this); + return new AttributeIterator(result); } } @@ -323,21 +309,22 @@ public UnsignedAttributeIterator UnauthenticatedAttributes() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeSignature"); } - Raw.UnsignedAttributeIterator* retVal = Raw.AuthenticodeSignature.UnauthenticatedAttributes(_inner); - return new UnsignedAttributeIterator(retVal); + Raw.UnsignedAttributeIterator* result = Raw.AuthenticodeSignature.UnauthenticatedAttributes(AsFFI()); + GC.KeepAlive(this); + return new UnsignedAttributeIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AuthenticodeSignature* AsFFI() + internal unsafe Raw.AuthenticodeSignature* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -347,13 +334,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AuthenticodeSignature.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -363,4 +351,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeTimestamper.cs b/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeTimestamper.cs index c06b77c6..ad09a4d9 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeTimestamper.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeTimestamper.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class AuthenticodeTimestamper: IDisposable { - private unsafe Raw.AuthenticodeTimestamper* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AuthenticodeTimestamper.Destroy; /// /// Creates a managed AuthenticodeTimestamper from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AuthenticodeTimestamper(Raw.AuthenticodeTimestamper* handle) + internal unsafe AuthenticodeTimestamper(Raw.AuthenticodeTimestamper* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AuthenticodeTimestamper(Raw.AuthenticodeTimestamper* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AuthenticodeTimestamper(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -37,19 +66,16 @@ public static AuthenticodeTimestamper New(string url) { unsafe { - byte[] urlBuf = DiplomatUtils.StringToUtf8(url); - nuint urlBufLength = (nuint)urlBuf.Length; - fixed (byte* urlBufPtr = urlBuf) + if (url == null) throw new ArgumentNullException(nameof(url)); + byte[] urlBytes = System.Text.Encoding.UTF8.GetBytes(url); + fixed (byte* urlPtr = urlBytes) { - IntPtr resultPtr = Raw.AuthenticodeTimestamper.New(urlBufPtr, urlBufLength); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeTimestamperBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultBoxAuthenticodeTimestamperBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.AuthenticodeTimestamper.New(new DiplomatSliceU8 { Ptr = urlPtr, Len = (nuint)urlBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.AuthenticodeTimestamper* retVal = result.Ok; - return new AuthenticodeTimestamper(retVal); + return new AuthenticodeTimestamper(result.Ok); } } } @@ -62,27 +88,21 @@ public Pkcs7 Timestamp(VecU8 digest, HashAlgorithm hashAlgo) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeTimestamper"); } - Raw.VecU8* digestRaw; - digestRaw = digest.AsFFI(); - if (digestRaw == null) - { - throw new ObjectDisposedException("VecU8"); - } - Raw.HashAlgorithm hashAlgoRaw; - hashAlgoRaw = (Raw.HashAlgorithm)hashAlgo; - IntPtr resultPtr = Raw.AuthenticodeTimestamper.Timestamp(_inner, digestRaw, hashAlgoRaw); - Raw.X509AuthenticodeFfiResultBoxPkcs7BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultBoxPkcs7BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (digest == null) throw new ArgumentNullException(nameof(digest)); + Raw.VecU8* digestRaw = digest.AsFFI(); + if (digestRaw == null) throw new ObjectDisposedException(nameof(VecU8)); + var result = Raw.AuthenticodeTimestamper.Timestamp(AsFFI(), digestRaw, hashAlgo); + GC.KeepAlive(this); + GC.KeepAlive(digest); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pkcs7* retVal = result.Ok; - return new Pkcs7(retVal); + return new Pkcs7(result.Ok); } } @@ -90,32 +110,29 @@ public void ModifySignedData(Pkcs7 token, SignedData signedData) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeTimestamper"); } - Raw.Pkcs7* tokenRaw; - tokenRaw = token.AsFFI(); - if (tokenRaw == null) - { - throw new ObjectDisposedException("Pkcs7"); - } - Raw.SignedData* signedDataRaw; - signedDataRaw = signedData.AsFFI(); - if (signedDataRaw == null) - { - throw new ObjectDisposedException("SignedData"); - } - Raw.AuthenticodeTimestamper.ModifySignedData(_inner, tokenRaw, signedDataRaw); + if (token == null) throw new ArgumentNullException(nameof(token)); + Raw.Pkcs7* tokenRaw = token.AsFFI(); + if (tokenRaw == null) throw new ObjectDisposedException(nameof(Pkcs7)); + if (signedData == null) throw new ArgumentNullException(nameof(signedData)); + Raw.SignedData* signedDataRaw = signedData.AsFFI(); + if (signedDataRaw == null) throw new ObjectDisposedException(nameof(SignedData)); + Raw.AuthenticodeTimestamper.ModifySignedData(AsFFI(), tokenRaw, signedDataRaw); + GC.KeepAlive(this); + GC.KeepAlive(token); + GC.KeepAlive(signedData); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AuthenticodeTimestamper* AsFFI() + internal unsafe Raw.AuthenticodeTimestamper* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -125,13 +142,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AuthenticodeTimestamper.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -141,4 +159,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeValidator.cs b/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeValidator.cs index d821c56d..b9f51146 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeValidator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AuthenticodeValidator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,37 +10,68 @@ namespace Devolutions.Picky; public partial class AuthenticodeValidator: IDisposable { - private unsafe Raw.AuthenticodeValidator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AuthenticodeValidator.Destroy; /// /// Creates a managed AuthenticodeValidator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AuthenticodeValidator(Raw.AuthenticodeValidator* handle) + internal unsafe AuthenticodeValidator(Raw.AuthenticodeValidator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AuthenticodeValidator(Raw.AuthenticodeValidator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AuthenticodeValidator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } public void ExactDate(UtcDate exact) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.UtcDate* exactRaw; - exactRaw = exact.AsFFI(); - if (exactRaw == null) - { - throw new ObjectDisposedException("UtcDate"); - } - Raw.AuthenticodeValidator.ExactDate(_inner, exactRaw); + if (exact == null) throw new ArgumentNullException(nameof(exact)); + Raw.UtcDate* exactRaw = exact.AsFFI(); + if (exactRaw == null) throw new ObjectDisposedException(nameof(UtcDate)); + Raw.AuthenticodeValidator.ExactDate(AsFFI(), exactRaw); + GC.KeepAlive(this); + GC.KeepAlive(exact); } } @@ -51,23 +79,20 @@ public void IntervalDate(UtcDate lower, UtcDate upper) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.UtcDate* lowerRaw; - lowerRaw = lower.AsFFI(); - if (lowerRaw == null) - { - throw new ObjectDisposedException("UtcDate"); - } - Raw.UtcDate* upperRaw; - upperRaw = upper.AsFFI(); - if (upperRaw == null) - { - throw new ObjectDisposedException("UtcDate"); - } - Raw.AuthenticodeValidator.IntervalDate(_inner, lowerRaw, upperRaw); + if (lower == null) throw new ArgumentNullException(nameof(lower)); + Raw.UtcDate* lowerRaw = lower.AsFFI(); + if (lowerRaw == null) throw new ObjectDisposedException(nameof(UtcDate)); + if (upper == null) throw new ArgumentNullException(nameof(upper)); + Raw.UtcDate* upperRaw = upper.AsFFI(); + if (upperRaw == null) throw new ObjectDisposedException(nameof(UtcDate)); + Raw.AuthenticodeValidator.IntervalDate(AsFFI(), lowerRaw, upperRaw); + GC.KeepAlive(this); + GC.KeepAlive(lower); + GC.KeepAlive(upper); } } @@ -75,11 +100,12 @@ public void RequireNotBeforeCheck() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.AuthenticodeValidator.RequireNotBeforeCheck(_inner); + Raw.AuthenticodeValidator.RequireNotBeforeCheck(AsFFI()); + GC.KeepAlive(this); } } @@ -87,11 +113,12 @@ public void RequireNotAfterCheck() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.AuthenticodeValidator.RequireNotAfterCheck(_inner); + Raw.AuthenticodeValidator.RequireNotAfterCheck(AsFFI()); + GC.KeepAlive(this); } } @@ -99,11 +126,12 @@ public void IgnoreNotBeforeCheck() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.AuthenticodeValidator.IgnoreNotBeforeCheck(_inner); + Raw.AuthenticodeValidator.IgnoreNotBeforeCheck(AsFFI()); + GC.KeepAlive(this); } } @@ -111,11 +139,12 @@ public void IgnoreNotAfterCheck() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.AuthenticodeValidator.IgnoreNotAfterCheck(_inner); + Raw.AuthenticodeValidator.IgnoreNotAfterCheck(AsFFI()); + GC.KeepAlive(this); } } @@ -123,11 +152,12 @@ public void RequireSigningCertificateCheck() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.AuthenticodeValidator.RequireSigningCertificateCheck(_inner); + Raw.AuthenticodeValidator.RequireSigningCertificateCheck(AsFFI()); + GC.KeepAlive(this); } } @@ -135,11 +165,12 @@ public void IgnoreSigningCertificateCheck() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.AuthenticodeValidator.IgnoreSigningCertificateCheck(_inner); + Raw.AuthenticodeValidator.IgnoreSigningCertificateCheck(AsFFI()); + GC.KeepAlive(this); } } @@ -147,17 +178,16 @@ public void RequireBasicAuthenticodeValidation(VecU8 expectedFileHash) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.VecU8* expectedFileHashRaw; - expectedFileHashRaw = expectedFileHash.AsFFI(); - if (expectedFileHashRaw == null) - { - throw new ObjectDisposedException("VecU8"); - } - Raw.AuthenticodeValidator.RequireBasicAuthenticodeValidation(_inner, expectedFileHashRaw); + if (expectedFileHash == null) throw new ArgumentNullException(nameof(expectedFileHash)); + Raw.VecU8* expectedFileHashRaw = expectedFileHash.AsFFI(); + if (expectedFileHashRaw == null) throw new ObjectDisposedException(nameof(VecU8)); + Raw.AuthenticodeValidator.RequireBasicAuthenticodeValidation(AsFFI(), expectedFileHashRaw); + GC.KeepAlive(this); + GC.KeepAlive(expectedFileHash); } } @@ -165,11 +195,12 @@ public void IgnoreBasicAuthenticodeValidation() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.AuthenticodeValidator.IgnoreBasicAuthenticodeValidation(_inner); + Raw.AuthenticodeValidator.IgnoreBasicAuthenticodeValidation(AsFFI()); + GC.KeepAlive(this); } } @@ -177,11 +208,12 @@ public void RequireChainCheck() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.AuthenticodeValidator.RequireChainCheck(_inner); + Raw.AuthenticodeValidator.RequireChainCheck(AsFFI()); + GC.KeepAlive(this); } } @@ -189,11 +221,12 @@ public void IgnoreChainCheck() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.AuthenticodeValidator.IgnoreChainCheck(_inner); + Raw.AuthenticodeValidator.IgnoreChainCheck(AsFFI()); + GC.KeepAlive(this); } } @@ -201,17 +234,16 @@ public void ExcludeCertAuthorities(DirectoryNameIterator certAuths) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - Raw.DirectoryNameIterator* certAuthsRaw; - certAuthsRaw = certAuths.AsFFI(); - if (certAuthsRaw == null) - { - throw new ObjectDisposedException("DirectoryNameIterator"); - } - Raw.AuthenticodeValidator.ExcludeCertAuthorities(_inner, certAuthsRaw); + if (certAuths == null) throw new ArgumentNullException(nameof(certAuths)); + Raw.DirectoryNameIterator* certAuthsRaw = certAuths.AsFFI(); + if (certAuthsRaw == null) throw new ObjectDisposedException(nameof(DirectoryNameIterator)); + Raw.AuthenticodeValidator.ExcludeCertAuthorities(AsFFI(), certAuthsRaw); + GC.KeepAlive(this); + GC.KeepAlive(certAuths); } } @@ -220,26 +252,26 @@ public void Verify() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthenticodeValidator"); } - IntPtr resultPtr = Raw.AuthenticodeValidator.Verify(_inner); - Raw.X509AuthenticodeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AuthenticodeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.AuthenticodeValidator.Verify(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } + return; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AuthenticodeValidator* AsFFI() + internal unsafe Raw.AuthenticodeValidator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -249,13 +281,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AuthenticodeValidator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -265,4 +298,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/AuthorityKeyIdentifier.cs b/ffi/dotnet/Devolutions.Picky/Generated/AuthorityKeyIdentifier.cs index f50c9476..10912942 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/AuthorityKeyIdentifier.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/AuthorityKeyIdentifier.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class AuthorityKeyIdentifier: IDisposable { - private unsafe Raw.AuthorityKeyIdentifier* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.AuthorityKeyIdentifier.Destroy; public GeneralName? AuthorityCertIssuer { @@ -43,14 +48,38 @@ public VecU8? KeyIdentifier /// Creates a managed AuthorityKeyIdentifier from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe AuthorityKeyIdentifier(Raw.AuthorityKeyIdentifier* handle) + internal unsafe AuthorityKeyIdentifier(Raw.AuthorityKeyIdentifier* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe AuthorityKeyIdentifier(Raw.AuthorityKeyIdentifier* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe AuthorityKeyIdentifier(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -60,16 +89,13 @@ public unsafe AuthorityKeyIdentifier(Raw.AuthorityKeyIdentifier* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthorityKeyIdentifier"); } - Raw.VecU8* retVal = Raw.AuthorityKeyIdentifier.GetKeyIdentifier(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.AuthorityKeyIdentifier.GetKeyIdentifier(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -80,16 +106,13 @@ public unsafe AuthorityKeyIdentifier(Raw.AuthorityKeyIdentifier* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthorityKeyIdentifier"); } - Raw.GeneralName* retVal = Raw.AuthorityKeyIdentifier.GetAuthorityCertIssuer(_inner); - if (retVal == null) - { - return null; - } - return new GeneralName(retVal); + Raw.GeneralName* result = Raw.AuthorityKeyIdentifier.GetAuthorityCertIssuer(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new GeneralName(result); } } @@ -100,25 +123,22 @@ public unsafe AuthorityKeyIdentifier(Raw.AuthorityKeyIdentifier* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("AuthorityKeyIdentifier"); } - Raw.VecU8* retVal = Raw.AuthorityKeyIdentifier.GetAuthorityCertSerialNumber(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.AuthorityKeyIdentifier.GetAuthorityCertSerialNumber(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.AuthorityKeyIdentifier* AsFFI() + internal unsafe Raw.AuthorityKeyIdentifier* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -128,13 +148,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.AuthorityKeyIdentifier.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -144,4 +165,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/BasicConstraints.cs b/ffi/dotnet/Devolutions.Picky/Generated/BasicConstraints.cs index 6759572f..cb9d8733 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/BasicConstraints.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/BasicConstraints.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class BasicConstraints: IDisposable { - private unsafe Raw.BasicConstraints* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.BasicConstraints.Destroy; public GetCaResult Ca { @@ -35,29 +40,51 @@ public U8? Pathlen /// Creates a managed BasicConstraints from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe BasicConstraints(Raw.BasicConstraints* handle) + internal unsafe BasicConstraints(Raw.BasicConstraints* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe BasicConstraints(Raw.BasicConstraints* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe BasicConstraints(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A GetCaResult allocated on C# side. - /// public GetCaResult GetCa() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("BasicConstraints"); } - Raw.GetCaResult retVal = Raw.BasicConstraints.GetCa(_inner); - return (GetCaResult)retVal; + var result = Raw.BasicConstraints.GetCa(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -68,25 +95,22 @@ public GetCaResult GetCa() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("BasicConstraints"); } - Raw.U8* retVal = Raw.BasicConstraints.GetPathlen(_inner); - if (retVal == null) - { - return null; - } - return new U8(retVal); + Raw.U8* result = Raw.BasicConstraints.GetPathlen(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new U8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.BasicConstraints* AsFFI() + internal unsafe Raw.BasicConstraints* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -96,13 +120,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.BasicConstraints.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -112,4 +137,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/BufferTooSmallError.cs b/ffi/dotnet/Devolutions.Picky/Generated/BufferTooSmallError.cs index 66fd04dd..13ee5524 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/BufferTooSmallError.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/BufferTooSmallError.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,56 +10,82 @@ namespace Devolutions.Picky; public partial class BufferTooSmallError: IDisposable { - private unsafe Raw.BufferTooSmallError* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.BufferTooSmallError.Destroy; /// /// Creates a managed BufferTooSmallError from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe BufferTooSmallError(Raw.BufferTooSmallError* handle) + internal unsafe BufferTooSmallError(Raw.BufferTooSmallError* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - public void ToDisplay(DiplomatWriteable writeable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe BufferTooSmallError(Raw.BufferTooSmallError* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("BufferTooSmallError"); - } - Raw.BufferTooSmallError.ToDisplay(_inner, &writeable); - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe BufferTooSmallError(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } public string ToDisplay() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("BufferTooSmallError"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - Raw.BufferTooSmallError.ToDisplay(_inner, &writeable); - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; + DiplomatWrite writeable = new DiplomatWrite(); + try + { + Raw.BufferTooSmallError.ToDisplay(AsFFI(), &writeable); + GC.KeepAlive(this); + return writeable.ToUnicode(); + } + finally + { + writeable.Dispose(); + } } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.BufferTooSmallError* AsFFI() + internal unsafe Raw.BufferTooSmallError* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -72,13 +95,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.BufferTooSmallError.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -88,4 +112,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/BufferTooSmallException.cs b/ffi/dotnet/Devolutions.Picky/Generated/BufferTooSmallException.cs index c468b9a8..aabccbba 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/BufferTooSmallException.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/BufferTooSmallException.cs @@ -1,30 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; -#nullable enable - -public partial class BufferTooSmallException : Exception +public class BufferTooSmallException : Exception { - private BufferTooSmallError _inner; - - public BufferTooSmallException(BufferTooSmallError inner) : base(inner.ToDisplay()) - { - _inner = inner; - } + public BufferTooSmallError Inner { get; } + private readonly object[] _edges; - public BufferTooSmallError Inner + public BufferTooSmallException(BufferTooSmallError inner, params object[] edges) : base( + inner.ToDisplay() + ) { - get - { - return _inner; - } + Inner = inner; + _edges = edges; } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Cert.cs b/ffi/dotnet/Devolutions.Picky/Generated/Cert.cs index 48afef92..6b5309a4 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Cert.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Cert.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class Cert: IDisposable { - private unsafe Raw.Cert* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Cert.Destroy; public CertType CertType { @@ -83,19 +88,40 @@ public UtcDate ValidNotBefore /// Creates a managed Cert from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Cert(Raw.Cert* handle) + internal unsafe Cert(Raw.Cert* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Cert(Raw.Cert* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Parses a X509 certificate from its DER representation. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe Cert(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A Cert allocated on Rust side. @@ -104,25 +130,19 @@ public static Cert FromDer(byte[] der) { unsafe { - nuint derLength = (nuint)der.Length; + if (der == null) throw new ArgumentNullException(nameof(der)); fixed (byte* derPtr = der) { - IntPtr resultPtr = Raw.Cert.FromDer(derPtr, derLength); - Raw.X509FfiResultBoxCertBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultBoxCertBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Cert.FromDer(new DiplomatSliceU8 { Ptr = derPtr, Len = (nuint)der.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Cert* retVal = result.Ok; - return new Cert(retVal); + return new Cert(result.Ok); } } } - /// - /// Extracts X509 certificate from PEM object. - /// /// /// /// A Cert allocated on Rust side. @@ -131,27 +151,19 @@ public static Cert FromPem(Pem pem) { unsafe { - Raw.Pem* pemRaw; - pemRaw = pem.AsFFI(); - if (pemRaw == null) - { - throw new ObjectDisposedException("Pem"); - } - IntPtr resultPtr = Raw.Cert.FromPem(pemRaw); - Raw.X509FfiResultBoxCertBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultBoxCertBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (pem == null) throw new ArgumentNullException(nameof(pem)); + Raw.Pem* pemRaw = pem.AsFFI(); + if (pemRaw == null) throw new ObjectDisposedException(nameof(Pem)); + var result = Raw.Cert.FromPem(pemRaw); + GC.KeepAlive(pem); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Cert* retVal = result.Ok; - return new Cert(retVal); + return new Cert(result.Ok); } } - /// - /// Exports the X509 certificate into a PEM object - /// /// /// /// A Pem allocated on Rust side. @@ -160,35 +172,31 @@ public Pem ToPem() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Cert"); } - IntPtr resultPtr = Raw.Cert.ToPem(_inner); - Raw.X509FfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Cert.ToPem(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } - /// - /// A CertType allocated on C# side. - /// public CertType GetTy() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Cert"); } - Raw.CertType retVal = Raw.Cert.GetTy(_inner); - return (CertType)retVal; + var result = Raw.Cert.GetTy(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -199,28 +207,27 @@ public PublicKey GetPublicKey() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Cert"); } - Raw.PublicKey* retVal = Raw.Cert.GetPublicKey(_inner); - return new PublicKey(retVal); + Raw.PublicKey* result = Raw.Cert.GetPublicKey(AsFFI()); + GC.KeepAlive(this); + return new PublicKey(result); } } - /// - /// A CertType allocated on C# side. - /// public CertType GetCertType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Cert"); } - Raw.CertType retVal = Raw.Cert.GetCertType(_inner); - return (CertType)retVal; + var result = Raw.Cert.GetCertType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -231,12 +238,13 @@ public UtcDate GetValidNotBefore() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Cert"); } - Raw.UtcDate* retVal = Raw.Cert.GetValidNotBefore(_inner); - return new UtcDate(retVal); + Raw.UtcDate* result = Raw.Cert.GetValidNotBefore(AsFFI()); + GC.KeepAlive(this); + return new UtcDate(result); } } @@ -247,31 +255,13 @@ public UtcDate GetValidNotAfter() { unsafe { - if (_inner == null) - { - throw new ObjectDisposedException("Cert"); - } - Raw.UtcDate* retVal = Raw.Cert.GetValidNotAfter(_inner); - return new UtcDate(retVal); - } - } - - /// - public void GetSubjectKeyIdHex(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Cert"); } - IntPtr resultPtr = Raw.Cert.GetSubjectKeyIdHex(_inner, &writeable); - Raw.X509FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } + Raw.UtcDate* result = Raw.Cert.GetValidNotAfter(AsFFI()); + GC.KeepAlive(this); + return new UtcDate(result); } } @@ -280,39 +270,24 @@ public string GetSubjectKeyIdHex() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Cert"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.Cert.GetSubjectKeyIdHex(_inner, &writeable); - Raw.X509FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - public void GetSubjectName(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("Cert"); + var result = Raw.Cert.GetSubjectKeyIdHex(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - IntPtr resultPtr = Raw.Cert.GetSubjectName(_inner, &writeable); - Raw.X509FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } @@ -322,39 +297,24 @@ public string GetSubjectName() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Cert"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.Cert.GetSubjectName(_inner, &writeable); - Raw.X509FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - public void GetIssuerName(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("Cert"); + var result = Raw.Cert.GetSubjectName(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - IntPtr resultPtr = Raw.Cert.GetIssuerName(_inner, &writeable); - Raw.X509FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } @@ -364,30 +324,34 @@ public string GetIssuerName() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Cert"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.Cert.GetIssuerName(_inner, &writeable); - Raw.X509FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); + var result = Raw.Cert.GetIssuerName(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally + { + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Cert* AsFFI() + internal unsafe Raw.Cert* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -397,13 +361,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Cert.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -413,4 +378,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/CertIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/CertIterator.cs index 737bd637..656c2589 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/CertIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/CertIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class CertIterator: IDisposable { - private unsafe Raw.CertIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.CertIterator.Destroy; /// /// Creates a managed CertIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe CertIterator(Raw.CertIterator* handle) + internal unsafe CertIterator(Raw.CertIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe CertIterator(Raw.CertIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe CertIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe CertIterator(Raw.CertIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertIterator"); } - Raw.Cert* retVal = Raw.CertIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new Cert(retVal); + Raw.Cert* result = Raw.CertIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new Cert(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.CertIterator* AsFFI() + internal unsafe Raw.CertIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.CertIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/CertType.cs b/ffi/dotnet/Devolutions.Picky/Generated/CertType.cs index 1f364d05..9533a59d 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/CertType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/CertType.cs @@ -1,20 +1,9 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum CertType +public enum CertType : int { Root = 0, Intermediate = 1, Leaf = 2, Unknown = 3, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/CertificateBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/CertificateBuilder.cs index 5d4e0f82..0288e12f 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/CertificateBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/CertificateBuilder.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,84 +10,52 @@ namespace Devolutions.Picky; public partial class CertificateBuilder: IDisposable { - private unsafe Raw.CertificateBuilder* _inner; - - public string IssuerCommonName - { - set - { - SetIssuerCommonName(value); - } - } + private unsafe RustHandle _inner; - public PrivateKey IssuerKey - { - set - { - SetIssuerKey(value); - } - } - - public bool KpServerAuth - { - set - { - SetKpServerAuth(value); - } - } - - public bool KuDigitalSignature - { - set - { - SetKuDigitalSignature(value); - } - } - - public bool SelfSigned - { - set - { - SetSelfSigned(value); - } - } - - public string SubjectDnsName - { - set - { - SetSubjectDnsName(value); - } - } - - public UtcDate ValidFrom - { - set - { - SetValidFrom(value); - } - } + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; - public UtcDate ValidTo - { - set - { - SetValidTo(value); - } - } + private static readonly unsafe RustDestructor _destroy = Raw.CertificateBuilder.Destroy; /// /// Creates a managed CertificateBuilder from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe CertificateBuilder(Raw.CertificateBuilder* handle) + internal unsafe CertificateBuilder(Raw.CertificateBuilder* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe CertificateBuilder(Raw.CertificateBuilder* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe CertificateBuilder(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -100,8 +65,8 @@ public static CertificateBuilder New() { unsafe { - Raw.CertificateBuilder* retVal = Raw.CertificateBuilder.New(); - return new CertificateBuilder(retVal); + Raw.CertificateBuilder* result = Raw.CertificateBuilder.New(); + return new CertificateBuilder(result); } } @@ -109,17 +74,16 @@ public void SetValidFrom(UtcDate validFrom) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateBuilder"); } - Raw.UtcDate* validFromRaw; - validFromRaw = validFrom.AsFFI(); - if (validFromRaw == null) - { - throw new ObjectDisposedException("UtcDate"); - } - Raw.CertificateBuilder.SetValidFrom(_inner, validFromRaw); + if (validFrom == null) throw new ArgumentNullException(nameof(validFrom)); + Raw.UtcDate* validFromRaw = validFrom.AsFFI(); + if (validFromRaw == null) throw new ObjectDisposedException(nameof(UtcDate)); + Raw.CertificateBuilder.SetValidFrom(AsFFI(), validFromRaw); + GC.KeepAlive(this); + GC.KeepAlive(validFrom); } } @@ -127,17 +91,16 @@ public void SetValidTo(UtcDate validTo) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateBuilder"); } - Raw.UtcDate* validToRaw; - validToRaw = validTo.AsFFI(); - if (validToRaw == null) - { - throw new ObjectDisposedException("UtcDate"); - } - Raw.CertificateBuilder.SetValidTo(_inner, validToRaw); + if (validTo == null) throw new ArgumentNullException(nameof(validTo)); + Raw.UtcDate* validToRaw = validTo.AsFFI(); + if (validToRaw == null) throw new ObjectDisposedException(nameof(UtcDate)); + Raw.CertificateBuilder.SetValidTo(AsFFI(), validToRaw); + GC.KeepAlive(this); + GC.KeepAlive(validTo); } } @@ -145,15 +108,16 @@ public void SetIssuerCommonName(string name) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateBuilder"); } - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - nuint nameBufLength = (nuint)nameBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + fixed (byte* namePtr = nameBytes) { - Raw.CertificateBuilder.SetIssuerCommonName(_inner, nameBufPtr, nameBufLength); + Raw.CertificateBuilder.SetIssuerCommonName(AsFFI(), new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }); + GC.KeepAlive(this); } } } @@ -162,15 +126,16 @@ public void SetSubjectDnsName(string name) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateBuilder"); } - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - nuint nameBufLength = (nuint)nameBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + fixed (byte* namePtr = nameBytes) { - Raw.CertificateBuilder.SetSubjectDnsName(_inner, nameBufPtr, nameBufLength); + Raw.CertificateBuilder.SetSubjectDnsName(AsFFI(), new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }); + GC.KeepAlive(this); } } } @@ -179,17 +144,16 @@ public void SetIssuerKey(PrivateKey key) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateBuilder"); } - Raw.PrivateKey* keyRaw; - keyRaw = key.AsFFI(); - if (keyRaw == null) - { - throw new ObjectDisposedException("PrivateKey"); - } - Raw.CertificateBuilder.SetIssuerKey(_inner, keyRaw); + if (key == null) throw new ArgumentNullException(nameof(key)); + Raw.PrivateKey* keyRaw = key.AsFFI(); + if (keyRaw == null) throw new ObjectDisposedException(nameof(PrivateKey)); + Raw.CertificateBuilder.SetIssuerKey(AsFFI(), keyRaw); + GC.KeepAlive(this); + GC.KeepAlive(key); } } @@ -197,11 +161,12 @@ public void SetSelfSigned(bool isSelfSigned) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateBuilder"); } - Raw.CertificateBuilder.SetSelfSigned(_inner, isSelfSigned); + Raw.CertificateBuilder.SetSelfSigned(AsFFI(), isSelfSigned); + GC.KeepAlive(this); } } @@ -209,11 +174,12 @@ public void SetKuDigitalSignature(bool enable) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateBuilder"); } - Raw.CertificateBuilder.SetKuDigitalSignature(_inner, enable); + Raw.CertificateBuilder.SetKuDigitalSignature(AsFFI(), enable); + GC.KeepAlive(this); } } @@ -221,11 +187,12 @@ public void SetKpServerAuth(bool enable) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateBuilder"); } - Raw.CertificateBuilder.SetKpServerAuth(_inner, enable); + Raw.CertificateBuilder.SetKpServerAuth(AsFFI(), enable); + GC.KeepAlive(this); } } @@ -237,28 +204,26 @@ public Cert Build() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateBuilder"); } - IntPtr resultPtr = Raw.CertificateBuilder.Build(_inner); - Raw.X509FfiResultBoxCertBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509FfiResultBoxCertBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.CertificateBuilder.Build(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Cert* retVal = result.Ok; - return new Cert(retVal); + return new Cert(result.Ok); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.CertificateBuilder* AsFFI() + internal unsafe Raw.CertificateBuilder* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -268,13 +233,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.CertificateBuilder.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -284,4 +250,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/CertificateChoices.cs b/ffi/dotnet/Devolutions.Picky/Generated/CertificateChoices.cs index e7ddd3ba..3b5dea00 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/CertificateChoices.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/CertificateChoices.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class CertificateChoices: IDisposable { - private unsafe Raw.CertificateChoices* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.CertificateChoices.Destroy; public VecU8? Certificate { @@ -35,14 +40,38 @@ public VecU8? Other /// Creates a managed CertificateChoices from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe CertificateChoices(Raw.CertificateChoices* handle) + internal unsafe CertificateChoices(Raw.CertificateChoices* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe CertificateChoices(Raw.CertificateChoices* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe CertificateChoices(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -52,16 +81,13 @@ public unsafe CertificateChoices(Raw.CertificateChoices* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateChoices"); } - Raw.VecU8* retVal = Raw.CertificateChoices.GetCertificate(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.CertificateChoices.GetCertificate(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -72,16 +98,13 @@ public unsafe CertificateChoices(Raw.CertificateChoices* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateChoices"); } - Raw.VecU8* retVal = Raw.CertificateChoices.GetOther(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.CertificateChoices.GetOther(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -89,21 +112,22 @@ public bool IsCertificate() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateChoices"); } - bool retVal = Raw.CertificateChoices.IsCertificate(_inner); - return retVal; + var result = Raw.CertificateChoices.IsCertificate(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.CertificateChoices* AsFFI() + internal unsafe Raw.CertificateChoices* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -113,13 +137,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.CertificateChoices.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -129,4 +154,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/CertificateChoicesIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/CertificateChoicesIterator.cs index 48b6b6d4..fc90adaa 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/CertificateChoicesIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/CertificateChoicesIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class CertificateChoicesIterator: IDisposable { - private unsafe Raw.CertificateChoicesIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.CertificateChoicesIterator.Destroy; /// /// Creates a managed CertificateChoicesIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe CertificateChoicesIterator(Raw.CertificateChoicesIterator* handle) + internal unsafe CertificateChoicesIterator(Raw.CertificateChoicesIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe CertificateChoicesIterator(Raw.CertificateChoicesIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe CertificateChoicesIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe CertificateChoicesIterator(Raw.CertificateChoicesIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateChoicesIterator"); } - Raw.CertificateChoices* retVal = Raw.CertificateChoicesIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new CertificateChoices(retVal); + Raw.CertificateChoices* result = Raw.CertificateChoicesIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new CertificateChoices(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.CertificateChoicesIterator* AsFFI() + internal unsafe Raw.CertificateChoicesIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.CertificateChoicesIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/CertificateList.cs b/ffi/dotnet/Devolutions.Picky/Generated/CertificateList.cs index 90cb5085..aa3d6b0a 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/CertificateList.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/CertificateList.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class CertificateList: IDisposable { - private unsafe Raw.CertificateList* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.CertificateList.Destroy; public AlgorithmIdentifier SignatureAlgorithm { @@ -43,14 +48,38 @@ public TbsCertList TbsCertList /// Creates a managed CertificateList from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe CertificateList(Raw.CertificateList* handle) + internal unsafe CertificateList(Raw.CertificateList* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe CertificateList(Raw.CertificateList* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe CertificateList(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -60,12 +89,13 @@ public TbsCertList GetTbsCertList() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateList"); } - Raw.TbsCertList* retVal = Raw.CertificateList.GetTbsCertList(_inner); - return new TbsCertList(retVal); + Raw.TbsCertList* result = Raw.CertificateList.GetTbsCertList(AsFFI()); + GC.KeepAlive(this); + return new TbsCertList(result); } } @@ -76,12 +106,13 @@ public AlgorithmIdentifier GetSignatureAlgorithm() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateList"); } - Raw.AlgorithmIdentifier* retVal = Raw.CertificateList.GetSignatureAlgorithm(_inner); - return new AlgorithmIdentifier(retVal); + Raw.AlgorithmIdentifier* result = Raw.CertificateList.GetSignatureAlgorithm(AsFFI()); + GC.KeepAlive(this); + return new AlgorithmIdentifier(result); } } @@ -92,21 +123,22 @@ public VecU8 GetSignatureValue() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("CertificateList"); } - Raw.VecU8* retVal = Raw.CertificateList.GetSignatureValue(_inner); - return new VecU8(retVal); + Raw.VecU8* result = Raw.CertificateList.GetSignatureValue(AsFFI()); + GC.KeepAlive(this); + return new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.CertificateList* AsFFI() + internal unsafe Raw.CertificateList* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -116,13 +148,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.CertificateList.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -132,4 +165,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/CmsVersion.cs b/ffi/dotnet/Devolutions.Picky/Generated/CmsVersion.cs index 616eef69..1ea6024f 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/CmsVersion.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/CmsVersion.cs @@ -1,17 +1,6 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum CmsVersion +public enum CmsVersion : int { V0 = 0, V1 = 1, @@ -19,4 +8,4 @@ public enum CmsVersion V3 = 3, V4 = 4, V5 = 5, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatBool.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatBool.cs new file mode 100644 index 00000000..dd57d32c --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatBool.cs @@ -0,0 +1,21 @@ +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Diplomat; + +// Blittable one-byte stand-in for `bool`. .NET Framework P/Invoke can't return a +// struct by value if any field is non-blittable, and `bool` is non-blittable, so +// Result/Option tags and struct bool fields use a byte (these bindings target +// netstandard2.0 and must load on net48). +// Rules: https://learn.microsoft.com/en-us/dotnet/standard/native-interop/blittable-and-non-blittable-types +// Matches Rust's 1-byte bool (0/1): https://doc.rust-lang.org/reference/types/boolean.html +[StructLayout(LayoutKind.Sequential)] +internal readonly struct DiplomatBool +{ + private readonly byte _value; + + private DiplomatBool(byte value) => _value = value; + + // Implicit both ways so the idiomatic layer stays bool-only. + public static implicit operator DiplomatBool(bool value) => new DiplomatBool(value ? (byte)1 : (byte)0); + public static implicit operator bool(DiplomatBool value) => value._value != 0; +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultArgon2PickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultArgon2PickyError.cs new file mode 100644 index 00000000..5290fe4a --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultArgon2PickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultArgon2PickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal Argon2* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe Argon2* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultAuthenticodeSignaturePickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultAuthenticodeSignaturePickyError.cs new file mode 100644 index 00000000..ecd4b3dd --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultAuthenticodeSignaturePickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultAuthenticodeSignaturePickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal AuthenticodeSignature* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe AuthenticodeSignature* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultAuthenticodeTimestamperPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultAuthenticodeTimestamperPickyError.cs new file mode 100644 index 00000000..e84bb590 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultAuthenticodeTimestamperPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultAuthenticodeTimestamperPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal AuthenticodeTimestamper* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe AuthenticodeTimestamper* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultBoolPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultBoolPickyError.cs new file mode 100644 index 00000000..ef9aacd1 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultBoolPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultBoolPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal byte ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public bool Ok => IsOk ? _inner.ok != 0 : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultCertPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultCertPickyError.cs new file mode 100644 index 00000000..35a1f861 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultCertPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultCertPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal Cert* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe Cert* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultJwtSigPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultJwtSigPickyError.cs new file mode 100644 index 00000000..d173108f --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultJwtSigPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultJwtSigPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal JwtSig* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe JwtSig* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultLongPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultLongPickyError.cs new file mode 100644 index 00000000..989b093e --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultLongPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultLongPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal long ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public long Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPemPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPemPickyError.cs new file mode 100644 index 00000000..8a99a97c --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPemPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultPemPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal Pem* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe Pem* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPfxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPfxPickyError.cs new file mode 100644 index 00000000..4d27ce35 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPfxPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultPfxPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal Pfx* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe Pfx* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPkcs12AttributePickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPkcs12AttributePickyError.cs new file mode 100644 index 00000000..d76a36a1 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPkcs12AttributePickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultPkcs12AttributePickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal Pkcs12Attribute* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe Pkcs12Attribute* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPkcs12CryptoContextPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPkcs12CryptoContextPickyError.cs new file mode 100644 index 00000000..91b041c2 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPkcs12CryptoContextPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultPkcs12CryptoContextPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal Pkcs12CryptoContext* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe Pkcs12CryptoContext* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPkcs7PickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPkcs7PickyError.cs new file mode 100644 index 00000000..aa7682aa --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPkcs7PickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultPkcs7PickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal Pkcs7* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe Pkcs7* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPrivateKeyPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPrivateKeyPickyError.cs new file mode 100644 index 00000000..c82ec6a6 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPrivateKeyPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultPrivateKeyPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal PrivateKey* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe PrivateKey* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPublicKeyPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPublicKeyPickyError.cs new file mode 100644 index 00000000..6b4ad3dd --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPublicKeyPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultPublicKeyPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal PublicKey* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe PublicKey* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPuttyPpkPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPuttyPpkPickyError.cs new file mode 100644 index 00000000..b2b8060b --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPuttyPpkPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultPuttyPpkPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal PuttyPpk* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe PuttyPpk* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPuttyPublicKeyPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPuttyPublicKeyPickyError.cs new file mode 100644 index 00000000..53a668d0 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultPuttyPublicKeyPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultPuttyPublicKeyPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal PuttyPublicKey* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe PuttyPublicKey* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSafeBagPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSafeBagPickyError.cs new file mode 100644 index 00000000..50cf5de6 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSafeBagPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultSafeBagPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal SafeBag* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe SafeBag* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSignatureAlgorithmPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSignatureAlgorithmPickyError.cs new file mode 100644 index 00000000..1898f6b2 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSignatureAlgorithmPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultSignatureAlgorithmPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal SignatureAlgorithm* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe SignatureAlgorithm* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSshCertPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSshCertPickyError.cs new file mode 100644 index 00000000..6c6d0621 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSshCertPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultSshCertPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal SshCert* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe SshCert* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSshPrivateKeyPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSshPrivateKeyPickyError.cs new file mode 100644 index 00000000..9b38dfe6 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSshPrivateKeyPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultSshPrivateKeyPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal SshPrivateKey* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe SshPrivateKey* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSshPublicKeyPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSshPublicKeyPickyError.cs new file mode 100644 index 00000000..45bc1a2e --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultSshPublicKeyPickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultSshPublicKeyPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal SshPublicKey* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe SshPublicKey* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultUtcDatePickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultUtcDatePickyError.cs new file mode 100644 index 00000000..bdd4c765 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultUtcDatePickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultUtcDatePickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal UtcDate* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe UtcDate* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultVecU8PickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultVecU8PickyError.cs new file mode 100644 index 00000000..598826ca --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultVecU8PickyError.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultVecU8PickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal VecU8* ok; + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe VecU8* Ok => IsOk ? _inner.ok : throw new InvalidOperationException("Result does not contain Ok value"); + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultVoidBufferTooSmallError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultVoidBufferTooSmallError.cs new file mode 100644 index 00000000..74b4fe3c --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultVoidBufferTooSmallError.cs @@ -0,0 +1,22 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultVoidBufferTooSmallError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal BufferTooSmallError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe BufferTooSmallError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultVoidPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultVoidPickyError.cs new file mode 100644 index 00000000..ea1a3aab --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatResultVoidPickyError.cs @@ -0,0 +1,22 @@ +using System; +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Raw; + +using Devolutions.Picky; +using Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal partial struct DiplomatResultVoidPickyError +{ + [StructLayout(LayoutKind.Explicit)] + private unsafe struct InnerUnion + { + [FieldOffset(0)] internal PickyError* err; + } + + private InnerUnion _inner; + + public DiplomatBool IsOk; + public unsafe PickyError* Err => !IsOk ? _inner.err : throw new InvalidOperationException("Result does not contain Err value"); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatRuntime.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatRuntime.cs deleted file mode 100644 index 061affb9..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatRuntime.cs +++ /dev/null @@ -1,182 +0,0 @@ -// Automatically generated by Diplomat - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Text; - -#if __IOS__ -using ObjCRuntime; -#endif - -namespace Devolutions.Picky.Diplomat; - -#nullable enable - -[UnmanagedFunctionPointer(CallingConvention.Cdecl)] -delegate void WriteableFlush(IntPtr self); - -[UnmanagedFunctionPointer(CallingConvention.Cdecl)] -[return: MarshalAs(UnmanagedType.U1)] -delegate bool WriteableGrow(IntPtr self, nuint capacity); - -[Serializable] -[StructLayout(LayoutKind.Sequential)] -public struct DiplomatWriteable : IDisposable -{ - // About the current approach: - // Ideally DiplomatWriteable should wrap the native string type and grows/writes directly into the internal buffer. - // However, there is no native string type backed by UTF-8 in dotnet frameworks. - // Alternative could be to provide Diplomat's own `Utf8String` type, but this is not trivial and mostly useless - // on its own because all other dotnet/C# APIs are expecting the standard UTF-16 encoded string/String type. - // API is expected to become overall less ergonomic by forcing users to explicitly convert between UTF-16 and UTF-8 anyway in such case. - // It could be useful for copy-free interactions between Diplomat-generated API though. - // Also, there is no way to re-use the unmanaged buffer as-is to get a managed byte[] - // (hence `ToUtf8Bytes` is copying the internal buffer from unmanaged to managed memory). - // It's encouraged to enable memoization when applicable (#129). - - IntPtr context; - IntPtr buf; - nuint len; - nuint cap; - readonly IntPtr flush; - readonly IntPtr grow; - - public DiplomatWriteable() - { - WriteableFlush flushFunc = Flush; - WriteableGrow growFunc = Grow; - - IntPtr flushFuncPtr = Marshal.GetFunctionPointerForDelegate(flushFunc); - IntPtr growFuncPtr = Marshal.GetFunctionPointerForDelegate(growFunc); - - // flushFunc and growFunc are managed objects and might be disposed of by the garbage collector. - // To prevent this, we make the context hold the references and protect the context itself - // for automatic disposal by moving it behind a GCHandle. - DiplomatWriteableContext ctx = new DiplomatWriteableContext(); - ctx.flushFunc = flushFunc; - ctx.growFunc = growFunc; - GCHandle ctxHandle = GCHandle.Alloc(ctx); - - context = GCHandle.ToIntPtr(ctxHandle); - buf = Marshal.AllocHGlobal(64); - len = 0; - cap = 64; - flush = flushFuncPtr; - grow = growFuncPtr; - } - - public byte[] ToUtf8Bytes() - { - if (len > int.MaxValue) - { - throw new IndexOutOfRangeException("DiplomatWriteable buffer is too big"); - } - byte[] managedArray = new byte[(int)len]; - Marshal.Copy(buf, managedArray, 0, (int)len); - return managedArray; - } - - public string ToUnicode() - { -#if NET6_0_OR_GREATER - if (len > int.MaxValue) - { - throw new IndexOutOfRangeException("DiplomatWriteable buffer is too big"); - } - return Marshal.PtrToStringUTF8(buf, (int) len); -#else - byte[] utf8 = ToUtf8Bytes(); - return DiplomatUtils.Utf8ToString(utf8); -#endif - } - - public void Dispose() - { - if (buf != IntPtr.Zero) - { - Marshal.FreeHGlobal(buf); - buf = IntPtr.Zero; - } - - if (context != IntPtr.Zero) - { - GCHandle.FromIntPtr(context).Free(); - context = IntPtr.Zero; - } - } - -#if __IOS__ - [MonoPInvokeCallback(typeof(WriteableFlush))] -#endif - private static void Flush(IntPtr self) - { - // Nothing to do - } - -#if __IOS__ - [MonoPInvokeCallback(typeof(WriteableGrow))] -#endif - [return: MarshalAs(UnmanagedType.U1)] - private unsafe static bool Grow(IntPtr writeable, nuint capacity) - { - if (writeable == IntPtr.Zero) - { - return false; - } - DiplomatWriteable* self = (DiplomatWriteable*)writeable; - - nuint newCap = capacity; - if (newCap > int.MaxValue) - { - return false; - } - - IntPtr newBuf; - try - { - newBuf = Marshal.AllocHGlobal((int)newCap); - } - catch (OutOfMemoryException) - { - return false; - } - - Buffer.MemoryCopy((void*)self->buf, (void*)newBuf, newCap, self->cap); - Marshal.FreeHGlobal(self->buf); - self->buf = newBuf; - self->cap = newCap; - - return true; - } -} - -internal struct DiplomatWriteableContext -{ - internal WriteableFlush flushFunc; - internal WriteableGrow growFunc; -} - -internal static class DiplomatUtils -{ - internal static byte[] StringToUtf8(string s) - { - int size = Encoding.UTF8.GetByteCount(s); - byte[] buf = new byte[size]; - Encoding.UTF8.GetBytes(s, 0, s.Length, buf, 0); - return buf; - } - - internal static string Utf8ToString(byte[] utf8) - { - char[] chars = new char[utf8.Length]; - Encoding.UTF8.GetChars(utf8, 0, utf8.Length, chars, 0); - return new string(chars); - } -} - -public class DiplomatOpaqueException : Exception -{ - public DiplomatOpaqueException() : base("The FFI function failed with an opaque error") { } -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceMutU32.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceMutU32.cs new file mode 100644 index 00000000..6118b30d --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceMutU32.cs @@ -0,0 +1,10 @@ +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal unsafe struct DiplomatSliceMutU32 +{ + public uint* Ptr; + public nuint Len; +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceMutU8.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceMutU8.cs new file mode 100644 index 00000000..efc0006b --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceMutU8.cs @@ -0,0 +1,10 @@ +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal unsafe struct DiplomatSliceMutU8 +{ + public byte* Ptr; + public nuint Len; +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceU32.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceU32.cs new file mode 100644 index 00000000..a1f6fd27 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceU32.cs @@ -0,0 +1,10 @@ +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal unsafe struct DiplomatSliceU32 +{ + public uint* Ptr; + public nuint Len; +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceU8.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceU8.cs new file mode 100644 index 00000000..c59e3921 --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatSliceU8.cs @@ -0,0 +1,10 @@ +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Diplomat; + +[StructLayout(LayoutKind.Sequential)] +internal unsafe struct DiplomatSliceU8 +{ + public byte* Ptr; + public nuint Len; +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DiplomatWrite.cs b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatWrite.cs new file mode 100644 index 00000000..954aff7d --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/DiplomatWrite.cs @@ -0,0 +1,166 @@ +using System; +using System.Runtime.InteropServices; + +#if __IOS__ +using ObjCRuntime; +#endif + +namespace Devolutions.Picky.Diplomat; + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +internal delegate void WriteableFlush(IntPtr self); + +[UnmanagedFunctionPointer(CallingConvention.Cdecl)] +[return: MarshalAs(UnmanagedType.U1)] +internal delegate bool WriteableGrow(IntPtr self, nuint capacity); + +/// +/// Caller-provided writer that Rust appends UTF-8 bytes into. +/// Use after a Rust call returns to extract the +/// written content as a managed string. Dispose to free the underlying +/// unmanaged buffer. +/// +// Mirrors the Rust `DiplomatWrite` repr(C) layout. The `byte growFailed` +// field corresponds to Rust's `grow_failed: bool`; Sequential layout pads +// it to the next 8-byte boundary so `flush`/`grow` land at offsets 40/48. +[StructLayout(LayoutKind.Sequential)] +internal struct DiplomatWrite : IDisposable +{ + IntPtr context; + IntPtr buf; + nuint len; + nuint cap; + byte growFailed; + readonly IntPtr flush; + readonly IntPtr grow; + + public DiplomatWrite() + { + WriteableFlush flushFunc = Flush; + WriteableGrow growFunc = Grow; + + IntPtr flushFuncPtr = Marshal.GetFunctionPointerForDelegate(flushFunc); + IntPtr growFuncPtr = Marshal.GetFunctionPointerForDelegate(growFunc); + + // Hold the delegate objects alive for as long as the function-pointer + // form is in use. Without this, the GC could free the thunks and + // Rust's callback into them would crash. + DiplomatWriteContext ctx = new DiplomatWriteContext + { + flushFunc = flushFunc, + growFunc = growFunc, + }; + GCHandle ctxHandle = GCHandle.Alloc(ctx); + + context = GCHandle.ToIntPtr(ctxHandle); + buf = Marshal.AllocHGlobal(64); + len = 0; + cap = 64; + growFailed = 0; + flush = flushFuncPtr; + grow = growFuncPtr; + } + + public byte[] ToUtf8Bytes() + { + if (len > int.MaxValue) + { + throw new IndexOutOfRangeException("DiplomatWrite buffer is too big"); + } + byte[] managedArray = new byte[(int)len]; + Marshal.Copy(buf, managedArray, 0, (int)len); + return managedArray; + } + + public string ToUnicode() + { + if (len > int.MaxValue) + { + throw new IndexOutOfRangeException("DiplomatWrite buffer is too big"); + } +#if NET6_0_OR_GREATER + return Marshal.PtrToStringUTF8(buf, (int)len) ?? string.Empty; +#else + // `Marshal.PtrToStringUTF8` doesn't exist on netstandard2.0 / .NET + // Framework. Fall back to copying the bytes out and decoding via + // `Encoding.UTF8`, both of which are available there. + return System.Text.Encoding.UTF8.GetString(ToUtf8Bytes()); +#endif + } + + public void Dispose() + { + if (buf != IntPtr.Zero) + { + Marshal.FreeHGlobal(buf); + buf = IntPtr.Zero; + } + + if (context != IntPtr.Zero) + { + GCHandle.FromIntPtr(context).Free(); + context = IntPtr.Zero; + } + } + +#if __IOS__ + [MonoPInvokeCallback(typeof(WriteableFlush))] +#endif + private static void Flush(IntPtr self) + { + // Nothing to do — Rust signals "I'm done writing" but we don't + // need to act on it. The caller will read via ToUnicode() when + // it's ready. + } + +#if __IOS__ + [MonoPInvokeCallback(typeof(WriteableGrow))] +#endif + [return: MarshalAs(UnmanagedType.U1)] + private unsafe static bool Grow(IntPtr writeable, nuint capacity) + { + if (writeable == IntPtr.Zero) + { + return false; + } + DiplomatWrite* self = (DiplomatWrite*)writeable; + + nuint newCap = capacity; + if (newCap > int.MaxValue) + { + return false; + } + + // Rust only ever grows the buffer, but guard against a `newCap` + // smaller than the bytes we're about to copy: `Buffer.MemoryCopy` + // would otherwise read past the new allocation. Refuse the grow + // instead of corrupting unmanaged memory. + if (newCap < self->len) + { + return false; + } + + IntPtr newBuf; + try + { + newBuf = Marshal.AllocHGlobal((int)newCap); + } + catch (OutOfMemoryException) + { + return false; + } + + Buffer.MemoryCopy((void*)self->buf, (void*)newBuf, newCap, self->len); + Marshal.FreeHGlobal(self->buf); + self->buf = newBuf; + self->cap = newCap; + + return true; + } +} + +internal struct DiplomatWriteContext +{ + internal WriteableFlush flushFunc; + internal WriteableGrow growFunc; +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DirectoryName.cs b/ffi/dotnet/Devolutions.Picky/Generated/DirectoryName.cs index 2d436f69..f634568b 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/DirectoryName.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/DirectoryName.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class DirectoryName: IDisposable { - private unsafe Raw.DirectoryName* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.DirectoryName.Destroy; /// /// Creates a managed DirectoryName from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe DirectoryName(Raw.DirectoryName* handle) + internal unsafe DirectoryName(Raw.DirectoryName* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe DirectoryName(Raw.DirectoryName* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe DirectoryName(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,8 +65,8 @@ public static DirectoryName New() { unsafe { - Raw.DirectoryName* retVal = Raw.DirectoryName.New(); - return new DirectoryName(retVal); + Raw.DirectoryName* result = Raw.DirectoryName.New(); + return new DirectoryName(result); } } @@ -48,12 +77,12 @@ public static DirectoryName NewCommonName(string name) { unsafe { - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - nuint nameBufLength = (nuint)nameBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + fixed (byte* namePtr = nameBytes) { - Raw.DirectoryName* retVal = Raw.DirectoryName.NewCommonName(nameBufPtr, nameBufLength); - return new DirectoryName(retVal); + Raw.DirectoryName* result = Raw.DirectoryName.NewCommonName(new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }); + return new DirectoryName(result); } } } @@ -65,16 +94,13 @@ public static DirectoryName NewCommonName(string name) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("DirectoryName"); } - Raw.DirectoryString* retVal = Raw.DirectoryName.FindCommonName(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.DirectoryName.FindCommonName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -82,17 +108,16 @@ public void AddAttr(NameAttr attr, string value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("DirectoryName"); } - byte[] valueBuf = DiplomatUtils.StringToUtf8(value); - nuint valueBufLength = (nuint)valueBuf.Length; - Raw.NameAttr attrRaw; - attrRaw = (Raw.NameAttr)attr; - fixed (byte* valueBufPtr = valueBuf) + if (value == null) throw new ArgumentNullException(nameof(value)); + byte[] valueBytes = System.Text.Encoding.UTF8.GetBytes(value); + fixed (byte* valuePtr = valueBytes) { - Raw.DirectoryName.AddAttr(_inner, attrRaw, valueBufPtr, valueBufLength); + Raw.DirectoryName.AddAttr(AsFFI(), attr, new DiplomatSliceU8 { Ptr = valuePtr, Len = (nuint)valueBytes.Length }); + GC.KeepAlive(this); } } } @@ -102,21 +127,21 @@ public void AddEmail(string email) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("DirectoryName"); } - byte[] emailBuf = DiplomatUtils.StringToUtf8(email); - nuint emailBufLength = (nuint)emailBuf.Length; - fixed (byte* emailBufPtr = emailBuf) + if (email == null) throw new ArgumentNullException(nameof(email)); + byte[] emailBytes = System.Text.Encoding.UTF8.GetBytes(email); + fixed (byte* emailPtr = emailBytes) { - IntPtr resultPtr = Raw.DirectoryName.AddEmail(_inner, emailBufPtr, emailBufLength); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.DirectoryName.AddEmail(AsFFI(), new DiplomatSliceU8 { Ptr = emailPtr, Len = (nuint)emailBytes.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } + return; } } } @@ -124,9 +149,9 @@ public void AddEmail(string email) /// /// Returns the underlying raw handle. /// - public unsafe Raw.DirectoryName* AsFFI() + internal unsafe Raw.DirectoryName* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -136,13 +161,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.DirectoryName.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -152,4 +178,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DirectoryNameIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/DirectoryNameIterator.cs index 90e11ae6..b95cfcf8 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/DirectoryNameIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/DirectoryNameIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,28 +10,60 @@ namespace Devolutions.Picky; public partial class DirectoryNameIterator: IDisposable { - private unsafe Raw.DirectoryNameIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.DirectoryNameIterator.Destroy; /// /// Creates a managed DirectoryNameIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe DirectoryNameIterator(Raw.DirectoryNameIterator* handle) + internal unsafe DirectoryNameIterator(Raw.DirectoryNameIterator* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe DirectoryNameIterator(Raw.DirectoryNameIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe DirectoryNameIterator(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// /// Returns the underlying raw handle. /// - public unsafe Raw.DirectoryNameIterator* AsFFI() + internal unsafe Raw.DirectoryNameIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -44,13 +73,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.DirectoryNameIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -60,4 +90,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DirectoryString.cs b/ffi/dotnet/Devolutions.Picky/Generated/DirectoryString.cs index c8262d34..e64c44e9 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/DirectoryString.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/DirectoryString.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class DirectoryString: IDisposable { - private unsafe Raw.DirectoryString* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.DirectoryString.Destroy; public VecU8 AsBytes { @@ -43,48 +48,51 @@ public DirectoryStringType Type /// Creates a managed DirectoryString from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe DirectoryString(Raw.DirectoryString* handle) + internal unsafe DirectoryString(Raw.DirectoryString* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - /// A DirectoryStringType allocated on C# side. - /// - public DirectoryStringType GetType() + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe DirectoryString(Raw.DirectoryString* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("DirectoryString"); - } - Raw.DirectoryStringType retVal = Raw.DirectoryString.GetType(_inner); - return (DirectoryStringType)retVal; - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } - /// - public void GetAsString(DiplomatWriteable writable) + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe DirectoryString(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + + public DirectoryStringType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("DirectoryString"); } - IntPtr resultPtr = Raw.DirectoryString.GetAsString(_inner, &writable); - Raw.X509StringFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509StringFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } + var result = Raw.DirectoryString.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -93,21 +101,25 @@ public string GetAsString() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("DirectoryString"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.DirectoryString.GetAsString(_inner, &writeable); - Raw.X509StringFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509StringFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.DirectoryString.GetAsString(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -118,21 +130,22 @@ public VecU8 GetAsBytes() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("DirectoryString"); } - Raw.VecU8* retVal = Raw.DirectoryString.GetAsBytes(_inner); - return new VecU8(retVal); + Raw.VecU8* result = Raw.DirectoryString.GetAsBytes(AsFFI()); + GC.KeepAlive(this); + return new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.DirectoryString* AsFFI() + internal unsafe Raw.DirectoryString* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -142,13 +155,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.DirectoryString.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -158,4 +172,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/DirectoryStringType.cs b/ffi/dotnet/Devolutions.Picky/Generated/DirectoryStringType.cs index 1ff66f04..a173dc91 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/DirectoryStringType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/DirectoryStringType.cs @@ -1,19 +1,8 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum DirectoryStringType +public enum DirectoryStringType : int { PrintableString = 0, Utf8String = 1, BmpString = 2, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/EcCurve.cs b/ffi/dotnet/Devolutions.Picky/Generated/EcCurve.cs index f1082583..b17b56bd 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/EcCurve.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/EcCurve.cs @@ -1,31 +1,8 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// Known elliptic curve name used for ECDSA arithmetic operations -/// -public enum EcCurve +public enum EcCurve : int { - /// - /// NIST P-256 - /// NistP256 = 0, - /// - /// NIST P-384 - /// NistP384 = 1, - /// - /// NIST P-521 - /// NistP521 = 2, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/EcParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/EcParameters.cs index 6797e840..45efcdfc 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/EcParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/EcParameters.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,28 +10,60 @@ namespace Devolutions.Picky; public partial class EcParameters: IDisposable { - private unsafe Raw.EcParameters* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.EcParameters.Destroy; /// /// Creates a managed EcParameters from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe EcParameters(Raw.EcParameters* handle) + internal unsafe EcParameters(Raw.EcParameters* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe EcParameters(Raw.EcParameters* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe EcParameters(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// /// Returns the underlying raw handle. /// - public unsafe Raw.EcParameters* AsFFI() + internal unsafe Raw.EcParameters* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -44,13 +73,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.EcParameters.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -60,4 +90,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/EdAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/EdAlgorithm.cs index 3bc774db..e42710ce 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/EdAlgorithm.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/EdAlgorithm.cs @@ -1,27 +1,7 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// Known Edwards curve-based algorithm name -/// -public enum EdAlgorithm +public enum EdAlgorithm : int { - /// - /// Ed25519 signing algorithm - /// Ed25519 = 0, - /// - /// X25519 key agreement algorithm - /// X25519 = 1, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/EdiPartyName.cs b/ffi/dotnet/Devolutions.Picky/Generated/EdiPartyName.cs index 5a19e14a..30d44dde 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/EdiPartyName.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/EdiPartyName.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class EdiPartyName: IDisposable { - private unsafe Raw.EdiPartyName* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.EdiPartyName.Destroy; public DirectoryString? NameAssigner { @@ -35,14 +40,38 @@ public DirectoryString PartyName /// Creates a managed EdiPartyName from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe EdiPartyName(Raw.EdiPartyName* handle) + internal unsafe EdiPartyName(Raw.EdiPartyName* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe EdiPartyName(Raw.EdiPartyName* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe EdiPartyName(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -52,16 +81,13 @@ public unsafe EdiPartyName(Raw.EdiPartyName* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("EdiPartyName"); } - Raw.DirectoryString* retVal = Raw.EdiPartyName.GetNameAssigner(_inner); - if (retVal == null) - { - return null; - } - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.EdiPartyName.GetNameAssigner(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new DirectoryString(result); } } @@ -72,21 +98,22 @@ public DirectoryString GetPartyName() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("EdiPartyName"); } - Raw.DirectoryString* retVal = Raw.EdiPartyName.GetPartyName(_inner); - return new DirectoryString(retVal); + Raw.DirectoryString* result = Raw.EdiPartyName.GetPartyName(AsFFI()); + GC.KeepAlive(this); + return new DirectoryString(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.EdiPartyName* AsFFI() + internal unsafe Raw.EdiPartyName* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -96,13 +123,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.EdiPartyName.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -112,4 +140,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/EncapsulatedContentInfo.cs b/ffi/dotnet/Devolutions.Picky/Generated/EncapsulatedContentInfo.cs index af7fae50..5ab131bb 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/EncapsulatedContentInfo.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/EncapsulatedContentInfo.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,39 +10,52 @@ namespace Devolutions.Picky; public partial class EncapsulatedContentInfo: IDisposable { - private unsafe Raw.EncapsulatedContentInfo* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.EncapsulatedContentInfo.Destroy; /// /// Creates a managed EncapsulatedContentInfo from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe EncapsulatedContentInfo(Raw.EncapsulatedContentInfo* handle) + internal unsafe EncapsulatedContentInfo(Raw.EncapsulatedContentInfo* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void ContentType(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe EncapsulatedContentInfo(Raw.EncapsulatedContentInfo* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("EncapsulatedContentInfo"); - } - IntPtr resultPtr = Raw.EncapsulatedContentInfo.ContentType(_inner, &writable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe EncapsulatedContentInfo(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -53,30 +63,34 @@ public string ContentType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("EncapsulatedContentInfo"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.EncapsulatedContentInfo.ContentType(_inner, &writeable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.EncapsulatedContentInfo.ContentType(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.EncapsulatedContentInfo* AsFFI() + internal unsafe Raw.EncapsulatedContentInfo* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -86,13 +100,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.EncapsulatedContentInfo.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -102,4 +117,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Extension.cs b/ffi/dotnet/Devolutions.Picky/Generated/Extension.cs index 9b8d66d4..a6a7c63c 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Extension.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Extension.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class Extension: IDisposable { - private unsafe Raw.Extension* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Extension.Destroy; public bool Critical { @@ -31,6 +36,10 @@ public string ExtnId } } + /// + /// Lifetime: the returned native-backed value may borrow from the receiver or one or more inputs. + /// The caller is responsible for keeping any borrowed backing storage alive and undisposed while the returned value is in use. + /// public ExtensionView Value { get @@ -43,33 +52,38 @@ public ExtensionView Value /// Creates a managed Extension from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Extension(Raw.Extension* handle) + internal unsafe Extension(Raw.Extension* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void GetExtnId(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Extension(Raw.Extension* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("Extension"); - } - IntPtr resultPtr = Raw.Extension.GetExtnId(_inner, &writable); - Raw.X509ExtensionFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509ExtensionFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Extension(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -77,21 +91,25 @@ public string GetExtnId() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Extension"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.Extension.GetExtnId(_inner, &writeable); - Raw.X509ExtensionFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509ExtensionFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.Extension.GetExtnId(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -99,37 +117,43 @@ public bool GetCritical() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Extension"); } - bool retVal = Raw.Extension.GetCritical(_inner); - return retVal; + var result = Raw.Extension.GetCritical(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// A ExtensionView allocated on Rust side. /// + /// + /// Lifetime: the returned native-backed value may borrow from the receiver or one or more inputs. + /// The caller is responsible for keeping any borrowed backing storage alive and undisposed while the returned value is in use. + /// public ExtensionView GetValue() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Extension"); } - Raw.ExtensionView* retVal = Raw.Extension.GetValue(_inner); - return new ExtensionView(retVal); + Raw.ExtensionView* result = Raw.Extension.GetValue(AsFFI()); + GC.KeepAlive(this); + return new ExtensionView(result, new object[] { this }); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Extension* AsFFI() + internal unsafe Raw.Extension* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -139,13 +163,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Extension.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -155,4 +180,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/ExtensionIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/ExtensionIterator.cs index 05feb16c..3f850690 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/ExtensionIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/ExtensionIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class ExtensionIterator: IDisposable { - private unsafe Raw.ExtensionIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.ExtensionIterator.Destroy; /// /// Creates a managed ExtensionIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe ExtensionIterator(Raw.ExtensionIterator* handle) + internal unsafe ExtensionIterator(Raw.ExtensionIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe ExtensionIterator(Raw.ExtensionIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe ExtensionIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe ExtensionIterator(Raw.ExtensionIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionIterator"); } - Raw.Extension* retVal = Raw.ExtensionIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new Extension(retVal); + Raw.Extension* result = Raw.ExtensionIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new Extension(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.ExtensionIterator* AsFFI() + internal unsafe Raw.ExtensionIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.ExtensionIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/ExtensionView.cs b/ffi/dotnet/Devolutions.Picky/Generated/ExtensionView.cs index 07b551da..3921da9e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/ExtensionView.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/ExtensionView.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class ExtensionView: IDisposable { - private unsafe Raw.ExtensionView* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.ExtensionView.Destroy; public ExtensionViewType Type { @@ -27,29 +32,51 @@ public ExtensionViewType Type /// Creates a managed ExtensionView from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe ExtensionView(Raw.ExtensionView* handle) + internal unsafe ExtensionView(Raw.ExtensionView* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe ExtensionView(Raw.ExtensionView* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe ExtensionView(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A ExtensionViewType allocated on C# side. - /// public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.ExtensionViewType retVal = Raw.ExtensionView.GetType(_inner); - return (ExtensionViewType)retVal; + var result = Raw.ExtensionView.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -60,16 +87,13 @@ public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.AuthorityKeyIdentifier* retVal = Raw.ExtensionView.ToAuthorityKeyIdentifier(_inner); - if (retVal == null) - { - return null; - } - return new AuthorityKeyIdentifier(retVal); + Raw.AuthorityKeyIdentifier* result = Raw.ExtensionView.ToAuthorityKeyIdentifier(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new AuthorityKeyIdentifier(result); } } @@ -80,16 +104,13 @@ public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.VecU8* retVal = Raw.ExtensionView.ToSubjectKeyIdentifier(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.ExtensionView.ToSubjectKeyIdentifier(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -100,16 +121,13 @@ public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.VecU8* retVal = Raw.ExtensionView.ToKeyUsage(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.ExtensionView.ToKeyUsage(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -120,16 +138,13 @@ public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.GeneralNameIterator* retVal = Raw.ExtensionView.ToSubjectAltName(_inner); - if (retVal == null) - { - return null; - } - return new GeneralNameIterator(retVal); + Raw.GeneralNameIterator* result = Raw.ExtensionView.ToSubjectAltName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new GeneralNameIterator(result); } } @@ -140,16 +155,13 @@ public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.GeneralNameIterator* retVal = Raw.ExtensionView.ToIssuerAltName(_inner); - if (retVal == null) - { - return null; - } - return new GeneralNameIterator(retVal); + Raw.GeneralNameIterator* result = Raw.ExtensionView.ToIssuerAltName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new GeneralNameIterator(result); } } @@ -160,16 +172,13 @@ public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.BasicConstraints* retVal = Raw.ExtensionView.ToBasicConstraints(_inner); - if (retVal == null) - { - return null; - } - return new BasicConstraints(retVal); + Raw.BasicConstraints* result = Raw.ExtensionView.ToBasicConstraints(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new BasicConstraints(result); } } @@ -180,16 +189,13 @@ public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.OidIterator* retVal = Raw.ExtensionView.ToExtendedKeyUsage(_inner); - if (retVal == null) - { - return null; - } - return new OidIterator(retVal); + Raw.OidIterator* result = Raw.ExtensionView.ToExtendedKeyUsage(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new OidIterator(result); } } @@ -200,16 +206,13 @@ public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.VecU8* retVal = Raw.ExtensionView.ToGeneric(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.ExtensionView.ToGeneric(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -220,25 +223,22 @@ public ExtensionViewType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("ExtensionView"); } - Raw.VecU8* retVal = Raw.ExtensionView.ToCrlNumber(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.ExtensionView.ToCrlNumber(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.ExtensionView* AsFFI() + internal unsafe Raw.ExtensionView* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -248,13 +248,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.ExtensionView.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -264,4 +265,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/ExtensionViewType.cs b/ffi/dotnet/Devolutions.Picky/Generated/ExtensionViewType.cs index d6a608fe..25e1a269 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/ExtensionViewType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/ExtensionViewType.cs @@ -1,17 +1,6 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum ExtensionViewType +public enum ExtensionViewType : int { AuthorityKeyIdentifier = 0, SubjectKeyIdentifier = 1, @@ -22,4 +11,4 @@ public enum ExtensionViewType ExtendedKeyUsage = 6, Generic = 7, CrlNumber = 8, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/GeneralName.cs b/ffi/dotnet/Devolutions.Picky/Generated/GeneralName.cs index b43d577c..78ffd52c 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/GeneralName.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/GeneralName.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class GeneralName: IDisposable { - private unsafe Raw.GeneralName* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.GeneralName.Destroy; public GeneralNameType Type { @@ -27,29 +32,51 @@ public GeneralNameType Type /// Creates a managed GeneralName from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe GeneralName(Raw.GeneralName* handle) + internal unsafe GeneralName(Raw.GeneralName* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe GeneralName(Raw.GeneralName* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe GeneralName(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A GeneralNameType allocated on C# side. - /// public GeneralNameType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralName"); } - Raw.GeneralNameType retVal = Raw.GeneralName.GetType(_inner); - return (GeneralNameType)retVal; + var result = Raw.GeneralName.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -60,35 +87,13 @@ public GeneralNameType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralName"); } - Raw.OtherName* retVal = Raw.GeneralName.ToOtherName(_inner); - if (retVal == null) - { - return null; - } - return new OtherName(retVal); - } - } - - /// - public void ToRfc822Name(DiplomatWriteable writable) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("GeneralName"); - } - IntPtr resultPtr = Raw.GeneralName.ToRfc822Name(_inner, &writable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } + Raw.OtherName* result = Raw.GeneralName.ToOtherName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new OtherName(result); } } @@ -97,39 +102,24 @@ public string ToRfc822Name() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralName"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.GeneralName.ToRfc822Name(_inner, &writeable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); + var result = Raw.GeneralName.ToRfc822Name(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - public void ToDnsName(DiplomatWriteable writable) - { - unsafe - { - if (_inner == null) + finally { - throw new ObjectDisposedException("GeneralName"); - } - IntPtr resultPtr = Raw.GeneralName.ToDnsName(_inner, &writable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } @@ -139,21 +129,25 @@ public string ToDnsName() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralName"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.GeneralName.ToDnsName(_inner, &writeable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); + var result = Raw.GeneralName.ToDnsName(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally + { + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -164,16 +158,13 @@ public string ToDnsName() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralName"); } - Raw.AttributeTypeAndValueNestedIterator* retVal = Raw.GeneralName.ToDirectoryName(_inner); - if (retVal == null) - { - return null; - } - return new AttributeTypeAndValueNestedIterator(retVal); + Raw.AttributeTypeAndValueNestedIterator* result = Raw.GeneralName.ToDirectoryName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new AttributeTypeAndValueNestedIterator(result); } } @@ -184,58 +175,40 @@ public string ToDnsName() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralName"); } - Raw.EdiPartyName* retVal = Raw.GeneralName.ToEdiPartyName(_inner); - if (retVal == null) - { - return null; - } - return new EdiPartyName(retVal); + Raw.EdiPartyName* result = Raw.GeneralName.ToEdiPartyName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new EdiPartyName(result); } } /// - public void ToUri(DiplomatWriteable writable) + public string ToUri() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralName"); } - IntPtr resultPtr = Raw.GeneralName.ToUri(_inner, &writable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - public string ToUri() - { - unsafe - { - if (_inner == null) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("GeneralName"); + var result = Raw.GeneralName.ToUri(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.GeneralName.ToUri(_inner, &writeable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -246,67 +219,49 @@ public string ToUri() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralName"); } - Raw.VecU8* retVal = Raw.GeneralName.ToIpAddress(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.GeneralName.ToIpAddress(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } /// - public void ToRegisteredId(DiplomatWriteable writable) + public string ToRegisteredId() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralName"); } - IntPtr resultPtr = Raw.GeneralName.ToRegisteredId(_inner, &writable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - public string ToRegisteredId() - { - unsafe - { - if (_inner == null) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("GeneralName"); + var result = Raw.GeneralName.ToRegisteredId(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.GeneralName.ToRegisteredId(_inner, &writeable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.GeneralName* AsFFI() + internal unsafe Raw.GeneralName* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -316,13 +271,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.GeneralName.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -332,4 +288,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/GeneralNameIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/GeneralNameIterator.cs index 1b87a424..1520b991 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/GeneralNameIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/GeneralNameIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class GeneralNameIterator: IDisposable { - private unsafe Raw.GeneralNameIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.GeneralNameIterator.Destroy; /// /// Creates a managed GeneralNameIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe GeneralNameIterator(Raw.GeneralNameIterator* handle) + internal unsafe GeneralNameIterator(Raw.GeneralNameIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe GeneralNameIterator(Raw.GeneralNameIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe GeneralNameIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe GeneralNameIterator(Raw.GeneralNameIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("GeneralNameIterator"); } - Raw.GeneralName* retVal = Raw.GeneralNameIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new GeneralName(retVal); + Raw.GeneralName* result = Raw.GeneralNameIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new GeneralName(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.GeneralNameIterator* AsFFI() + internal unsafe Raw.GeneralNameIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.GeneralNameIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/GeneralNameType.cs b/ffi/dotnet/Devolutions.Picky/Generated/GeneralNameType.cs index 7a40e529..a7180d4a 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/GeneralNameType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/GeneralNameType.cs @@ -1,17 +1,6 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum GeneralNameType +public enum GeneralNameType : int { OtherName = 0, Rfc822Name = 1, @@ -21,4 +10,4 @@ public enum GeneralNameType Uri = 5, IpAddress = 6, RegisteredId = 7, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/GetCaResult.cs b/ffi/dotnet/Devolutions.Picky/Generated/GetCaResult.cs index 7331492a..68bf14ab 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/GetCaResult.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/GetCaResult.cs @@ -1,19 +1,8 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum GetCaResult +public enum GetCaResult : int { None = 0, True = 1, False = 2, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/HashAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/HashAlgorithm.cs index ff948a89..70397d9b 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/HashAlgorithm.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/HashAlgorithm.cs @@ -1,25 +1,14 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum HashAlgorithm +public enum HashAlgorithm : int { - MD5 = 0, - SHA1 = 1, - SHA2_224 = 2, - SHA2_256 = 3, - SHA2_384 = 4, - SHA2_512 = 5, - SHA3_384 = 6, - SHA3_512 = 7, + Md5 = 0, + Sha1 = 1, + Sha2224 = 2, + Sha2256 = 3, + Sha2384 = 4, + Sha2512 = 5, + Sha3384 = 6, + Sha3512 = 7, Unknown = 8, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/IssuerAndSerialNumber.cs b/ffi/dotnet/Devolutions.Picky/Generated/IssuerAndSerialNumber.cs index 62dde471..66a00550 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/IssuerAndSerialNumber.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/IssuerAndSerialNumber.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class IssuerAndSerialNumber: IDisposable { - private unsafe Raw.IssuerAndSerialNumber* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.IssuerAndSerialNumber.Destroy; public string Issuer { @@ -27,33 +32,38 @@ public string Issuer /// Creates a managed IssuerAndSerialNumber from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe IssuerAndSerialNumber(Raw.IssuerAndSerialNumber* handle) + internal unsafe IssuerAndSerialNumber(Raw.IssuerAndSerialNumber* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void GetIssuer(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe IssuerAndSerialNumber(Raw.IssuerAndSerialNumber* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("IssuerAndSerialNumber"); - } - IntPtr resultPtr = Raw.IssuerAndSerialNumber.GetIssuer(_inner, &writable); - Raw.X509SingerInfoFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509SingerInfoFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe IssuerAndSerialNumber(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -61,30 +71,34 @@ public string GetIssuer() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("IssuerAndSerialNumber"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.IssuerAndSerialNumber.GetIssuer(_inner, &writeable); - Raw.X509SingerInfoFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509SingerInfoFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.IssuerAndSerialNumber.GetIssuer(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.IssuerAndSerialNumber* AsFFI() + internal unsafe Raw.IssuerAndSerialNumber* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -94,13 +108,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.IssuerAndSerialNumber.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -110,4 +125,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/JwsAlg.cs b/ffi/dotnet/Devolutions.Picky/Generated/JwsAlg.cs index f962303b..a4794cb0 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/JwsAlg.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/JwsAlg.cs @@ -1,79 +1,19 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// `alg` header parameter values for JWS -/// -public enum JwsAlg +public enum JwsAlg : int { - /// - /// RSASSA-PKCS-v1_5 using SHA-256 - /// - RS256 = 0, - /// - /// RSASSA-PKCS-v1_5 using SHA-384 - /// - RS384 = 1, - /// - /// RSASSA-PKCS-v1_5 using SHA-512 - /// - RS512 = 2, - /// - /// HMAC using SHA-256 (unsupported) - /// - HS256 = 3, - /// - /// HMAC using SHA-384 (unsupported) - /// - HS384 = 4, - /// - /// HMAC using SHA-512 (unsupported) - /// - HS512 = 5, - /// - /// ECDSA using P-256 and SHA-256 - /// - ES256 = 6, - /// - /// ECDSA using P-384 and SHA-384 - /// - ES384 = 7, - /// - /// ECDSA using P-521 and SHA-512 - /// - ES512 = 8, - /// - /// RSASSA-PSS using SHA-256 and MGF1 with SHA-256 (unsupported) - /// - PS256 = 9, - /// - /// RSASSA-PSS using SHA-384 and MGF1 with SHA-384 (unsupported) - /// - PS384 = 10, - /// - /// RSASSA-PSS using SHA-512 and MGF1 with SHA-512 (unsupported) - /// - PS512 = 11, - /// - /// EdDSA using Ed25519/Ed448 - /// - EdDSA = 12, - /// - /// [DO NOT USE] EdDSA using Ed25519 - /// - /// - /// This value is used by some popular libraries (e.g. `golang-jwt) instead of `EdDSA` due to - /// mistake in the implementation. This value is deprecated and should not be used. - /// - ED25519 = 13, -} + Rs256 = 0, + Rs384 = 1, + Rs512 = 2, + Hs256 = 3, + Hs384 = 4, + Hs512 = 5, + Es256 = 6, + Es384 = 7, + Es512 = 8, + Ps256 = 9, + Ps384 = 10, + Ps512 = 11, + EdDsa = 12, + Ed25519 = 13, +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/JwtSig.cs b/ffi/dotnet/Devolutions.Picky/Generated/JwtSig.cs index a57bfe47..c5e7d248 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/JwtSig.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/JwtSig.cs @@ -1,25 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// Signed JSON Web Token object. -/// -/// -/// This is a JWS (JSON Web Signature) structure with JWT claims contained in a JSON payload. -/// public partial class JwtSig: IDisposable { - private unsafe Raw.JwtSig* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.JwtSig.Destroy; public string Claims { @@ -57,223 +56,160 @@ public string Kid /// Creates a managed JwtSig from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe JwtSig(Raw.JwtSig* handle) + internal unsafe JwtSig(Raw.JwtSig* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - /// A JwtSigBuilder allocated on Rust side. - /// - public static JwtSigBuilder Builder() + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe JwtSig(Raw.JwtSig* handle, object[] edges) { - unsafe - { - Raw.JwtSigBuilder* retVal = Raw.JwtSig.Builder(); - return new JwtSigBuilder(retVal); - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Returns the content type. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// - /// - public void GetContentType(DiplomatWriteable writeable) + internal unsafe JwtSig(RustHandle inner, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("JwtSig"); - } - IntPtr resultPtr = Raw.JwtSig.GetContentType(_inner, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = inner; + _edges = edges; } - /// - /// Returns the content type. - /// - /// - public string GetContentType() + /// + /// A JwtSigBuilder allocated on Rust side. + /// + public static JwtSigBuilder Builder() { unsafe { - if (_inner == null) - { - throw new ObjectDisposedException("JwtSig"); - } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.JwtSig.GetContentType(_inner, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; + Raw.JwtSigBuilder* result = Raw.JwtSig.Builder(); + return new JwtSigBuilder(result); } } - /// - /// Returns the key ID. - /// /// - public void GetKid(DiplomatWriteable writeable) + public string GetContentType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSig"); } - IntPtr resultPtr = Raw.JwtSig.GetKid(_inner, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.JwtSig.GetContentType(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } - /// - /// Returns the key ID. - /// /// public string GetKid() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSig"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.JwtSig.GetKid(_inner, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - /// Returns the header as a JSON encoded payload. - /// - /// - public void GetHeader(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("JwtSig"); + var result = Raw.JwtSig.GetKid(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - IntPtr resultPtr = Raw.JwtSig.GetHeader(_inner, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } - /// - /// Returns the header as a JSON encoded payload. - /// /// public string GetHeader() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSig"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.JwtSig.GetHeader(_inner, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - /// Returns the claims as a JSON encoded payload. - /// - /// - public void GetClaims(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("JwtSig"); + var result = Raw.JwtSig.GetHeader(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - IntPtr resultPtr = Raw.JwtSig.GetClaims(_inner, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } - /// - /// Returns the claims as a JSON encoded payload. - /// /// public string GetClaims() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSig"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.JwtSig.GetClaims(_inner, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); + var result = Raw.JwtSig.GetClaims(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally + { + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } - /// - /// Decode JWT and check signature using provided public key. - /// /// /// /// A JwtSig allocated on Rust side. @@ -282,38 +218,28 @@ public static JwtSig Decode(string compactRepr, PublicKey publicKey, JwtValidato { unsafe { - byte[] compactReprBuf = DiplomatUtils.StringToUtf8(compactRepr); - nuint compactReprBufLength = (nuint)compactReprBuf.Length; - Raw.PublicKey* publicKeyRaw; - publicKeyRaw = publicKey.AsFFI(); - if (publicKeyRaw == null) - { - throw new ObjectDisposedException("PublicKey"); - } - Raw.JwtValidator* validatorRaw; - validatorRaw = validator.AsFFI(); - if (validatorRaw == null) + if (compactRepr == null) throw new ArgumentNullException(nameof(compactRepr)); + if (publicKey == null) throw new ArgumentNullException(nameof(publicKey)); + Raw.PublicKey* publicKeyRaw = publicKey.AsFFI(); + if (publicKeyRaw == null) throw new ObjectDisposedException(nameof(PublicKey)); + if (validator == null) throw new ArgumentNullException(nameof(validator)); + Raw.JwtValidator* validatorRaw = validator.AsFFI(); + if (validatorRaw == null) throw new ObjectDisposedException(nameof(JwtValidator)); + byte[] compactReprBytes = System.Text.Encoding.UTF8.GetBytes(compactRepr); + fixed (byte* compactReprPtr = compactReprBytes) { - throw new ObjectDisposedException("JwtValidator"); - } - fixed (byte* compactReprBufPtr = compactReprBuf) - { - IntPtr resultPtr = Raw.JwtSig.Decode(compactReprBufPtr, compactReprBufLength, publicKeyRaw, validatorRaw); - Raw.JwtFfiResultBoxJwtSigBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultBoxJwtSigBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.JwtSig.Decode(new DiplomatSliceU8 { Ptr = compactReprPtr, Len = (nuint)compactReprBytes.Length }, publicKeyRaw, validatorRaw); + GC.KeepAlive(publicKey); + GC.KeepAlive(validator); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.JwtSig* retVal = result.Ok; - return new JwtSig(retVal); + return new JwtSig(result.Ok); } } } - /// - /// Decode JWT WITHOUT CHECKING THE SIGNATURE. Useful for token inspection. - /// /// /// /// A JwtSig allocated on Rust side. @@ -322,89 +248,57 @@ public static JwtSig DecodeUnchecked(string compactRepr) { unsafe { - byte[] compactReprBuf = DiplomatUtils.StringToUtf8(compactRepr); - nuint compactReprBufLength = (nuint)compactReprBuf.Length; - fixed (byte* compactReprBufPtr = compactReprBuf) + if (compactRepr == null) throw new ArgumentNullException(nameof(compactRepr)); + byte[] compactReprBytes = System.Text.Encoding.UTF8.GetBytes(compactRepr); + fixed (byte* compactReprPtr = compactReprBytes) { - IntPtr resultPtr = Raw.JwtSig.DecodeUnchecked(compactReprBufPtr, compactReprBufLength); - Raw.JwtFfiResultBoxJwtSigBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultBoxJwtSigBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.JwtSig.DecodeUnchecked(new DiplomatSliceU8 { Ptr = compactReprPtr, Len = (nuint)compactReprBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.JwtSig* retVal = result.Ok; - return new JwtSig(retVal); - } - } - } - - /// - /// Encode using the given private key and returns the compact representation of this token. - /// - /// - public void Encode(PrivateKey key, DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("JwtSig"); - } - Raw.PrivateKey* keyRaw; - keyRaw = key.AsFFI(); - if (keyRaw == null) - { - throw new ObjectDisposedException("PrivateKey"); - } - IntPtr resultPtr = Raw.JwtSig.Encode(_inner, keyRaw, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); + return new JwtSig(result.Ok); } } } - /// - /// Encode using the given private key and returns the compact representation of this token. - /// /// public string Encode(PrivateKey key) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSig"); } - Raw.PrivateKey* keyRaw; - keyRaw = key.AsFFI(); - if (keyRaw == null) + if (key == null) throw new ArgumentNullException(nameof(key)); + Raw.PrivateKey* keyRaw = key.AsFFI(); + if (keyRaw == null) throw new ObjectDisposedException(nameof(PrivateKey)); + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("PrivateKey"); + var result = Raw.JwtSig.Encode(AsFFI(), keyRaw, &writeable); + GC.KeepAlive(this); + GC.KeepAlive(key); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.JwtSig.Encode(_inner, keyRaw, &writeable); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.JwtSig* AsFFI() + internal unsafe Raw.JwtSig* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -414,13 +308,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.JwtSig.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -430,4 +325,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/JwtSigBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/JwtSigBuilder.cs index 87fa5233..09ab23f7 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/JwtSigBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/JwtSigBuilder.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,52 +10,52 @@ namespace Devolutions.Picky; public partial class JwtSigBuilder: IDisposable { - private unsafe Raw.JwtSigBuilder* _inner; - - public JwsAlg Algorithm - { - set - { - SetAlgorithm(value); - } - } - - public string Claims - { - set - { - SetClaims(value); - } - } + private unsafe RustHandle _inner; - public string ContentType - { - set - { - SetContentType(value); - } - } + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; - public string Kid - { - set - { - SetKid(value); - } - } + private static readonly unsafe RustDestructor _destroy = Raw.JwtSigBuilder.Destroy; /// /// Creates a managed JwtSigBuilder from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe JwtSigBuilder(Raw.JwtSigBuilder* handle) + internal unsafe JwtSigBuilder(Raw.JwtSigBuilder* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe JwtSigBuilder(Raw.JwtSigBuilder* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe JwtSigBuilder(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -68,8 +65,8 @@ public static JwtSigBuilder Init() { unsafe { - Raw.JwtSigBuilder* retVal = Raw.JwtSigBuilder.Init(); - return new JwtSigBuilder(retVal); + Raw.JwtSigBuilder* result = Raw.JwtSigBuilder.Init(); + return new JwtSigBuilder(result); } } @@ -77,13 +74,12 @@ public void SetAlgorithm(JwsAlg alg) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - Raw.JwsAlg algRaw; - algRaw = (Raw.JwsAlg)alg; - Raw.JwtSigBuilder.SetAlgorithm(_inner, algRaw); + Raw.JwtSigBuilder.SetAlgorithm(AsFFI(), alg); + GC.KeepAlive(this); } } @@ -91,15 +87,16 @@ public void SetContentType(string cty) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - byte[] ctyBuf = DiplomatUtils.StringToUtf8(cty); - nuint ctyBufLength = (nuint)ctyBuf.Length; - fixed (byte* ctyBufPtr = ctyBuf) + if (cty == null) throw new ArgumentNullException(nameof(cty)); + byte[] ctyBytes = System.Text.Encoding.UTF8.GetBytes(cty); + fixed (byte* ctyPtr = ctyBytes) { - Raw.JwtSigBuilder.SetContentType(_inner, ctyBufPtr, ctyBufLength); + Raw.JwtSigBuilder.SetContentType(AsFFI(), new DiplomatSliceU8 { Ptr = ctyPtr, Len = (nuint)ctyBytes.Length }); + GC.KeepAlive(this); } } } @@ -108,200 +105,160 @@ public void SetKid(string kid) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - byte[] kidBuf = DiplomatUtils.StringToUtf8(kid); - nuint kidBufLength = (nuint)kidBuf.Length; - fixed (byte* kidBufPtr = kidBuf) + if (kid == null) throw new ArgumentNullException(nameof(kid)); + byte[] kidBytes = System.Text.Encoding.UTF8.GetBytes(kid); + fixed (byte* kidPtr = kidBytes) { - Raw.JwtSigBuilder.SetKid(_inner, kidBufPtr, kidBufLength); + Raw.JwtSigBuilder.SetKid(AsFFI(), new DiplomatSliceU8 { Ptr = kidPtr, Len = (nuint)kidBytes.Length }); + GC.KeepAlive(this); } } } - /// - /// Adds a JSON object as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// /// public void AddAdditionalParameterObject(string name, string obj) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - byte[] objBuf = DiplomatUtils.StringToUtf8(obj); - nuint nameBufLength = (nuint)nameBuf.Length; - nuint objBufLength = (nuint)objBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + if (obj == null) throw new ArgumentNullException(nameof(obj)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + byte[] objBytes = System.Text.Encoding.UTF8.GetBytes(obj); + fixed (byte* namePtr = nameBytes) + fixed (byte* objPtr = objBytes) { - fixed (byte* objBufPtr = objBuf) + var result = Raw.JwtSigBuilder.AddAdditionalParameterObject(AsFFI(), new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }, new DiplomatSliceU8 { Ptr = objPtr, Len = (nuint)objBytes.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { - IntPtr resultPtr = Raw.JwtSigBuilder.AddAdditionalParameterObject(_inner, nameBufPtr, nameBufLength, objBufPtr, objBufLength); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } + throw new PickyException(new PickyError(result.Err)); } + return; } } } - /// - /// Adds a boolean as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// public void AddAdditionalParameterBool(string name, bool value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - nuint nameBufLength = (nuint)nameBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + fixed (byte* namePtr = nameBytes) { - Raw.JwtSigBuilder.AddAdditionalParameterBool(_inner, nameBufPtr, nameBufLength, value); + Raw.JwtSigBuilder.AddAdditionalParameterBool(AsFFI(), new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }, value); + GC.KeepAlive(this); } } } - /// - /// Adds a positive number as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// public void AddAdditionalParameterPosInt(string name, ulong value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - nuint nameBufLength = (nuint)nameBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + fixed (byte* namePtr = nameBytes) { - Raw.JwtSigBuilder.AddAdditionalParameterPosInt(_inner, nameBufPtr, nameBufLength, value); + Raw.JwtSigBuilder.AddAdditionalParameterPosInt(AsFFI(), new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }, value); + GC.KeepAlive(this); } } } - /// - /// Adds a possibly negative number as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// public void AddAdditionalParameterNegInt(string name, long value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - nuint nameBufLength = (nuint)nameBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + fixed (byte* namePtr = nameBytes) { - Raw.JwtSigBuilder.AddAdditionalParameterNegInt(_inner, nameBufPtr, nameBufLength, value); + Raw.JwtSigBuilder.AddAdditionalParameterNegInt(AsFFI(), new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }, value); + GC.KeepAlive(this); } } } - /// - /// Adds a float as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// public void AddAdditionalParameterFloat(string name, long value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - nuint nameBufLength = (nuint)nameBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + fixed (byte* namePtr = nameBytes) { - Raw.JwtSigBuilder.AddAdditionalParameterFloat(_inner, nameBufPtr, nameBufLength, value); + Raw.JwtSigBuilder.AddAdditionalParameterFloat(AsFFI(), new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }, value); + GC.KeepAlive(this); } } } - /// - /// Adds a float as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// public void AddAdditionalParameterString(string name, string value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - byte[] valueBuf = DiplomatUtils.StringToUtf8(value); - nuint nameBufLength = (nuint)nameBuf.Length; - nuint valueBufLength = (nuint)valueBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + if (value == null) throw new ArgumentNullException(nameof(value)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + byte[] valueBytes = System.Text.Encoding.UTF8.GetBytes(value); + fixed (byte* namePtr = nameBytes) + fixed (byte* valuePtr = valueBytes) { - fixed (byte* valueBufPtr = valueBuf) - { - Raw.JwtSigBuilder.AddAdditionalParameterString(_inner, nameBufPtr, nameBufLength, valueBufPtr, valueBufLength); - } + Raw.JwtSigBuilder.AddAdditionalParameterString(AsFFI(), new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }, new DiplomatSliceU8 { Ptr = valuePtr, Len = (nuint)valueBytes.Length }); + GC.KeepAlive(this); } } } - /// - /// Sets the given JSON payload. - /// - /// - /// Claims should be a valid JSON payload. - /// /// public void SetClaims(string claims) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - byte[] claimsBuf = DiplomatUtils.StringToUtf8(claims); - nuint claimsBufLength = (nuint)claimsBuf.Length; - fixed (byte* claimsBufPtr = claimsBuf) + if (claims == null) throw new ArgumentNullException(nameof(claims)); + byte[] claimsBytes = System.Text.Encoding.UTF8.GetBytes(claims); + fixed (byte* claimsPtr = claimsBytes) { - IntPtr resultPtr = Raw.JwtSigBuilder.SetClaims(_inner, claimsBufPtr, claimsBufLength); - Raw.JwtFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.JwtFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.JwtSigBuilder.SetClaims(AsFFI(), new DiplomatSliceU8 { Ptr = claimsPtr, Len = (nuint)claimsBytes.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } + return; } } } @@ -313,21 +270,22 @@ public JwtSig Build() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("JwtSigBuilder"); } - Raw.JwtSig* retVal = Raw.JwtSigBuilder.Build(_inner); - return new JwtSig(retVal); + Raw.JwtSig* result = Raw.JwtSigBuilder.Build(AsFFI()); + GC.KeepAlive(this); + return new JwtSig(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.JwtSigBuilder* AsFFI() + internal unsafe Raw.JwtSigBuilder* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -337,13 +295,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.JwtSigBuilder.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -353,4 +312,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/JwtValidator.cs b/ffi/dotnet/Devolutions.Picky/Generated/JwtValidator.cs index 620f01cb..01987355 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/JwtValidator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/JwtValidator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,25 +10,54 @@ namespace Devolutions.Picky; public partial class JwtValidator: IDisposable { - private unsafe Raw.JwtValidator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.JwtValidator.Destroy; /// /// Creates a managed JwtValidator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe JwtValidator(Raw.JwtValidator* handle) + internal unsafe JwtValidator(Raw.JwtValidator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe JwtValidator(Raw.JwtValidator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Check signature and the registered exp and nbf claims. If a claim is missing token is rejected. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe JwtValidator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// A JwtValidator allocated on Rust side. /// @@ -39,14 +65,11 @@ public static JwtValidator Strict(long numericDate, ushort leeway) { unsafe { - Raw.JwtValidator* retVal = Raw.JwtValidator.Strict(numericDate, leeway); - return new JwtValidator(retVal); + Raw.JwtValidator* result = Raw.JwtValidator.Strict(numericDate, leeway); + return new JwtValidator(result); } } - /// - /// Check signature and the registered exp and nbf claims. Token isn't rejected if a claim is missing. - /// /// /// A JwtValidator allocated on Rust side. /// @@ -54,14 +77,11 @@ public static JwtValidator Lenient(long numericDate, ushort leeway) { unsafe { - Raw.JwtValidator* retVal = Raw.JwtValidator.Lenient(numericDate, leeway); - return new JwtValidator(retVal); + Raw.JwtValidator* result = Raw.JwtValidator.Lenient(numericDate, leeway); + return new JwtValidator(result); } } - /// - /// No check. - /// /// /// A JwtValidator allocated on Rust side. /// @@ -69,17 +89,17 @@ public static JwtValidator NoCheck() { unsafe { - Raw.JwtValidator* retVal = Raw.JwtValidator.NoCheck(); - return new JwtValidator(retVal); + Raw.JwtValidator* result = Raw.JwtValidator.NoCheck(); + return new JwtValidator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.JwtValidator* AsFFI() + internal unsafe Raw.JwtValidator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -89,13 +109,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.JwtValidator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -105,4 +126,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/KeyKind.cs b/ffi/dotnet/Devolutions.Picky/Generated/KeyKind.cs index 53c58008..31cb01f6 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/KeyKind.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/KeyKind.cs @@ -1,35 +1,9 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// Known key kinds -/// -public enum KeyKind +public enum KeyKind : int { - /// - /// RSA (Rivest–Shamir–Adleman) - /// Rsa = 0, - /// - /// Elliptic-curve - /// Ec = 1, - /// - /// Edwards-curve - /// Ed = 2, - /// - /// MLDSA (Module-Lattice-Based Digital Signature Algorithm) - /// Mldsa = 3, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/MsCounterSign.cs b/ffi/dotnet/Devolutions.Picky/Generated/MsCounterSign.cs index 41032539..b5ab3d16 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/MsCounterSign.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/MsCounterSign.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class MsCounterSign: IDisposable { - private unsafe Raw.MsCounterSign* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.MsCounterSign.Destroy; public string Oid { @@ -35,33 +40,38 @@ public SignedData SignedData /// Creates a managed MsCounterSign from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe MsCounterSign(Raw.MsCounterSign* handle) + internal unsafe MsCounterSign(Raw.MsCounterSign* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void GetOid(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe MsCounterSign(Raw.MsCounterSign* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("MsCounterSign"); - } - IntPtr resultPtr = Raw.MsCounterSign.GetOid(_inner, &writable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe MsCounterSign(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -69,21 +79,25 @@ public string GetOid() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("MsCounterSign"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.MsCounterSign.GetOid(_inner, &writeable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.MsCounterSign.GetOid(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -94,21 +108,22 @@ public SignedData GetSignedData() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("MsCounterSign"); } - Raw.SignedData* retVal = Raw.MsCounterSign.GetSignedData(_inner); - return new SignedData(retVal); + Raw.SignedData* result = Raw.MsCounterSign.GetSignedData(AsFFI()); + GC.KeepAlive(this); + return new SignedData(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.MsCounterSign* AsFFI() + internal unsafe Raw.MsCounterSign* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -118,13 +133,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.MsCounterSign.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -134,4 +150,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/MsCounterSignIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/MsCounterSignIterator.cs index dbb8c4b8..a5acd793 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/MsCounterSignIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/MsCounterSignIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class MsCounterSignIterator: IDisposable { - private unsafe Raw.MsCounterSignIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.MsCounterSignIterator.Destroy; /// /// Creates a managed MsCounterSignIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe MsCounterSignIterator(Raw.MsCounterSignIterator* handle) + internal unsafe MsCounterSignIterator(Raw.MsCounterSignIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe MsCounterSignIterator(Raw.MsCounterSignIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe MsCounterSignIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe MsCounterSignIterator(Raw.MsCounterSignIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("MsCounterSignIterator"); } - Raw.MsCounterSign* retVal = Raw.MsCounterSignIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new MsCounterSign(retVal); + Raw.MsCounterSign* result = Raw.MsCounterSignIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new MsCounterSign(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.MsCounterSignIterator* AsFFI() + internal unsafe Raw.MsCounterSignIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.MsCounterSignIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/NameAttr.cs b/ffi/dotnet/Devolutions.Picky/Generated/NameAttr.cs index 69a47e31..44123b40 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/NameAttr.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/NameAttr.cs @@ -1,17 +1,6 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum NameAttr +public enum NameAttr : int { CommonName = 0, Surname = 1, @@ -24,4 +13,4 @@ public enum NameAttr OrganizationalUnitName = 8, GivenName = 9, Phone = 10, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/NativeLib.cs b/ffi/dotnet/Devolutions.Picky/Generated/NativeLib.cs new file mode 100644 index 00000000..4fb1f16a --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/NativeLib.cs @@ -0,0 +1,15 @@ +using System.Runtime.InteropServices; + +namespace Devolutions.Picky.Diplomat; + +// Shared native-library name for every `[DllImport]` in the raw layer. +// Emitted once per generation run so the iOS framework-bundle path and the +// bare name aren't duplicated into every `Raw*` struct. +internal static class DiplomatNativeLib +{ +#if __IOS__ + internal const string Name = "libDevolutionsPicky.framework/libDevolutionsPicky"; +#else + internal const string Name = "DevolutionsPicky"; +#endif +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/OidIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/OidIterator.cs index 63c83a8c..5af4bdcf 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/OidIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/OidIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,39 +10,52 @@ namespace Devolutions.Picky; public partial class OidIterator: IDisposable { - private unsafe Raw.OidIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.OidIterator.Destroy; /// /// Creates a managed OidIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe OidIterator(Raw.OidIterator* handle) + internal unsafe OidIterator(Raw.OidIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void Next(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe OidIterator(Raw.OidIterator* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("OidIterator"); - } - IntPtr resultPtr = Raw.OidIterator.Next(_inner, &writable); - Raw.X509ExtensionFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509ExtensionFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe OidIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -53,30 +63,34 @@ public string Next() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("OidIterator"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.OidIterator.Next(_inner, &writeable); - Raw.X509ExtensionFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509ExtensionFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.OidIterator.Next(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.OidIterator* AsFFI() + internal unsafe Raw.OidIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -86,13 +100,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.OidIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -102,4 +117,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/OtherName.cs b/ffi/dotnet/Devolutions.Picky/Generated/OtherName.cs index cbdb1160..863a32c1 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/OtherName.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/OtherName.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class OtherName: IDisposable { - private unsafe Raw.OtherName* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.OtherName.Destroy; public string TypeId { @@ -35,33 +40,38 @@ public VecU8 Value /// Creates a managed OtherName from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe OtherName(Raw.OtherName* handle) + internal unsafe OtherName(Raw.OtherName* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void GetTypeId(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe OtherName(Raw.OtherName* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("OtherName"); - } - IntPtr resultPtr = Raw.OtherName.GetTypeId(_inner, &writable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe OtherName(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -69,21 +79,25 @@ public string GetTypeId() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("OtherName"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.OtherName.GetTypeId(_inner, &writeable); - Raw.X509NameFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509NameFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.OtherName.GetTypeId(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -94,21 +108,22 @@ public VecU8 GetValue() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("OtherName"); } - Raw.VecU8* retVal = Raw.OtherName.GetValue(_inner); - return new VecU8(retVal); + Raw.VecU8* result = Raw.OtherName.GetValue(AsFFI()); + GC.KeepAlive(this); + return new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.OtherName* AsFFI() + internal unsafe Raw.OtherName* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -118,13 +133,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.OtherName.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -134,4 +150,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pbes1Cipher.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pbes1Cipher.cs index b3ca5637..fc164a77 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pbes1Cipher.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pbes1Cipher.cs @@ -1,21 +1,7 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// Pkcs12Pbe is deprecated and should not be used in general. -/// -public enum Pbes1Cipher +public enum Pbes1Cipher : int { ShaAnd40BitRc2Cbc = 0, ShaAnd3Key3DesCbc = 1, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pbes2Cipher.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pbes2Cipher.cs index 57c6eeb8..9a141428 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pbes2Cipher.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pbes2Cipher.cs @@ -1,22 +1,8 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// PBES2 cipher algorithm -/// -public enum Pbes2Cipher +public enum Pbes2Cipher : int { Aes128Cbc = 0, Aes192Cbc = 1, Aes256Cbc = 2, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pem.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pem.cs index 47bb35a3..2a314a33 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pem.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pem.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// PEM object. -/// public partial class Pem: IDisposable { - private unsafe Raw.Pem* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Pem.Destroy; public ulong DataLength { @@ -38,19 +40,40 @@ public string Label /// Creates a managed Pem from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Pem(Raw.Pem* handle) + internal unsafe Pem(Raw.Pem* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Pem(Raw.Pem* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Creates a PEM object with the given label and data. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe Pem(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A Pem allocated on Rust side. @@ -59,30 +82,22 @@ public static Pem New(string label, byte[] data) { unsafe { - byte[] labelBuf = DiplomatUtils.StringToUtf8(label); - nuint dataLength = (nuint)data.Length; - nuint labelBufLength = (nuint)labelBuf.Length; + if (label == null) throw new ArgumentNullException(nameof(label)); + if (data == null) throw new ArgumentNullException(nameof(data)); + byte[] labelBytes = System.Text.Encoding.UTF8.GetBytes(label); + fixed (byte* labelPtr = labelBytes) fixed (byte* dataPtr = data) { - fixed (byte* labelBufPtr = labelBuf) + var result = Raw.Pem.New(new DiplomatSliceU8 { Ptr = labelPtr, Len = (nuint)labelBytes.Length }, new DiplomatSliceU8 { Ptr = dataPtr, Len = (nuint)data.Length }); + if (!result.IsOk) { - IntPtr resultPtr = Raw.Pem.New(labelBufPtr, labelBufLength, dataPtr, dataLength); - Raw.PemFfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PemFfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + throw new PickyException(new PickyError(result.Err)); } + return new Pem(result.Ok); } } } - /// - /// Loads a PEM from the filesystem. - /// /// /// /// A Pem allocated on Rust side. @@ -91,53 +106,44 @@ public static Pem LoadFromFile(string path) { unsafe { - byte[] pathBuf = DiplomatUtils.StringToUtf8(path); - nuint pathBufLength = (nuint)pathBuf.Length; - fixed (byte* pathBufPtr = pathBuf) + if (path == null) throw new ArgumentNullException(nameof(path)); + byte[] pathBytes = System.Text.Encoding.UTF8.GetBytes(path); + fixed (byte* pathPtr = pathBytes) { - IntPtr resultPtr = Raw.Pem.LoadFromFile(pathBufPtr, pathBufLength); - Raw.PemFfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PemFfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Pem.LoadFromFile(new DiplomatSliceU8 { Ptr = pathPtr, Len = (nuint)pathBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } } - /// - /// Saves this PEM object to the filesystem. - /// /// public void SaveToFile(string path) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pem"); } - byte[] pathBuf = DiplomatUtils.StringToUtf8(path); - nuint pathBufLength = (nuint)pathBuf.Length; - fixed (byte* pathBufPtr = pathBuf) + if (path == null) throw new ArgumentNullException(nameof(path)); + byte[] pathBytes = System.Text.Encoding.UTF8.GetBytes(path); + fixed (byte* pathPtr = pathBytes) { - IntPtr resultPtr = Raw.Pem.SaveToFile(_inner, pathBufPtr, pathBufLength); - Raw.PemFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PemFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Pem.SaveToFile(AsFFI(), new DiplomatSliceU8 { Ptr = pathPtr, Len = (nuint)pathBytes.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } + return; } } } - /// - /// Parses a PEM-encoded string representation. - /// /// /// /// A Pem allocated on Rust side. @@ -146,141 +152,94 @@ public static Pem Parse(string input) { unsafe { - byte[] inputBuf = DiplomatUtils.StringToUtf8(input); - nuint inputBufLength = (nuint)inputBuf.Length; - fixed (byte* inputBufPtr = inputBuf) + if (input == null) throw new ArgumentNullException(nameof(input)); + byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input); + fixed (byte* inputPtr = inputBytes) { - IntPtr resultPtr = Raw.Pem.Parse(inputBufPtr, inputBufLength); - Raw.PemFfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PemFfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Pem.Parse(new DiplomatSliceU8 { Ptr = inputPtr, Len = (nuint)inputBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } } - /// - /// Returns the length of the data contained by this PEM object. - /// public ulong GetDataLength() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pem"); } - ulong retVal = Raw.Pem.GetDataLength(_inner); - return retVal; + var result = Raw.Pem.GetDataLength(AsFFI()); + GC.KeepAlive(this); + return result; } } - /// - /// Returns the label of this PEM object. - /// - /// - public void GetLabel(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("Pem"); - } - IntPtr resultPtr = Raw.Pem.GetLabel(_inner, &writeable); - Raw.PemFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PemFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - /// Returns the label of this PEM object. - /// /// public string GetLabel() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pem"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.Pem.GetLabel(_inner, &writeable); - Raw.PemFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PemFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - /// Returns the string representation of this PEM object. - /// - /// - public void ToRepr(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("Pem"); + var result = Raw.Pem.GetLabel(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - IntPtr resultPtr = Raw.Pem.ToRepr(_inner, &writeable); - Raw.PemFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PemFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } - /// - /// Returns the string representation of this PEM object. - /// /// public string ToRepr() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pem"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.Pem.ToRepr(_inner, &writeable); - Raw.PemFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PemFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.Pem.ToRepr(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Pem* AsFFI() + internal unsafe Raw.Pem* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -290,13 +249,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Pem.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -306,4 +266,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pfx.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pfx.cs index a70128af..1cad6e10 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pfx.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pfx.cs @@ -1,35 +1,61 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// A PKCS12 archive. -/// public partial class Pfx: IDisposable { - private unsafe Raw.Pfx* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Pfx.Destroy; /// /// Creates a managed Pfx from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Pfx(Raw.Pfx* handle) + internal unsafe Pfx(Raw.Pfx* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Pfx(Raw.Pfx* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Pfx(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -39,20 +65,15 @@ public static PfxBuilder Builder(Pkcs12CryptoContext cryptoContext) { unsafe { - Raw.Pkcs12CryptoContext* cryptoContextRaw; - cryptoContextRaw = cryptoContext.AsFFI(); - if (cryptoContextRaw == null) - { - throw new ObjectDisposedException("Pkcs12CryptoContext"); - } - Raw.PfxBuilder* retVal = Raw.Pfx.Builder(cryptoContextRaw); - return new PfxBuilder(retVal); + if (cryptoContext == null) throw new ArgumentNullException(nameof(cryptoContext)); + Raw.Pkcs12CryptoContext* cryptoContextRaw = cryptoContext.AsFFI(); + if (cryptoContextRaw == null) throw new ObjectDisposedException(nameof(Pkcs12CryptoContext)); + Raw.PfxBuilder* result = Raw.Pfx.Builder(cryptoContextRaw); + GC.KeepAlive(cryptoContext); + return new PfxBuilder(result); } } - /// - /// Parses a PKCS12 archive (PFX) from its DER representation. - /// /// /// /// A Pfx allocated on Rust side. @@ -61,30 +82,23 @@ public static Pfx FromDer(byte[] der, Pkcs12CryptoContext cryptoContext, Pkcs12P { unsafe { - nuint derLength = (nuint)der.Length; - Raw.Pkcs12CryptoContext* cryptoContextRaw; - cryptoContextRaw = cryptoContext.AsFFI(); - if (cryptoContextRaw == null) - { - throw new ObjectDisposedException("Pkcs12CryptoContext"); - } - Raw.Pkcs12ParsingParams* parsingParamsRaw; - parsingParamsRaw = parsingParams.AsFFI(); - if (parsingParamsRaw == null) - { - throw new ObjectDisposedException("Pkcs12ParsingParams"); - } + if (der == null) throw new ArgumentNullException(nameof(der)); + if (cryptoContext == null) throw new ArgumentNullException(nameof(cryptoContext)); + Raw.Pkcs12CryptoContext* cryptoContextRaw = cryptoContext.AsFFI(); + if (cryptoContextRaw == null) throw new ObjectDisposedException(nameof(Pkcs12CryptoContext)); + if (parsingParams == null) throw new ArgumentNullException(nameof(parsingParams)); + Raw.Pkcs12ParsingParams* parsingParamsRaw = parsingParams.AsFFI(); + if (parsingParamsRaw == null) throw new ObjectDisposedException(nameof(Pkcs12ParsingParams)); fixed (byte* derPtr = der) { - IntPtr resultPtr = Raw.Pfx.FromDer(derPtr, derLength, cryptoContextRaw, parsingParamsRaw); - Raw.Pkcs12FfiResultBoxPfxBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultBoxPfxBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Pfx.FromDer(new DiplomatSliceU8 { Ptr = derPtr, Len = (nuint)der.Length }, cryptoContextRaw, parsingParamsRaw); + GC.KeepAlive(cryptoContext); + GC.KeepAlive(parsingParams); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pfx* retVal = result.Ok; - return new Pfx(retVal); + return new Pfx(result.Ok); } } } @@ -96,49 +110,40 @@ public static Pfx FromDer(byte[] der, Pkcs12CryptoContext cryptoContext, Pkcs12P { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pfx"); } - Raw.Pkcs12MacAlgorithmHmac* retVal = Raw.Pfx.HmacAlgorithm(_inner); - if (retVal == null) - { - return null; - } - return new Pkcs12MacAlgorithmHmac(retVal); + Raw.Pkcs12MacAlgorithmHmac* result = Raw.Pfx.HmacAlgorithm(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new Pkcs12MacAlgorithmHmac(result); } } - /// - /// Saves this PKCS12 archive to the filesystem. - /// /// public void SaveToFile(string path) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pfx"); } - byte[] pathBuf = DiplomatUtils.StringToUtf8(path); - nuint pathBufLength = (nuint)pathBuf.Length; - fixed (byte* pathBufPtr = pathBuf) + if (path == null) throw new ArgumentNullException(nameof(path)); + byte[] pathBytes = System.Text.Encoding.UTF8.GetBytes(path); + fixed (byte* pathPtr = pathBytes) { - IntPtr resultPtr = Raw.Pfx.SaveToFile(_inner, pathBufPtr, pathBufLength); - Raw.Pkcs12FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Pfx.SaveToFile(AsFFI(), new DiplomatSliceU8 { Ptr = pathPtr, Len = (nuint)pathBytes.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } + return; } } } - /// - /// Returns a `SafeBagIterator` to inspect PFX data - /// /// /// A SafeBagIterator allocated on Rust side. /// @@ -146,44 +151,36 @@ public SafeBagIterator SafeBags() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pfx"); } - Raw.SafeBagIterator* retVal = Raw.Pfx.SafeBags(_inner); - return new SafeBagIterator(retVal); + Raw.SafeBagIterator* result = Raw.Pfx.SafeBags(AsFFI()); + GC.KeepAlive(this); + return new SafeBagIterator(result); } } - /// - /// Crawls all safe contents and safe bags and returns true if one of them is unknown. - /// - /// - /// "Unknown" in this context means that the content is encrypted and most - /// likely the provided password was wrong, or no password at all was provided. - /// It is required to relax parsing strictness by modifying parsing - /// parameters via the `Pkcs12ParsingParams` object in order to allow a - /// `Pfx` object with unknown items. This is useful for partial inspection. - /// public bool HasUnknown() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pfx"); } - bool retVal = Raw.Pfx.HasUnknown(_inner); - return retVal; + var result = Raw.Pfx.HasUnknown(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Pfx* AsFFI() + internal unsafe Raw.Pfx* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -193,13 +190,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Pfx.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -209,4 +207,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PfxBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/PfxBuilder.cs index e8555dbf..fd2f981c 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PfxBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PfxBuilder.cs @@ -1,43 +1,61 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// PFX (PKCS12 archive) builder. -/// public partial class PfxBuilder: IDisposable { - private unsafe Raw.PfxBuilder* _inner; + private unsafe RustHandle _inner; - public Pkcs12MacAlgorithmHmac HmacAlgorithm - { - set - { - SetHmacAlgorithm(value); - } - } + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.PfxBuilder.Destroy; /// /// Creates a managed PfxBuilder from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe PfxBuilder(Raw.PfxBuilder* handle) + internal unsafe PfxBuilder(Raw.PfxBuilder* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe PfxBuilder(Raw.PfxBuilder* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe PfxBuilder(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -47,14 +65,12 @@ public static PfxBuilder Init(Pkcs12CryptoContext cryptoContext) { unsafe { - Raw.Pkcs12CryptoContext* cryptoContextRaw; - cryptoContextRaw = cryptoContext.AsFFI(); - if (cryptoContextRaw == null) - { - throw new ObjectDisposedException("Pkcs12CryptoContext"); - } - Raw.PfxBuilder* retVal = Raw.PfxBuilder.Init(cryptoContextRaw); - return new PfxBuilder(retVal); + if (cryptoContext == null) throw new ArgumentNullException(nameof(cryptoContext)); + Raw.Pkcs12CryptoContext* cryptoContextRaw = cryptoContext.AsFFI(); + if (cryptoContextRaw == null) throw new ObjectDisposedException(nameof(Pkcs12CryptoContext)); + Raw.PfxBuilder* result = Raw.PfxBuilder.Init(cryptoContextRaw); + GC.KeepAlive(cryptoContext); + return new PfxBuilder(result); } } @@ -62,17 +78,16 @@ public void AddSafeBagToCurrentSafeContents(SafeBag safeBag) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PfxBuilder"); } - Raw.SafeBag* safeBagRaw; - safeBagRaw = safeBag.AsFFI(); - if (safeBagRaw == null) - { - throw new ObjectDisposedException("SafeBag"); - } - Raw.PfxBuilder.AddSafeBagToCurrentSafeContents(_inner, safeBagRaw); + if (safeBag == null) throw new ArgumentNullException(nameof(safeBag)); + Raw.SafeBag* safeBagRaw = safeBag.AsFFI(); + if (safeBagRaw == null) throw new ObjectDisposedException(nameof(SafeBag)); + Raw.PfxBuilder.AddSafeBagToCurrentSafeContents(AsFFI(), safeBagRaw); + GC.KeepAlive(this); + GC.KeepAlive(safeBag); } } @@ -80,11 +95,12 @@ public void MarkSafeContentsAsReady() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PfxBuilder"); } - Raw.PfxBuilder.MarkSafeContentsAsReady(_inner); + Raw.PfxBuilder.MarkSafeContentsAsReady(AsFFI()); + GC.KeepAlive(this); } } @@ -93,23 +109,21 @@ public void MarkEncryptedSafeContentsAsReady(Pkcs12Encryption encryption) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PfxBuilder"); } - Raw.Pkcs12Encryption* encryptionRaw; - encryptionRaw = encryption.AsFFI(); - if (encryptionRaw == null) - { - throw new ObjectDisposedException("Pkcs12Encryption"); - } - IntPtr resultPtr = Raw.PfxBuilder.MarkEncryptedSafeContentsAsReady(_inner, encryptionRaw); - Raw.Pkcs12FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (encryption == null) throw new ArgumentNullException(nameof(encryption)); + Raw.Pkcs12Encryption* encryptionRaw = encryption.AsFFI(); + if (encryptionRaw == null) throw new ObjectDisposedException(nameof(Pkcs12Encryption)); + var result = Raw.PfxBuilder.MarkEncryptedSafeContentsAsReady(AsFFI(), encryptionRaw); + GC.KeepAlive(this); + GC.KeepAlive(encryption); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } + return; } } @@ -117,17 +131,16 @@ public void SetHmacAlgorithm(Pkcs12MacAlgorithmHmac macAlgorithm) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PfxBuilder"); } - Raw.Pkcs12MacAlgorithmHmac* macAlgorithmRaw; - macAlgorithmRaw = macAlgorithm.AsFFI(); - if (macAlgorithmRaw == null) - { - throw new ObjectDisposedException("Pkcs12MacAlgorithmHmac"); - } - Raw.PfxBuilder.SetHmacAlgorithm(_inner, macAlgorithmRaw); + if (macAlgorithm == null) throw new ArgumentNullException(nameof(macAlgorithm)); + Raw.Pkcs12MacAlgorithmHmac* macAlgorithmRaw = macAlgorithm.AsFFI(); + if (macAlgorithmRaw == null) throw new ObjectDisposedException(nameof(Pkcs12MacAlgorithmHmac)); + Raw.PfxBuilder.SetHmacAlgorithm(AsFFI(), macAlgorithmRaw); + GC.KeepAlive(this); + GC.KeepAlive(macAlgorithm); } } @@ -139,28 +152,26 @@ public Pfx Build() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PfxBuilder"); } - IntPtr resultPtr = Raw.PfxBuilder.Build(_inner); - Raw.Pkcs12FfiResultBoxPfxBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultBoxPfxBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PfxBuilder.Build(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pfx* retVal = result.Ok; - return new Pfx(retVal); + return new Pfx(result.Ok); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.PfxBuilder* AsFFI() + internal unsafe Raw.PfxBuilder* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -170,13 +181,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.PfxBuilder.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -186,4 +198,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/PickyError.cs index 4a3edc43..f03774fd 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PickyError.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PickyError.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// Stringified Picky error along with an error kind. -/// public partial class PickyError: IDisposable { - private unsafe Raw.PickyError* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.PickyError.Destroy; public PickyErrorKind Kind { @@ -30,90 +32,95 @@ public PickyErrorKind Kind /// Creates a managed PickyError from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe PickyError(Raw.PickyError* handle) + internal unsafe PickyError(Raw.PickyError* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - /// Returns the error as a string. - /// - public void ToDisplay(DiplomatWriteable writeable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe PickyError(Raw.PickyError* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("PickyError"); - } - Raw.PickyError.ToDisplay(_inner, &writeable); - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Returns the error as a string. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe PickyError(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + public string ToDisplay() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PickyError"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - Raw.PickyError.ToDisplay(_inner, &writeable); - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; + DiplomatWrite writeable = new DiplomatWrite(); + try + { + Raw.PickyError.ToDisplay(AsFFI(), &writeable); + GC.KeepAlive(this); + return writeable.ToUnicode(); + } + finally + { + writeable.Dispose(); + } } } - /// - /// Prints the error string. - /// public void Print() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PickyError"); } - Raw.PickyError.Print(_inner); + Raw.PickyError.Print(AsFFI()); + GC.KeepAlive(this); } } - /// - /// Returns the error kind. - /// - /// - /// A PickyErrorKind allocated on C# side. - /// public PickyErrorKind GetKind() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PickyError"); } - Raw.PickyErrorKind retVal = Raw.PickyError.GetKind(_inner); - return (PickyErrorKind)retVal; + var result = Raw.PickyError.GetKind(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.PickyError* AsFFI() + internal unsafe Raw.PickyError* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -123,13 +130,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.PickyError.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -139,4 +147,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PickyErrorKind.cs b/ffi/dotnet/Devolutions.Picky/Generated/PickyErrorKind.cs index 66979882..6cc235b4 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PickyErrorKind.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PickyErrorKind.cs @@ -1,39 +1,10 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// Kind associated to a Picky Error -/// -public enum PickyErrorKind +public enum PickyErrorKind : int { - /// - /// Generic Picky error - /// Generic = 0, - /// - /// Token or certificate not yet valid - /// NotYetValid = 1, - /// - /// Token or certificate expired - /// Expired = 2, - /// - /// Bad signature for token or certificate - /// BadSignature = 3, - /// - /// MAC validation failed (wrong password or corrupted data) - /// Pkcs12MacValidation = 4, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PickyException.cs b/ffi/dotnet/Devolutions.Picky/Generated/PickyException.cs index 94f656e9..874c976e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PickyException.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PickyException.cs @@ -1,30 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; -#nullable enable - -public partial class PickyException : Exception +public class PickyException : Exception { - private PickyError _inner; - - public PickyException(PickyError inner) : base(inner.ToDisplay()) - { - _inner = inner; - } + public PickyError Inner { get; } + private readonly object[] _edges; - public PickyError Inner + public PickyException(PickyError inner, params object[] edges) : base( + inner.ToDisplay() + ) { - get - { - return _inner; - } + Inner = inner; + _edges = edges; } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12Attribute.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12Attribute.cs index 041a0651..895d4141 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12Attribute.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12Attribute.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// Attributes which can be used to store additional information about safe (e.g. friendly name, key ID). -/// public partial class Pkcs12Attribute: IDisposable { - private unsafe Raw.Pkcs12Attribute* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Pkcs12Attribute.Destroy; public string FriendlyName { @@ -38,20 +40,40 @@ public Pkcs12AttributeKind Kind /// Creates a managed Pkcs12Attribute from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Pkcs12Attribute(Raw.Pkcs12Attribute* handle) + internal unsafe Pkcs12Attribute(Raw.Pkcs12Attribute* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Pkcs12Attribute(Raw.Pkcs12Attribute* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Creates a new `friendly name` attribute. This attribute is used to store a human-readable - /// name of the safe bag contents (e.g. certificate name). + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe Pkcs12Attribute(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A Pkcs12Attribute allocated on Rust side. @@ -60,27 +82,20 @@ public static Pkcs12Attribute NewFriendlyName(string name) { unsafe { - byte[] nameBuf = DiplomatUtils.StringToUtf8(name); - nuint nameBufLength = (nuint)nameBuf.Length; - fixed (byte* nameBufPtr = nameBuf) + if (name == null) throw new ArgumentNullException(nameof(name)); + byte[] nameBytes = System.Text.Encoding.UTF8.GetBytes(name); + fixed (byte* namePtr = nameBytes) { - IntPtr resultPtr = Raw.Pkcs12Attribute.NewFriendlyName(nameBufPtr, nameBufLength); - Raw.Pkcs12FfiResultBoxPkcs12AttributeBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultBoxPkcs12AttributeBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Pkcs12Attribute.NewFriendlyName(new DiplomatSliceU8 { Ptr = namePtr, Len = (nuint)nameBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pkcs12Attribute* retVal = result.Ok; - return new Pkcs12Attribute(retVal); + return new Pkcs12Attribute(result.Ok); } } } - /// - /// Creates a new `local key id` attribute. This attribute is used to indicate relation between - /// private key and certificate (when set to same value on both objects). - /// /// /// A Pkcs12Attribute allocated on Rust side. /// @@ -88,79 +103,62 @@ public static Pkcs12Attribute NewLocalKeyId(byte[] value) { unsafe { - nuint valueLength = (nuint)value.Length; + if (value == null) throw new ArgumentNullException(nameof(value)); fixed (byte* valuePtr = value) { - Raw.Pkcs12Attribute* retVal = Raw.Pkcs12Attribute.NewLocalKeyId(valuePtr, valueLength); - return new Pkcs12Attribute(retVal); + Raw.Pkcs12Attribute* result = Raw.Pkcs12Attribute.NewLocalKeyId(new DiplomatSliceU8 { Ptr = valuePtr, Len = (nuint)value.Length }); + return new Pkcs12Attribute(result); } } } - /// - /// A Pkcs12AttributeKind allocated on C# side. - /// public Pkcs12AttributeKind GetKind() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs12Attribute"); } - Raw.Pkcs12AttributeKind retVal = Raw.Pkcs12Attribute.GetKind(_inner); - return (Pkcs12AttributeKind)retVal; + var result = Raw.Pkcs12Attribute.GetKind(AsFFI()); + GC.KeepAlive(this); + return result; } } /// - public void GetFriendlyName(DiplomatWriteable writeable) + public string GetFriendlyName() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs12Attribute"); } - IntPtr resultPtr = Raw.Pkcs12Attribute.GetFriendlyName(_inner, &writeable); - Raw.Pkcs12FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - public string GetFriendlyName() - { - unsafe - { - if (_inner == null) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("Pkcs12Attribute"); + var result = Raw.Pkcs12Attribute.GetFriendlyName(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.Pkcs12Attribute.GetFriendlyName(_inner, &writeable); - Raw.Pkcs12FfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Pkcs12Attribute* AsFFI() + internal unsafe Raw.Pkcs12Attribute* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -170,13 +168,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Pkcs12Attribute.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -186,4 +185,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12AttributeIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12AttributeIterator.cs index d06a4bc2..983a3ae7 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12AttributeIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12AttributeIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class Pkcs12AttributeIterator: IDisposable { - private unsafe Raw.Pkcs12AttributeIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Pkcs12AttributeIterator.Destroy; /// /// Creates a managed Pkcs12AttributeIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Pkcs12AttributeIterator(Raw.Pkcs12AttributeIterator* handle) + internal unsafe Pkcs12AttributeIterator(Raw.Pkcs12AttributeIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Pkcs12AttributeIterator(Raw.Pkcs12AttributeIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Pkcs12AttributeIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe Pkcs12AttributeIterator(Raw.Pkcs12AttributeIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs12AttributeIterator"); } - Raw.Pkcs12Attribute* retVal = Raw.Pkcs12AttributeIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new Pkcs12Attribute(retVal); + Raw.Pkcs12Attribute* result = Raw.Pkcs12AttributeIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new Pkcs12Attribute(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Pkcs12AttributeIterator* AsFFI() + internal unsafe Raw.Pkcs12AttributeIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Pkcs12AttributeIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12AttributeKind.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12AttributeKind.cs index 5d3b7d84..d4352ef8 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12AttributeKind.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12AttributeKind.cs @@ -1,19 +1,8 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum Pkcs12AttributeKind +public enum Pkcs12AttributeKind : int { FriendlyName = 0, LocalKeyId = 1, Custom = 2, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12CryptoContext.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12CryptoContext.cs index fc18075d..ab49a59f 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12CryptoContext.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12CryptoContext.cs @@ -1,37 +1,64 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// Crypto context to use when building a PFX. -/// public partial class Pkcs12CryptoContext: IDisposable { - private unsafe Raw.Pkcs12CryptoContext* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Pkcs12CryptoContext.Destroy; /// /// Creates a managed Pkcs12CryptoContext from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Pkcs12CryptoContext(Raw.Pkcs12CryptoContext* handle) + internal unsafe Pkcs12CryptoContext(Raw.Pkcs12CryptoContext* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Pkcs12CryptoContext(Raw.Pkcs12CryptoContext* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Pkcs12CryptoContext(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + + /// /// /// A Pkcs12CryptoContext allocated on Rust side. /// @@ -39,16 +66,21 @@ public static Pkcs12CryptoContext WithPassword(string password) { unsafe { - byte[] passwordBuf = DiplomatUtils.StringToUtf8(password); - nuint passwordBufLength = (nuint)passwordBuf.Length; - fixed (byte* passwordBufPtr = passwordBuf) + if (password == null) throw new ArgumentNullException(nameof(password)); + byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(password); + fixed (byte* passwordPtr = passwordBytes) { - Raw.Pkcs12CryptoContext* retVal = Raw.Pkcs12CryptoContext.WithPassword(passwordBufPtr, passwordBufLength); - return new Pkcs12CryptoContext(retVal); + var result = Raw.Pkcs12CryptoContext.WithPassword(new DiplomatSliceU8 { Ptr = passwordPtr, Len = (nuint)passwordBytes.Length }); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return new Pkcs12CryptoContext(result.Ok); } } } + /// /// /// A Pkcs12CryptoContext allocated on Rust side. /// @@ -56,17 +88,21 @@ public static Pkcs12CryptoContext NoPassword() { unsafe { - Raw.Pkcs12CryptoContext* retVal = Raw.Pkcs12CryptoContext.NoPassword(); - return new Pkcs12CryptoContext(retVal); + var result = Raw.Pkcs12CryptoContext.NoPassword(); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return new Pkcs12CryptoContext(result.Ok); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Pkcs12CryptoContext* AsFFI() + internal unsafe Raw.Pkcs12CryptoContext* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -76,13 +112,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Pkcs12CryptoContext.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -92,4 +129,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12Encryption.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12Encryption.cs index 306b67e2..08d86145 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12Encryption.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12Encryption.cs @@ -1,35 +1,61 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// Encryption mode to use for the PFX file -/// public partial class Pkcs12Encryption: IDisposable { - private unsafe Raw.Pkcs12Encryption* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Pkcs12Encryption.Destroy; /// /// Creates a managed Pkcs12Encryption from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Pkcs12Encryption(Raw.Pkcs12Encryption* handle) + internal unsafe Pkcs12Encryption(Raw.Pkcs12Encryption* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Pkcs12Encryption(Raw.Pkcs12Encryption* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Pkcs12Encryption(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -39,8 +65,8 @@ public static Pkcs12Encryption Default() { unsafe { - Raw.Pkcs12Encryption* retVal = Raw.Pkcs12Encryption.Default(); - return new Pkcs12Encryption(retVal); + Raw.Pkcs12Encryption* result = Raw.Pkcs12Encryption.Default(); + return new Pkcs12Encryption(result); } } @@ -51,12 +77,8 @@ public static Pkcs12Encryption NewPbes2(Pbes2Cipher cipher, Pkcs12HashAlgorithm { unsafe { - Raw.Pbes2Cipher cipherRaw; - cipherRaw = (Raw.Pbes2Cipher)cipher; - Raw.Pkcs12HashAlgorithm hmacKdfRaw; - hmacKdfRaw = (Raw.Pkcs12HashAlgorithm)hmacKdf; - Raw.Pkcs12Encryption* retVal = Raw.Pkcs12Encryption.NewPbes2(cipherRaw, hmacKdfRaw); - return new Pkcs12Encryption(retVal); + Raw.Pkcs12Encryption* result = Raw.Pkcs12Encryption.NewPbes2(cipher, hmacKdf); + return new Pkcs12Encryption(result); } } @@ -67,19 +89,17 @@ public static Pkcs12Encryption NewPbes1(Pbes1Cipher cipher) { unsafe { - Raw.Pbes1Cipher cipherRaw; - cipherRaw = (Raw.Pbes1Cipher)cipher; - Raw.Pkcs12Encryption* retVal = Raw.Pkcs12Encryption.NewPbes1(cipherRaw); - return new Pkcs12Encryption(retVal); + Raw.Pkcs12Encryption* result = Raw.Pkcs12Encryption.NewPbes1(cipher); + return new Pkcs12Encryption(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Pkcs12Encryption* AsFFI() + internal unsafe Raw.Pkcs12Encryption* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -89,13 +109,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Pkcs12Encryption.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -105,4 +126,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12HashAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12HashAlgorithm.cs index 40689f71..e233ca0a 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12HashAlgorithm.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12HashAlgorithm.cs @@ -1,24 +1,10 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// Hashing algorithm used for MAC or KDF in PFX file -/// -public enum Pkcs12HashAlgorithm +public enum Pkcs12HashAlgorithm : int { Sha1 = 0, Sha224 = 1, Sha256 = 2, Sha384 = 3, Sha512 = 4, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12MacAlgorithmHmac.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12MacAlgorithmHmac.cs index 3392fa7b..84754f30 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12MacAlgorithmHmac.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12MacAlgorithmHmac.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class Pkcs12MacAlgorithmHmac: IDisposable { - private unsafe Raw.Pkcs12MacAlgorithmHmac* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Pkcs12MacAlgorithmHmac.Destroy; /// /// Creates a managed Pkcs12MacAlgorithmHmac from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Pkcs12MacAlgorithmHmac(Raw.Pkcs12MacAlgorithmHmac* handle) + internal unsafe Pkcs12MacAlgorithmHmac(Raw.Pkcs12MacAlgorithmHmac* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Pkcs12MacAlgorithmHmac(Raw.Pkcs12MacAlgorithmHmac* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Pkcs12MacAlgorithmHmac(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,10 +65,8 @@ public static Pkcs12MacAlgorithmHmac NewHmac(Pkcs12HashAlgorithm hashAlgorithm) { unsafe { - Raw.Pkcs12HashAlgorithm hashAlgorithmRaw; - hashAlgorithmRaw = (Raw.Pkcs12HashAlgorithm)hashAlgorithm; - Raw.Pkcs12MacAlgorithmHmac* retVal = Raw.Pkcs12MacAlgorithmHmac.NewHmac(hashAlgorithmRaw); - return new Pkcs12MacAlgorithmHmac(retVal); + Raw.Pkcs12MacAlgorithmHmac* result = Raw.Pkcs12MacAlgorithmHmac.NewHmac(hashAlgorithm); + return new Pkcs12MacAlgorithmHmac(result); } } @@ -50,35 +77,31 @@ public static Pkcs12MacAlgorithmHmac NewHmacWithIterations(Pkcs12HashAlgorithm h { unsafe { - Raw.Pkcs12HashAlgorithm hashAlgorithmRaw; - hashAlgorithmRaw = (Raw.Pkcs12HashAlgorithm)hashAlgorithm; - Raw.Pkcs12MacAlgorithmHmac* retVal = Raw.Pkcs12MacAlgorithmHmac.NewHmacWithIterations(hashAlgorithmRaw, iterations); - return new Pkcs12MacAlgorithmHmac(retVal); + Raw.Pkcs12MacAlgorithmHmac* result = Raw.Pkcs12MacAlgorithmHmac.NewHmacWithIterations(hashAlgorithm, iterations); + return new Pkcs12MacAlgorithmHmac(result); } } - /// - /// A Pkcs12HashAlgorithm allocated on C# side. - /// public Pkcs12HashAlgorithm HashAlgorithm() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs12MacAlgorithmHmac"); } - Raw.Pkcs12HashAlgorithm retVal = Raw.Pkcs12MacAlgorithmHmac.HashAlgorithm(_inner); - return (Pkcs12HashAlgorithm)retVal; + var result = Raw.Pkcs12MacAlgorithmHmac.HashAlgorithm(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Pkcs12MacAlgorithmHmac* AsFFI() + internal unsafe Raw.Pkcs12MacAlgorithmHmac* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -88,13 +111,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Pkcs12MacAlgorithmHmac.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -104,4 +128,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12ParsingParams.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12ParsingParams.cs index f6211db8..9bc7f80b 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12ParsingParams.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs12ParsingParams.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,44 +10,52 @@ namespace Devolutions.Picky; public partial class Pkcs12ParsingParams: IDisposable { - private unsafe Raw.Pkcs12ParsingParams* _inner; + private unsafe RustHandle _inner; - public bool SkipDecryptionErrors - { - set - { - SetSkipDecryptionErrors(value); - } - } - - public bool SkipMacValidation - { - set - { - SetSkipMacValidation(value); - } - } + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; - public bool SkipSoftParsingErrors - { - set - { - SetSkipSoftParsingErrors(value); - } - } + private static readonly unsafe RustDestructor _destroy = Raw.Pkcs12ParsingParams.Destroy; /// /// Creates a managed Pkcs12ParsingParams from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Pkcs12ParsingParams(Raw.Pkcs12ParsingParams* handle) + internal unsafe Pkcs12ParsingParams(Raw.Pkcs12ParsingParams* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Pkcs12ParsingParams(Raw.Pkcs12ParsingParams* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Pkcs12ParsingParams(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -60,68 +65,56 @@ public static Pkcs12ParsingParams New() { unsafe { - Raw.Pkcs12ParsingParams* retVal = Raw.Pkcs12ParsingParams.New(); - return new Pkcs12ParsingParams(retVal); + Raw.Pkcs12ParsingParams* result = Raw.Pkcs12ParsingParams.New(); + return new Pkcs12ParsingParams(result); } } - /// - /// Continue parsing even if conversion to high level picky data structure fails (e.g. due to - /// unsupported private key or certificate kind) - /// public void SetSkipSoftParsingErrors(bool value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs12ParsingParams"); } - Raw.Pkcs12ParsingParams.SetSkipSoftParsingErrors(_inner, value); + Raw.Pkcs12ParsingParams.SetSkipSoftParsingErrors(AsFFI(), value); + GC.KeepAlive(this); } } - /// - /// Continue parsing even if decryption fails and keep data in encrypted form - /// public void SetSkipDecryptionErrors(bool value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs12ParsingParams"); } - Raw.Pkcs12ParsingParams.SetSkipDecryptionErrors(_inner, value); + Raw.Pkcs12ParsingParams.SetSkipDecryptionErrors(AsFFI(), value); + GC.KeepAlive(this); } } - /// - /// Continue parsing even if MAC validation fails. - /// - /// - /// This is useful for parsing available unencrypted data from - /// password-protected PFX files. Also could be useful if PFX integrity has been intentionally - /// violated for testing purposes. - /// public void SetSkipMacValidation(bool value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs12ParsingParams"); } - Raw.Pkcs12ParsingParams.SetSkipMacValidation(_inner, value); + Raw.Pkcs12ParsingParams.SetSkipMacValidation(AsFFI(), value); + GC.KeepAlive(this); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Pkcs12ParsingParams* AsFFI() + internal unsafe Raw.Pkcs12ParsingParams* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -131,13 +124,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Pkcs12ParsingParams.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -147,4 +141,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs7.cs b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs7.cs index ae10486a..69718d8d 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Pkcs7.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Pkcs7.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class Pkcs7: IDisposable { - private unsafe Raw.Pkcs7* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Pkcs7.Destroy; /// /// Creates a managed Pkcs7 from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Pkcs7(Raw.Pkcs7* handle) + internal unsafe Pkcs7(Raw.Pkcs7* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Pkcs7(Raw.Pkcs7* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Pkcs7(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -37,18 +66,15 @@ public static Pkcs7 FromDer(byte[] data) { unsafe { - nuint dataLength = (nuint)data.Length; + if (data == null) throw new ArgumentNullException(nameof(data)); fixed (byte* dataPtr = data) { - IntPtr resultPtr = Raw.Pkcs7.FromDer(dataPtr, dataLength); - Raw.Pkcs7FfiResultBoxPkcs7BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs7FfiResultBoxPkcs7BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Pkcs7.FromDer(new DiplomatSliceU8 { Ptr = dataPtr, Len = (nuint)data.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pkcs7* retVal = result.Ok; - return new Pkcs7(retVal); + return new Pkcs7(result.Ok); } } } @@ -61,21 +87,16 @@ public static Pkcs7 FromPem(Pem pem) { unsafe { - Raw.Pem* pemRaw; - pemRaw = pem.AsFFI(); - if (pemRaw == null) - { - throw new ObjectDisposedException("Pem"); - } - IntPtr resultPtr = Raw.Pkcs7.FromPem(pemRaw); - Raw.Pkcs7FfiResultBoxPkcs7BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs7FfiResultBoxPkcs7BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (pem == null) throw new ArgumentNullException(nameof(pem)); + Raw.Pem* pemRaw = pem.AsFFI(); + if (pemRaw == null) throw new ObjectDisposedException(nameof(Pem)); + var result = Raw.Pkcs7.FromPem(pemRaw); + GC.KeepAlive(pem); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pkcs7* retVal = result.Ok; - return new Pkcs7(retVal); + return new Pkcs7(result.Ok); } } @@ -87,19 +108,17 @@ public VecU8 ToDer() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs7"); } - IntPtr resultPtr = Raw.Pkcs7.ToDer(_inner); - Raw.Pkcs7FfiResultBoxVecU8BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs7FfiResultBoxVecU8BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Pkcs7.ToDer(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.VecU8* retVal = result.Ok; - return new VecU8(retVal); + return new VecU8(result.Ok); } } @@ -111,19 +130,17 @@ public Pem ToPem() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs7"); } - IntPtr resultPtr = Raw.Pkcs7.ToPem(_inner); - Raw.Pkcs7FfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs7FfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.Pkcs7.ToPem(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } @@ -134,12 +151,13 @@ public AlgorithmIdentifierIterator DigestAlgorithms() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs7"); } - Raw.AlgorithmIdentifierIterator* retVal = Raw.Pkcs7.DigestAlgorithms(_inner); - return new AlgorithmIdentifierIterator(retVal); + Raw.AlgorithmIdentifierIterator* result = Raw.Pkcs7.DigestAlgorithms(AsFFI()); + GC.KeepAlive(this); + return new AlgorithmIdentifierIterator(result); } } @@ -150,12 +168,13 @@ public SignerInfoIterator SignerInfos() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs7"); } - Raw.SignerInfoIterator* retVal = Raw.Pkcs7.SignerInfos(_inner); - return new SignerInfoIterator(retVal); + Raw.SignerInfoIterator* result = Raw.Pkcs7.SignerInfos(AsFFI()); + GC.KeepAlive(this); + return new SignerInfoIterator(result); } } @@ -166,12 +185,13 @@ public EncapsulatedContentInfo EncapsulatedContentInfo() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs7"); } - Raw.EncapsulatedContentInfo* retVal = Raw.Pkcs7.EncapsulatedContentInfo(_inner); - return new EncapsulatedContentInfo(retVal); + Raw.EncapsulatedContentInfo* result = Raw.Pkcs7.EncapsulatedContentInfo(AsFFI()); + GC.KeepAlive(this); + return new EncapsulatedContentInfo(result); } } @@ -182,21 +202,22 @@ public CertIterator DecodeCertificates() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pkcs7"); } - Raw.CertIterator* retVal = Raw.Pkcs7.DecodeCertificates(_inner); - return new CertIterator(retVal); + Raw.CertIterator* result = Raw.Pkcs7.DecodeCertificates(AsFFI()); + GC.KeepAlive(this); + return new CertIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Pkcs7* AsFFI() + internal unsafe Raw.Pkcs7* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -206,13 +227,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Pkcs7.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -222,4 +244,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PrivateKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/PrivateKey.cs index 762e67b1..03dc9842 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PrivateKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PrivateKey.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class PrivateKey: IDisposable { - private unsafe Raw.PrivateKey* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.PrivateKey.Destroy; public KeyKind Kind { @@ -27,19 +32,40 @@ public KeyKind Kind /// Creates a managed PrivateKey from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe PrivateKey(Raw.PrivateKey* handle) + internal unsafe PrivateKey(Raw.PrivateKey* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe PrivateKey(Raw.PrivateKey* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Extracts private key from PEM object. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe PrivateKey(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A PrivateKey allocated on Rust side. @@ -48,27 +74,19 @@ public static PrivateKey FromPem(Pem pem) { unsafe { - Raw.Pem* pemRaw; - pemRaw = pem.AsFFI(); - if (pemRaw == null) - { - throw new ObjectDisposedException("Pem"); - } - IntPtr resultPtr = Raw.PrivateKey.FromPem(pemRaw); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (pem == null) throw new ArgumentNullException(nameof(pem)); + Raw.Pem* pemRaw = pem.AsFFI(); + if (pemRaw == null) throw new ObjectDisposedException(nameof(Pem)); + var result = Raw.PrivateKey.FromPem(pemRaw); + GC.KeepAlive(pem); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PrivateKey* retVal = result.Ok; - return new PrivateKey(retVal); + return new PrivateKey(result.Ok); } } - /// - /// Reads a private key from its PKCS8 storage. - /// /// /// /// A PrivateKey allocated on Rust side. @@ -77,18 +95,15 @@ public static PrivateKey FromPkcs8(byte[] pkcs8) { unsafe { - nuint pkcs8Length = (nuint)pkcs8.Length; + if (pkcs8 == null) throw new ArgumentNullException(nameof(pkcs8)); fixed (byte* pkcs8Ptr = pkcs8) { - IntPtr resultPtr = Raw.PrivateKey.FromPkcs8(pkcs8Ptr, pkcs8Length); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PrivateKey.FromPkcs8(new DiplomatSliceU8 { Ptr = pkcs8Ptr, Len = (nuint)pkcs8.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PrivateKey* retVal = result.Ok; - return new PrivateKey(retVal); + return new PrivateKey(result.Ok); } } } @@ -101,29 +116,20 @@ public static PrivateKey FromPemStr(string pem) { unsafe { - byte[] pemBuf = DiplomatUtils.StringToUtf8(pem); - nuint pemBufLength = (nuint)pemBuf.Length; - fixed (byte* pemBufPtr = pemBuf) + if (pem == null) throw new ArgumentNullException(nameof(pem)); + byte[] pemBytes = System.Text.Encoding.UTF8.GetBytes(pem); + fixed (byte* pemPtr = pemBytes) { - IntPtr resultPtr = Raw.PrivateKey.FromPemStr(pemBufPtr, pemBufLength); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PrivateKey.FromPemStr(new DiplomatSliceU8 { Ptr = pemPtr, Len = (nuint)pemBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PrivateKey* retVal = result.Ok; - return new PrivateKey(retVal); + return new PrivateKey(result.Ok); } } } - /// - /// Generates a new RSA private key. - /// - /// - /// This is slow in debug builds. - /// /// /// /// A PrivateKey allocated on Rust side. @@ -132,21 +138,15 @@ public static PrivateKey GenerateRsa(nuint bits) { unsafe { - IntPtr resultPtr = Raw.PrivateKey.GenerateRsa(bits); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PrivateKey.GenerateRsa(bits); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PrivateKey* retVal = result.Ok; - return new PrivateKey(retVal); + return new PrivateKey(result.Ok); } } - /// - /// Generates a new EC private key. - /// /// /// /// A PrivateKey allocated on Rust side. @@ -155,27 +155,15 @@ public static PrivateKey GenerateEc(EcCurve curve) { unsafe { - Raw.EcCurve curveRaw; - curveRaw = (Raw.EcCurve)curve; - IntPtr resultPtr = Raw.PrivateKey.GenerateEc(curveRaw); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PrivateKey.GenerateEc(curve); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PrivateKey* retVal = result.Ok; - return new PrivateKey(retVal); + return new PrivateKey(result.Ok); } } - /// - /// Generates new ed key pair with specified supported algorithm. - /// - /// - /// `write_public_key` specifies whether to include public key in the private key file. - /// Note that OpenSSL does not support ed keys with public key included. - /// /// /// /// A PrivateKey allocated on Rust side. @@ -184,23 +172,15 @@ public static PrivateKey GenerateEd(EdAlgorithm algorithm, bool writePublicKey) { unsafe { - Raw.EdAlgorithm algorithmRaw; - algorithmRaw = (Raw.EdAlgorithm)algorithm; - IntPtr resultPtr = Raw.PrivateKey.GenerateEd(algorithmRaw, writePublicKey); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PrivateKey.GenerateEd(algorithm, writePublicKey); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PrivateKey* retVal = result.Ok; - return new PrivateKey(retVal); + return new PrivateKey(result.Ok); } } - /// - /// Exports the private key into a PEM object - /// /// /// /// A Pem allocated on Rust side. @@ -209,28 +189,20 @@ public Pem ToPem() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PrivateKey"); } - IntPtr resultPtr = Raw.PrivateKey.ToPem(_inner); - Raw.KeyFfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PrivateKey.ToPem(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } - /// - /// Exports the private key into a PEM object using the PKCS 1 format - /// - /// - /// This format can only be used for RSA keys. - /// /// /// /// A Pem allocated on Rust side. @@ -239,25 +211,20 @@ public Pem ToPkcs1Pem() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PrivateKey"); } - IntPtr resultPtr = Raw.PrivateKey.ToPkcs1Pem(_inner); - Raw.KeyFfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PrivateKey.ToPkcs1Pem(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } - /// - /// Extracts the public part of this private key - /// /// /// /// A PublicKey allocated on Rust side. @@ -266,47 +233,40 @@ public PublicKey ToPublicKey() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PrivateKey"); } - IntPtr resultPtr = Raw.PrivateKey.ToPublicKey(_inner); - Raw.KeyFfiResultBoxPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PrivateKey.ToPublicKey(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PublicKey* retVal = result.Ok; - return new PublicKey(retVal); + return new PublicKey(result.Ok); } } - /// - /// Retrieves the key kind for this private key. - /// - /// - /// A KeyKind allocated on C# side. - /// public KeyKind GetKind() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PrivateKey"); } - Raw.KeyKind retVal = Raw.PrivateKey.GetKind(_inner); - return (KeyKind)retVal; + var result = Raw.PrivateKey.GetKind(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.PrivateKey* AsFFI() + internal unsafe Raw.PrivateKey* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -316,13 +276,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.PrivateKey.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -332,4 +293,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PublicKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/PublicKey.cs index 634f88d7..6fa4ff22 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PublicKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PublicKey.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class PublicKey: IDisposable { - private unsafe Raw.PublicKey* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.PublicKey.Destroy; public KeyKind Kind { @@ -27,19 +32,40 @@ public KeyKind Kind /// Creates a managed PublicKey from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe PublicKey(Raw.PublicKey* handle) + internal unsafe PublicKey(Raw.PublicKey* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe PublicKey(Raw.PublicKey* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Extracts public key from PEM object. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe PublicKey(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A PublicKey allocated on Rust side. @@ -48,27 +74,19 @@ public static PublicKey FromPem(Pem pem) { unsafe { - Raw.Pem* pemRaw; - pemRaw = pem.AsFFI(); - if (pemRaw == null) - { - throw new ObjectDisposedException("Pem"); - } - IntPtr resultPtr = Raw.PublicKey.FromPem(pemRaw); - Raw.KeyFfiResultBoxPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (pem == null) throw new ArgumentNullException(nameof(pem)); + Raw.Pem* pemRaw = pem.AsFFI(); + if (pemRaw == null) throw new ObjectDisposedException(nameof(Pem)); + var result = Raw.PublicKey.FromPem(pemRaw); + GC.KeepAlive(pem); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PublicKey* retVal = result.Ok; - return new PublicKey(retVal); + return new PublicKey(result.Ok); } } - /// - /// Reads a public key from its DER encoding (i.e.: SubjectPublicKeyInfo structure). - /// /// /// /// A PublicKey allocated on Rust side. @@ -77,25 +95,19 @@ public static PublicKey FromDer(byte[] der) { unsafe { - nuint derLength = (nuint)der.Length; + if (der == null) throw new ArgumentNullException(nameof(der)); fixed (byte* derPtr = der) { - IntPtr resultPtr = Raw.PublicKey.FromDer(derPtr, derLength); - Raw.KeyFfiResultBoxPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PublicKey.FromDer(new DiplomatSliceU8 { Ptr = derPtr, Len = (nuint)der.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PublicKey* retVal = result.Ok; - return new PublicKey(retVal); + return new PublicKey(result.Ok); } } } - /// - /// Reads a RSA public key from its DER encoding (i.e.: PKCS1). - /// /// /// /// A PublicKey allocated on Rust side. @@ -104,25 +116,19 @@ public static PublicKey FromPkcs1(byte[] der) { unsafe { - nuint derLength = (nuint)der.Length; + if (der == null) throw new ArgumentNullException(nameof(der)); fixed (byte* derPtr = der) { - IntPtr resultPtr = Raw.PublicKey.FromPkcs1(derPtr, derLength); - Raw.KeyFfiResultBoxPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PublicKey.FromPkcs1(new DiplomatSliceU8 { Ptr = derPtr, Len = (nuint)der.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PublicKey* retVal = result.Ok; - return new PublicKey(retVal); + return new PublicKey(result.Ok); } } } - /// - /// Exports the public key into a PEM object. - /// /// /// /// A Pem allocated on Rust side. @@ -131,28 +137,20 @@ public Pem ToPem() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PublicKey"); } - IntPtr resultPtr = Raw.PublicKey.ToPem(_inner); - Raw.KeyFfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PublicKey.ToPem(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } - /// - /// Exports the public key into a PEM object using the PKCS 1 format - /// - /// - /// This format can only be used for RSA keys. - /// /// /// /// A Pem allocated on Rust side. @@ -161,47 +159,40 @@ public Pem ToPkcs1Pem() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PublicKey"); } - IntPtr resultPtr = Raw.PublicKey.ToPkcs1Pem(_inner); - Raw.KeyFfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.KeyFfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PublicKey.ToPkcs1Pem(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } - /// - /// Retrieves the key kind for this public key. - /// - /// - /// A KeyKind allocated on C# side. - /// public KeyKind GetKind() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PublicKey"); } - Raw.KeyKind retVal = Raw.PublicKey.GetKind(_inner); - return (KeyKind)retVal; + var result = Raw.PublicKey.GetKind(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.PublicKey* AsFFI() + internal unsafe Raw.PublicKey* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -211,13 +202,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.PublicKey.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -227,4 +219,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PuttyArgon2Flavour.cs b/ffi/dotnet/Devolutions.Picky/Generated/PuttyArgon2Flavour.cs index ebeee69c..fa716d47 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PuttyArgon2Flavour.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PuttyArgon2Flavour.cs @@ -1,22 +1,8 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// Argon2 key derivation function flavour. -/// -public enum PuttyArgon2Flavour +public enum PuttyArgon2Flavour : int { Argon2d = 0, Argon2i = 1, Argon2id = 2, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PuttyArgon2Params.cs b/ffi/dotnet/Devolutions.Picky/Generated/PuttyArgon2Params.cs index 3090631b..84f6800a 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PuttyArgon2Params.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PuttyArgon2Params.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// Argon2 key derivation function parameters. -/// public partial class PuttyArgon2Params: IDisposable { - private unsafe Raw.PuttyArgon2Params* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.PuttyArgon2Params.Destroy; public PuttyArgon2Flavour Flavor { @@ -62,29 +64,51 @@ public VecU8 Salt /// Creates a managed PuttyArgon2Params from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe PuttyArgon2Params(Raw.PuttyArgon2Params* handle) + internal unsafe PuttyArgon2Params(Raw.PuttyArgon2Params* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe PuttyArgon2Params(Raw.PuttyArgon2Params* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe PuttyArgon2Params(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A PuttyArgon2Flavour allocated on C# side. - /// public PuttyArgon2Flavour GetFlavor() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyArgon2Params"); } - Raw.PuttyArgon2Flavour retVal = Raw.PuttyArgon2Params.GetFlavor(_inner); - return (PuttyArgon2Flavour)retVal; + var result = Raw.PuttyArgon2Params.GetFlavor(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -92,12 +116,13 @@ public uint GetMemory() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyArgon2Params"); } - uint retVal = Raw.PuttyArgon2Params.GetMemory(_inner); - return retVal; + var result = Raw.PuttyArgon2Params.GetMemory(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -105,12 +130,13 @@ public uint GetPasses() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyArgon2Params"); } - uint retVal = Raw.PuttyArgon2Params.GetPasses(_inner); - return retVal; + var result = Raw.PuttyArgon2Params.GetPasses(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -118,12 +144,13 @@ public uint GetParallelism() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyArgon2Params"); } - uint retVal = Raw.PuttyArgon2Params.GetParallelism(_inner); - return retVal; + var result = Raw.PuttyArgon2Params.GetParallelism(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -134,21 +161,22 @@ public VecU8 GetSalt() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyArgon2Params"); } - Raw.VecU8* retVal = Raw.PuttyArgon2Params.GetSalt(_inner); - return new VecU8(retVal); + Raw.VecU8* result = Raw.PuttyArgon2Params.GetSalt(AsFFI()); + GC.KeepAlive(this); + return new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.PuttyArgon2Params* AsFFI() + internal unsafe Raw.PuttyArgon2Params* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -158,13 +186,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.PuttyArgon2Params.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -174,4 +203,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpk.cs b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpk.cs index 59c6c6f6..284d6bb2 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpk.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpk.cs @@ -1,36 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// PuTTY Private Key (PPK) format. -/// -/// -/// ### Functionality -/// - Generation of new keys. -/// - Conversion to/from OpenSSH format. -/// - Encoding/decoding to/from string. -/// - Version upgrade/downgrade. -///
-/// ### Usage notes -/// - Ppk structure is immutable. All operations that modify the key return a new instance. -/// - When input file is encrypted, all operations with the private key will be unavailable until -/// ppk is decrypted via `PuttyPpk::decrypt`. -/// - Newly generated keys are always unencrypted. They should be encrypted via `PuttyPpk::encrypt` -/// when required -///
public partial class PuttyPpk: IDisposable { - private unsafe Raw.PuttyPpk* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.PuttyPpk.Destroy; public PuttyPpkKeyAlgorithm Algorithm { @@ -76,19 +64,40 @@ public PuttyPpkVersion Version /// Creates a managed PuttyPpk from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe PuttyPpk(Raw.PuttyPpk* handle) + internal unsafe PuttyPpk(Raw.PuttyPpk* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe PuttyPpk(Raw.PuttyPpk* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Generate a new RSA key file. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe PuttyPpk(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A PuttyPpk allocated on Rust side. @@ -97,26 +106,20 @@ public static PuttyPpk GenerateRsa(nuint bits, string comment) { unsafe { - byte[] commentBuf = DiplomatUtils.StringToUtf8(comment); - nuint commentBufLength = (nuint)commentBuf.Length; - fixed (byte* commentBufPtr = commentBuf) - { - IntPtr resultPtr = Raw.PuttyPpk.GenerateRsa(bits, commentBufPtr, commentBufLength); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (comment == null) throw new ArgumentNullException(nameof(comment)); + byte[] commentBytes = System.Text.Encoding.UTF8.GetBytes(comment); + fixed (byte* commentPtr = commentBytes) + { + var result = Raw.PuttyPpk.GenerateRsa(bits, new DiplomatSliceU8 { Ptr = commentPtr, Len = (nuint)commentBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } } - /// - /// Generate a new EC key file. - /// /// /// /// A PuttyPpk allocated on Rust side. @@ -125,28 +128,20 @@ public static PuttyPpk GenerateEc(EcCurve curve, string comment) { unsafe { - byte[] commentBuf = DiplomatUtils.StringToUtf8(comment); - nuint commentBufLength = (nuint)commentBuf.Length; - Raw.EcCurve curveRaw; - curveRaw = (Raw.EcCurve)curve; - fixed (byte* commentBufPtr = commentBuf) - { - IntPtr resultPtr = Raw.PuttyPpk.GenerateEc(curveRaw, commentBufPtr, commentBufLength); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (comment == null) throw new ArgumentNullException(nameof(comment)); + byte[] commentBytes = System.Text.Encoding.UTF8.GetBytes(comment); + fixed (byte* commentPtr = commentBytes) + { + var result = Raw.PuttyPpk.GenerateEc(curve, new DiplomatSliceU8 { Ptr = commentPtr, Len = (nuint)commentBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } } - /// - /// Generate a new Ed25519 key file. - /// /// /// /// A PuttyPpk allocated on Rust side. @@ -155,74 +150,47 @@ public static PuttyPpk GenerateEd25519(string comment) { unsafe { - byte[] commentBuf = DiplomatUtils.StringToUtf8(comment); - nuint commentBufLength = (nuint)commentBuf.Length; - fixed (byte* commentBufPtr = commentBuf) - { - IntPtr resultPtr = Raw.PuttyPpk.GenerateEd25519(commentBufPtr, commentBufLength); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (comment == null) throw new ArgumentNullException(nameof(comment)); + byte[] commentBytes = System.Text.Encoding.UTF8.GetBytes(comment); + fixed (byte* commentPtr = commentBytes) + { + var result = Raw.PuttyPpk.GenerateEd25519(new DiplomatSliceU8 { Ptr = commentPtr, Len = (nuint)commentBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } } - /// - /// Encode PPK key file to a string. - /// /// - public void ToRepr(DiplomatWriteable writeable) + public string ToRepr() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - IntPtr resultPtr = Raw.PuttyPpk.ToRepr(_inner, &writeable); - Raw.PuttyFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - /// Encode PPK key file to a string. - /// - /// - public string ToRepr() - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("PuttyPpk"); + var result = Raw.PuttyPpk.ToRepr(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.PuttyPpk.ToRepr(_inner, &writeable); - Raw.PuttyFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } - /// - /// Parse a PPK key file from a string. - /// /// /// /// A PuttyPpk allocated on Rust side. @@ -231,26 +199,20 @@ public static PuttyPpk Parse(string ppk) { unsafe { - byte[] ppkBuf = DiplomatUtils.StringToUtf8(ppk); - nuint ppkBufLength = (nuint)ppkBuf.Length; - fixed (byte* ppkBufPtr = ppkBuf) - { - IntPtr resultPtr = Raw.PuttyPpk.Parse(ppkBufPtr, ppkBufLength); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (ppk == null) throw new ArgumentNullException(nameof(ppk)); + byte[] ppkBytes = System.Text.Encoding.UTF8.GetBytes(ppk); + fixed (byte* ppkPtr = ppkBytes) + { + var result = Raw.PuttyPpk.Parse(new DiplomatSliceU8 { Ptr = ppkPtr, Len = (nuint)ppkBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } } - /// - /// Convert an OpenSSH private key to a PPK key file. - /// /// /// /// A PuttyPpk allocated on Rust side. @@ -259,27 +221,19 @@ public static PuttyPpk FromOpenssh(SshPrivateKey key) { unsafe { - Raw.SshPrivateKey* keyRaw; - keyRaw = key.AsFFI(); - if (keyRaw == null) - { - throw new ObjectDisposedException("SshPrivateKey"); - } - IntPtr resultPtr = Raw.PuttyPpk.FromOpenssh(keyRaw); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (key == null) throw new ArgumentNullException(nameof(key)); + Raw.SshPrivateKey* keyRaw = key.AsFFI(); + if (keyRaw == null) throw new ObjectDisposedException(nameof(SshPrivateKey)); + var result = Raw.PuttyPpk.FromOpenssh(keyRaw); + GC.KeepAlive(key); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } - /// - /// Convert a PPK key file to an OpenSSH private key. - /// /// /// /// A SshPrivateKey allocated on Rust side. @@ -288,30 +242,25 @@ public SshPrivateKey ToOpenssh(string passphrase) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - byte[] passphraseBuf = DiplomatUtils.StringToUtf8(passphrase); - nuint passphraseBufLength = (nuint)passphraseBuf.Length; - fixed (byte* passphraseBufPtr = passphraseBuf) + if (passphrase == null) throw new ArgumentNullException(nameof(passphrase)); + byte[] passphraseBytes = System.Text.Encoding.UTF8.GetBytes(passphrase); + fixed (byte* passphrasePtr = passphraseBytes) { - IntPtr resultPtr = Raw.PuttyPpk.ToOpenssh(_inner, passphraseBufPtr, passphraseBufLength); - Raw.PuttyFfiResultBoxSshPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxSshPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PuttyPpk.ToOpenssh(AsFFI(), new DiplomatSliceU8 { Ptr = passphrasePtr, Len = (nuint)passphraseBytes.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SshPrivateKey* retVal = result.Ok; - return new SshPrivateKey(retVal); + return new SshPrivateKey(result.Ok); } } } - /// - /// Wrap a private key - /// /// /// /// A PuttyPpk allocated on Rust side. @@ -320,27 +269,19 @@ public static PuttyPpk FromKey(PrivateKey privateKey) { unsafe { - Raw.PrivateKey* privateKeyRaw; - privateKeyRaw = privateKey.AsFFI(); - if (privateKeyRaw == null) - { - throw new ObjectDisposedException("PrivateKey"); - } - IntPtr resultPtr = Raw.PuttyPpk.FromKey(privateKeyRaw); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (privateKey == null) throw new ArgumentNullException(nameof(privateKey)); + Raw.PrivateKey* privateKeyRaw = privateKey.AsFFI(); + if (privateKeyRaw == null) throw new ObjectDisposedException(nameof(PrivateKey)); + var result = Raw.PuttyPpk.FromKey(privateKeyRaw); + GC.KeepAlive(privateKey); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } - /// - /// Get the public key from the PPK key file. - /// /// /// /// A PublicKey allocated on Rust side. @@ -349,25 +290,20 @@ public PublicKey GetPublicKey() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - IntPtr resultPtr = Raw.PuttyPpk.GetPublicKey(_inner); - Raw.PuttyFfiResultBoxPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PuttyPpk.GetPublicKey(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PublicKey* retVal = result.Ok; - return new PublicKey(retVal); + return new PublicKey(result.Ok); } } - /// - /// Get the private key from the PPK key file. - /// /// /// /// A PrivateKey allocated on Rust side. @@ -376,25 +312,20 @@ public PrivateKey GetPrivateKey() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - IntPtr resultPtr = Raw.PuttyPpk.GetPrivateKey(_inner); - Raw.PuttyFfiResultBoxPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PuttyPpk.GetPrivateKey(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PrivateKey* retVal = result.Ok; - return new PrivateKey(retVal); + return new PrivateKey(result.Ok); } } - /// - /// Extract the public key file (PuTTY format) from the PPK key file. - /// /// /// /// A PuttyPublicKey allocated on Rust side. @@ -403,111 +334,75 @@ public PuttyPublicKey ExtractPuttyPublicKey() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - IntPtr resultPtr = Raw.PuttyPpk.ExtractPuttyPublicKey(_inner); - Raw.PuttyFfiResultBoxPuttyPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PuttyPpk.ExtractPuttyPublicKey(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPublicKey* retVal = result.Ok; - return new PuttyPublicKey(retVal); + return new PuttyPublicKey(result.Ok); } } - /// - /// Get the PPK key file version. - /// - /// - /// A PuttyPpkVersion allocated on C# side. - /// public PuttyPpkVersion GetVersion() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - Raw.PuttyPpkVersion retVal = Raw.PuttyPpk.GetVersion(_inner); - return (PuttyPpkVersion)retVal; + var result = Raw.PuttyPpk.GetVersion(AsFFI()); + GC.KeepAlive(this); + return result; } } - /// - /// Get the PPK key file algorithm. - /// - /// - /// A PuttyPpkKeyAlgorithm allocated on C# side. - /// public PuttyPpkKeyAlgorithm GetAlgorithm() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - Raw.PuttyPpkKeyAlgorithm retVal = Raw.PuttyPpk.GetAlgorithm(_inner); - return (PuttyPpkKeyAlgorithm)retVal; + var result = Raw.PuttyPpk.GetAlgorithm(AsFFI()); + GC.KeepAlive(this); + return result; } } - /// - /// Get the PPK key file comment. - /// /// - public void GetComment(DiplomatWriteable writeable) + public string GetComment() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - IntPtr resultPtr = Raw.PuttyPpk.GetComment(_inner, &writeable); - Raw.PuttyFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - /// Get the PPK key file comment. - /// - /// - public string GetComment() - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("PuttyPpk"); + var result = Raw.PuttyPpk.GetComment(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.PuttyPpk.GetComment(_inner, &writeable); - Raw.PuttyFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } - /// - /// Returns a new PPK key instance with a different comment. - /// /// /// /// A PuttyPpk allocated on Rust side. @@ -516,30 +411,25 @@ public PuttyPpk WithComment(string comment) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - byte[] commentBuf = DiplomatUtils.StringToUtf8(comment); - nuint commentBufLength = (nuint)commentBuf.Length; - fixed (byte* commentBufPtr = commentBuf) + if (comment == null) throw new ArgumentNullException(nameof(comment)); + byte[] commentBytes = System.Text.Encoding.UTF8.GetBytes(comment); + fixed (byte* commentPtr = commentBytes) { - IntPtr resultPtr = Raw.PuttyPpk.WithComment(_inner, commentBufPtr, commentBufLength); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PuttyPpk.WithComment(AsFFI(), new DiplomatSliceU8 { Ptr = commentPtr, Len = (nuint)commentBytes.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } } - /// - /// Convert the PPK key file to a different version. - /// /// /// /// A PuttyPpk allocated on Rust side. @@ -548,43 +438,34 @@ public PuttyPpk ToVersion(PuttyPpkVersion version) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - Raw.PuttyPpkVersion versionRaw; - versionRaw = (Raw.PuttyPpkVersion)version; - IntPtr resultPtr = Raw.PuttyPpk.ToVersion(_inner, versionRaw); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PuttyPpk.ToVersion(AsFFI(), version); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } - /// - /// Check if the PPK key file is encrypted. - /// public bool IsEncrypted() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - bool retVal = Raw.PuttyPpk.IsEncrypted(_inner); - return retVal; + var result = Raw.PuttyPpk.IsEncrypted(AsFFI()); + GC.KeepAlive(this); + return result; } } - /// - /// Get the Argon2 key derivation function parameters (if the key is encrypted). - /// /// /// A PuttyArgon2Params allocated on Rust side. /// @@ -592,22 +473,16 @@ public bool IsEncrypted() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - Raw.PuttyArgon2Params* retVal = Raw.PuttyPpk.Argon2Params(_inner); - if (retVal == null) - { - return null; - } - return new PuttyArgon2Params(retVal); + Raw.PuttyArgon2Params* result = Raw.PuttyPpk.Argon2Params(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new PuttyArgon2Params(result); } } - /// - /// Decrypt the PPK key file and return as a new instance. - /// /// /// /// A PuttyPpk allocated on Rust side. @@ -616,30 +491,25 @@ public PuttyPpk Decrypt(string passphrase) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - byte[] passphraseBuf = DiplomatUtils.StringToUtf8(passphrase); - nuint passphraseBufLength = (nuint)passphraseBuf.Length; - fixed (byte* passphraseBufPtr = passphraseBuf) + if (passphrase == null) throw new ArgumentNullException(nameof(passphrase)); + byte[] passphraseBytes = System.Text.Encoding.UTF8.GetBytes(passphrase); + fixed (byte* passphrasePtr = passphraseBytes) { - IntPtr resultPtr = Raw.PuttyPpk.Decrypt(_inner, passphraseBufPtr, passphraseBufLength); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PuttyPpk.Decrypt(AsFFI(), new DiplomatSliceU8 { Ptr = passphrasePtr, Len = (nuint)passphraseBytes.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } } - /// - /// Encrypt the PPK key file and return as a new instance. - /// /// /// /// A PuttyPpk allocated on Rust side. @@ -648,29 +518,25 @@ public PuttyPpk Encrypt(string passphrase, PuttyPpkEncryptionConfig config) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpk"); } - byte[] passphraseBuf = DiplomatUtils.StringToUtf8(passphrase); - nuint passphraseBufLength = (nuint)passphraseBuf.Length; - Raw.PuttyPpkEncryptionConfig* configRaw; - configRaw = config.AsFFI(); - if (configRaw == null) - { - throw new ObjectDisposedException("PuttyPpkEncryptionConfig"); - } - fixed (byte* passphraseBufPtr = passphraseBuf) - { - IntPtr resultPtr = Raw.PuttyPpk.Encrypt(_inner, passphraseBufPtr, passphraseBufLength, configRaw); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPpkBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (passphrase == null) throw new ArgumentNullException(nameof(passphrase)); + if (config == null) throw new ArgumentNullException(nameof(config)); + Raw.PuttyPpkEncryptionConfig* configRaw = config.AsFFI(); + if (configRaw == null) throw new ObjectDisposedException(nameof(PuttyPpkEncryptionConfig)); + byte[] passphraseBytes = System.Text.Encoding.UTF8.GetBytes(passphrase); + fixed (byte* passphrasePtr = passphraseBytes) + { + var result = Raw.PuttyPpk.Encrypt(AsFFI(), new DiplomatSliceU8 { Ptr = passphrasePtr, Len = (nuint)passphraseBytes.Length }, configRaw); + GC.KeepAlive(this); + GC.KeepAlive(config); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPpk* retVal = result.Ok; - return new PuttyPpk(retVal); + return new PuttyPpk(result.Ok); } } } @@ -678,9 +544,9 @@ public PuttyPpk Encrypt(string passphrase, PuttyPpkEncryptionConfig config) /// /// Returns the underlying raw handle. /// - public unsafe Raw.PuttyPpk* AsFFI() + internal unsafe Raw.PuttyPpk* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -690,13 +556,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.PuttyPpk.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -706,4 +573,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkEncryptionConfig.cs b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkEncryptionConfig.cs index 8a7016bb..69e65923 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkEncryptionConfig.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkEncryptionConfig.cs @@ -1,40 +1,61 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// PPK encryption configuration. -/// -/// -/// Could be either constructed via `PuttyPpkEncryptionConfig::default()` or `PuttyPpkEncryptionConfig::builder()` -///
-/// Defaults are the same as in PuTTY. -///
public partial class PuttyPpkEncryptionConfig: IDisposable { - private unsafe Raw.PuttyPpkEncryptionConfig* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.PuttyPpkEncryptionConfig.Destroy; /// /// Creates a managed PuttyPpkEncryptionConfig from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe PuttyPpkEncryptionConfig(Raw.PuttyPpkEncryptionConfig* handle) + internal unsafe PuttyPpkEncryptionConfig(Raw.PuttyPpkEncryptionConfig* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe PuttyPpkEncryptionConfig(Raw.PuttyPpkEncryptionConfig* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe PuttyPpkEncryptionConfig(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -44,8 +65,8 @@ public static PuttyPpkEncryptionConfig Default() { unsafe { - Raw.PuttyPpkEncryptionConfig* retVal = Raw.PuttyPpkEncryptionConfig.Default(); - return new PuttyPpkEncryptionConfig(retVal); + Raw.PuttyPpkEncryptionConfig* result = Raw.PuttyPpkEncryptionConfig.Default(); + return new PuttyPpkEncryptionConfig(result); } } @@ -56,17 +77,17 @@ public static PuttyPpkEncryptionConfigBuilder Builder() { unsafe { - Raw.PuttyPpkEncryptionConfigBuilder* retVal = Raw.PuttyPpkEncryptionConfig.Builder(); - return new PuttyPpkEncryptionConfigBuilder(retVal); + Raw.PuttyPpkEncryptionConfigBuilder* result = Raw.PuttyPpkEncryptionConfig.Builder(); + return new PuttyPpkEncryptionConfigBuilder(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.PuttyPpkEncryptionConfig* AsFFI() + internal unsafe Raw.PuttyPpkEncryptionConfig* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -76,13 +97,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.PuttyPpkEncryptionConfig.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -92,4 +114,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkEncryptionConfigBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkEncryptionConfigBuilder.cs index b5e547fe..914ba529 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkEncryptionConfigBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkEncryptionConfigBuilder.cs @@ -1,83 +1,73 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// PPK encryption configuration builder. -/// -/// -/// Could be constructed via `PuttyPpkEncryptionConfig::builder()`. -/// public partial class PuttyPpkEncryptionConfigBuilder: IDisposable { - private unsafe Raw.PuttyPpkEncryptionConfigBuilder* _inner; - - public uint Argon2Memory - { - set - { - SetArgon2Memory(value); - } - } - - public uint Argon2Parallelism - { - set - { - SetArgon2Parallelism(value); - } - } + private unsafe RustHandle _inner; - public uint Argon2Passes - { - set - { - SetArgon2Passes(value); - } - } + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; - public uint Argon2SaltSize - { - set - { - SetArgon2SaltSize(value); - } - } + private static readonly unsafe RustDestructor _destroy = Raw.PuttyPpkEncryptionConfigBuilder.Destroy; /// /// Creates a managed PuttyPpkEncryptionConfigBuilder from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe PuttyPpkEncryptionConfigBuilder(Raw.PuttyPpkEncryptionConfigBuilder* handle) + internal unsafe PuttyPpkEncryptionConfigBuilder(Raw.PuttyPpkEncryptionConfigBuilder* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe PuttyPpkEncryptionConfigBuilder(Raw.PuttyPpkEncryptionConfigBuilder* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe PuttyPpkEncryptionConfigBuilder(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } public void GetArgon2Flavour(PuttyArgon2Flavour argon2Flavour) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpkEncryptionConfigBuilder"); } - Raw.PuttyArgon2Flavour argon2FlavourRaw; - argon2FlavourRaw = (Raw.PuttyArgon2Flavour)argon2Flavour; - Raw.PuttyPpkEncryptionConfigBuilder.GetArgon2Flavour(_inner, argon2FlavourRaw); + Raw.PuttyPpkEncryptionConfigBuilder.GetArgon2Flavour(AsFFI(), argon2Flavour); + GC.KeepAlive(this); } } @@ -85,11 +75,12 @@ public void SetArgon2Memory(uint argon2Memory) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpkEncryptionConfigBuilder"); } - Raw.PuttyPpkEncryptionConfigBuilder.SetArgon2Memory(_inner, argon2Memory); + Raw.PuttyPpkEncryptionConfigBuilder.SetArgon2Memory(AsFFI(), argon2Memory); + GC.KeepAlive(this); } } @@ -97,11 +88,12 @@ public void SetArgon2Passes(uint argon2Passes) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpkEncryptionConfigBuilder"); } - Raw.PuttyPpkEncryptionConfigBuilder.SetArgon2Passes(_inner, argon2Passes); + Raw.PuttyPpkEncryptionConfigBuilder.SetArgon2Passes(AsFFI(), argon2Passes); + GC.KeepAlive(this); } } @@ -109,11 +101,12 @@ public void SetArgon2Parallelism(uint argon2Parallelism) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpkEncryptionConfigBuilder"); } - Raw.PuttyPpkEncryptionConfigBuilder.SetArgon2Parallelism(_inner, argon2Parallelism); + Raw.PuttyPpkEncryptionConfigBuilder.SetArgon2Parallelism(AsFFI(), argon2Parallelism); + GC.KeepAlive(this); } } @@ -121,11 +114,12 @@ public void SetArgon2SaltSize(uint argon2SaltSize) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpkEncryptionConfigBuilder"); } - Raw.PuttyPpkEncryptionConfigBuilder.SetArgon2SaltSize(_inner, argon2SaltSize); + Raw.PuttyPpkEncryptionConfigBuilder.SetArgon2SaltSize(AsFFI(), argon2SaltSize); + GC.KeepAlive(this); } } @@ -136,21 +130,22 @@ public PuttyPpkEncryptionConfig Build() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPpkEncryptionConfigBuilder"); } - Raw.PuttyPpkEncryptionConfig* retVal = Raw.PuttyPpkEncryptionConfigBuilder.Build(_inner); - return new PuttyPpkEncryptionConfig(retVal); + Raw.PuttyPpkEncryptionConfig* result = Raw.PuttyPpkEncryptionConfigBuilder.Build(AsFFI()); + GC.KeepAlive(this); + return new PuttyPpkEncryptionConfig(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.PuttyPpkEncryptionConfigBuilder* AsFFI() + internal unsafe Raw.PuttyPpkEncryptionConfigBuilder* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -160,13 +155,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.PuttyPpkEncryptionConfigBuilder.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -176,4 +172,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkKeyAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkKeyAlgorithm.cs index 902517a8..d9df9516 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkKeyAlgorithm.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkKeyAlgorithm.cs @@ -1,20 +1,6 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// PuTTY Private Key (PPK) algorithm. -/// -public enum PuttyPpkKeyAlgorithm +public enum PuttyPpkKeyAlgorithm : int { Rsa = 0, Dss = 1, @@ -23,4 +9,4 @@ public enum PuttyPpkKeyAlgorithm EcdsaSha2Nistp521 = 4, Ed25519 = 5, Ed448 = 6, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkVersion.cs b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkVersion.cs index ed01a84f..3134aa07 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkVersion.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPpkVersion.cs @@ -1,21 +1,7 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// PuTTY Private Key (PPK) version. -/// -public enum PuttyPpkVersion +public enum PuttyPpkVersion : int { V2 = 0, V3 = 1, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPublicKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPublicKey.cs index 79fe1c3d..5b43bf26 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/PuttyPublicKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/PuttyPublicKey.cs @@ -1,32 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// PuTTY public key format. -/// -/// -/// ### Functionality: -/// - Conversion to/from OpenSSH format. -/// - Encoding/decoding to/from string. -/// - Could be extracted from `PuttyPpk` private keys. -///
-/// ### Notes -/// - Although top-level containeris similar to PEM, it is not compatible with it because of -/// additional comment field after the header. -///
public partial class PuttyPublicKey: IDisposable { - private unsafe Raw.PuttyPublicKey* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.PuttyPublicKey.Destroy; public string Comment { @@ -40,19 +32,40 @@ public string Comment /// Creates a managed PuttyPublicKey from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe PuttyPublicKey(Raw.PuttyPublicKey* handle) + internal unsafe PuttyPublicKey(Raw.PuttyPublicKey* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe PuttyPublicKey(Raw.PuttyPublicKey* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Converts an OpenSSH public key to a PuTTY public key. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe PuttyPublicKey(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A PuttyPublicKey allocated on Rust side. @@ -61,27 +74,19 @@ public static PuttyPublicKey FromOpenssh(SshPublicKey key) { unsafe { - Raw.SshPublicKey* keyRaw; - keyRaw = key.AsFFI(); - if (keyRaw == null) - { - throw new ObjectDisposedException("SshPublicKey"); - } - IntPtr resultPtr = Raw.PuttyPublicKey.FromOpenssh(keyRaw); - Raw.PuttyFfiResultBoxPuttyPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPuttyPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (key == null) throw new ArgumentNullException(nameof(key)); + Raw.SshPublicKey* keyRaw = key.AsFFI(); + if (keyRaw == null) throw new ObjectDisposedException(nameof(SshPublicKey)); + var result = Raw.PuttyPublicKey.FromOpenssh(keyRaw); + GC.KeepAlive(key); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PuttyPublicKey* retVal = result.Ok; - return new PuttyPublicKey(retVal); + return new PuttyPublicKey(result.Ok); } } - /// - /// Converts the key to an OpenSSH public key. - /// /// /// /// A SshPublicKey allocated on Rust side. @@ -90,73 +95,47 @@ public SshPublicKey ToOpenssh() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPublicKey"); } - IntPtr resultPtr = Raw.PuttyPublicKey.ToOpenssh(_inner); - Raw.PuttyFfiResultBoxSshPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxSshPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PuttyPublicKey.ToOpenssh(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SshPublicKey* retVal = result.Ok; - return new SshPublicKey(retVal); + return new SshPublicKey(result.Ok); } } - /// - /// Get the comment of the public key. - /// /// - public void GetComment(DiplomatWriteable writeable) + public string GetComment() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPublicKey"); } - IntPtr resultPtr = Raw.PuttyPublicKey.GetComment(_inner, &writeable); - Raw.PuttyFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); + var result = Raw.PuttyPublicKey.GetComment(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - } - } - - /// - /// Get the comment of the public key. - /// - /// - public string GetComment() - { - unsafe - { - if (_inner == null) + finally { - throw new ObjectDisposedException("PuttyPublicKey"); + writeable.Dispose(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.PuttyPublicKey.GetComment(_inner, &writeable); - Raw.PuttyFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } - /// - /// Returns a new public key instance with a different comment. - /// /// /// A PuttyPublicKey allocated on Rust side. /// @@ -164,71 +143,48 @@ public PuttyPublicKey WithComment(string comment) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPublicKey"); } - byte[] commentBuf = DiplomatUtils.StringToUtf8(comment); - nuint commentBufLength = (nuint)commentBuf.Length; - fixed (byte* commentBufPtr = commentBuf) + if (comment == null) throw new ArgumentNullException(nameof(comment)); + byte[] commentBytes = System.Text.Encoding.UTF8.GetBytes(comment); + fixed (byte* commentPtr = commentBytes) { - Raw.PuttyPublicKey* retVal = Raw.PuttyPublicKey.WithComment(_inner, commentBufPtr, commentBufLength); - return new PuttyPublicKey(retVal); + Raw.PuttyPublicKey* result = Raw.PuttyPublicKey.WithComment(AsFFI(), new DiplomatSliceU8 { Ptr = commentPtr, Len = (nuint)commentBytes.Length }); + GC.KeepAlive(this); + return new PuttyPublicKey(result); } } } - /// - /// Converts the public key to a string (PuTTY format). - /// /// - public void ToRepr(DiplomatWriteable writeable) + public string ToRepr() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPublicKey"); } - IntPtr resultPtr = Raw.PuttyPublicKey.ToRepr(_inner, &writeable); - Raw.PuttyFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - /// Converts the public key to a string (PuTTY format). - /// - /// - public string ToRepr() - { - unsafe - { - if (_inner == null) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("PuttyPublicKey"); + var result = Raw.PuttyPublicKey.ToRepr(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.PuttyPublicKey.ToRepr(_inner, &writeable); - Raw.PuttyFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } - /// - /// Parses and returns the inner key as standard picky key type. - /// /// /// /// A PublicKey allocated on Rust side. @@ -237,28 +193,26 @@ public PublicKey ToInnerKey() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PuttyPublicKey"); } - IntPtr resultPtr = Raw.PuttyPublicKey.ToInnerKey(_inner); - Raw.PuttyFfiResultBoxPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.PuttyFfiResultBoxPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.PuttyPublicKey.ToInnerKey(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.PublicKey* retVal = result.Ok; - return new PublicKey(retVal); + return new PublicKey(result.Ok); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.PuttyPublicKey* AsFFI() + internal unsafe Raw.PuttyPublicKey* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -268,13 +222,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.PuttyPublicKey.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -284,4 +239,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAesAuthEncParams.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAesAuthEncParams.cs index 15e784a4..4fb893db 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAesAuthEncParams.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAesAuthEncParams.cs @@ -1,25 +1,14 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AesAuthEncParams +internal partial struct AesAuthEncParams { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AesAuthEncParams_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AesAuthEncParams* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AesAuthEncParams_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AesAuthEncParams* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAesParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAesParameters.cs index f260a17a..86f8a7d2 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAesParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAesParameters.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AesParameters +internal partial struct AesParameters { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AesParameters_get_type", ExactSpelling = true)] - public static unsafe extern AesParametersType GetType(AesParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AesParameters_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AesParametersType GetType(AesParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AesParameters_to_initialization_vector", ExactSpelling = true)] - public static unsafe extern VecU8* ToInitializationVector(AesParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AesParameters_to_initialization_vector", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* ToInitializationVector(AesParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AesParameters_to_authenticated_encryption_parameters", ExactSpelling = true)] - public static unsafe extern AesAuthEncParams* ToAuthenticatedEncryptionParameters(AesParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AesParameters_to_authenticated_encryption_parameters", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AesAuthEncParams* ToAuthenticatedEncryptionParameters(AesParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AesParameters_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AesParameters* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AesParameters_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AesParameters* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAesParametersType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAesParametersType.cs deleted file mode 100644 index 7148e68c..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAesParametersType.cs +++ /dev/null @@ -1,19 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum AesParametersType -{ - Null = 0, - InitializationVector = 1, - AuthenticatedEncryptionParameters = 2, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifier.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifier.cs index 3eef9b19..961a9687 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifier.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifier.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AlgorithmIdentifier +internal partial struct AlgorithmIdentifier { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifier_is_a", ExactSpelling = true)] - public static unsafe extern IntPtr IsA(AlgorithmIdentifier* self, byte* other, nuint otherSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifier_is_a", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultBoolPickyError IsA(AlgorithmIdentifier* handle, DiplomatSliceU8 other); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifier_get_oid", ExactSpelling = true)] - public static unsafe extern IntPtr GetOid(AlgorithmIdentifier* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifier_get_oid", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetOid(AlgorithmIdentifier* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifier_get_parameters", ExactSpelling = true)] - public static unsafe extern AlgorithmIdentifierParameters* GetParameters(AlgorithmIdentifier* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifier_get_parameters", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AlgorithmIdentifierParameters* GetParameters(AlgorithmIdentifier* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifier_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AlgorithmIdentifier* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifier_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AlgorithmIdentifier* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierIterator.cs index bdf282ee..32c3ce69 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AlgorithmIdentifierIterator +internal partial struct AlgorithmIdentifierIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifierIterator_next", ExactSpelling = true)] - public static unsafe extern AlgorithmIdentifier* Next(AlgorithmIdentifierIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifierIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AlgorithmIdentifier* Next(AlgorithmIdentifierIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifierIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AlgorithmIdentifierIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifierIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AlgorithmIdentifierIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierParameters.cs index 1b45f8ae..71bee2aa 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierParameters.cs @@ -1,40 +1,26 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// TODO/FIXME: Is having a reference here safe? We perhaps need to clone the parameters. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct AlgorithmIdentifierParameters +internal partial struct AlgorithmIdentifierParameters { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifierParameters_get_type", ExactSpelling = true)] - public static unsafe extern AlgorithmIdentifierParametersType GetType(AlgorithmIdentifierParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifierParameters_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AlgorithmIdentifierParametersType GetType(AlgorithmIdentifierParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifierParameters_to_aes", ExactSpelling = true)] - public static unsafe extern AesParameters* ToAes(AlgorithmIdentifierParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifierParameters_to_aes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AesParameters* ToAes(AlgorithmIdentifierParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifierParameters_to_ec", ExactSpelling = true)] - public static unsafe extern EcParameters* ToEc(AlgorithmIdentifierParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifierParameters_to_ec", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern EcParameters* ToEc(AlgorithmIdentifierParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifierParameters_to_rsassa_pss", ExactSpelling = true)] - public static unsafe extern RsassaPssParameters* ToRsassaPss(AlgorithmIdentifierParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifierParameters_to_rsassa_pss", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern RsassaPssParameters* ToRsassaPss(AlgorithmIdentifierParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AlgorithmIdentifierParameters_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AlgorithmIdentifierParameters* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AlgorithmIdentifierParameters_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AlgorithmIdentifierParameters* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierParametersType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierParametersType.cs deleted file mode 100644 index f2473ae0..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAlgorithmIdentifierParametersType.cs +++ /dev/null @@ -1,21 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum AlgorithmIdentifierParametersType -{ - None = 0, - Null = 1, - Aes = 2, - Ec = 3, - RsassaPss = 4, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2.cs index 5c758a08..f378b461 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Argon2 +internal partial struct Argon2 { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Argon2_new", ExactSpelling = true)] - public static unsafe extern IntPtr New(Argon2Algorithm algorithm, Argon2Params* parameters); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Argon2_new", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultArgon2PickyError New(Argon2Algorithm algorithm, Argon2Params* parameters); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Argon2_hash_password", ExactSpelling = true)] - public static unsafe extern IntPtr HashPassword(Argon2* self, byte* password, nuint passwordSz, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Argon2_hash_password", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError HashPassword(Argon2* handle, DiplomatSliceU8 password, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Argon2_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Argon2* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Argon2_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Argon2* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2Algorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2Algorithm.cs deleted file mode 100644 index fe436dde..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2Algorithm.cs +++ /dev/null @@ -1,19 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum Argon2Algorithm -{ - Argon2d = 0, - Argon2i = 1, - Argon2id = 2, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2FfiResultBoxArgon2BoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2FfiResultBoxArgon2BoxPickyError.cs deleted file mode 100644 index c34b174a..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2FfiResultBoxArgon2BoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct Argon2FfiResultBoxArgon2BoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Argon2* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Argon2* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Argon2_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2FfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2FfiResultVoidBoxPickyError.cs deleted file mode 100644 index eb9661da..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2FfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct Argon2FfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2Params.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2Params.cs index b5e751f2..593c04bf 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2Params.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawArgon2Params.cs @@ -1,55 +1,29 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Argon2Params +internal partial struct Argon2Params { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - /// - /// Create new parameters. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Argon2Params_new", ExactSpelling = true)] - public static unsafe extern Argon2Params* New(); - - /// - /// Sets the memory size in 1 KiB blocks. Between 1 and (2^32)-1. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Argon2Params_set_m_cost", ExactSpelling = true)] - public static unsafe extern void SetMCost(Argon2Params* self, uint value); - - /// - /// Sets the number of iterations. Between 1 and (2^32)-1. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Argon2Params_set_t_cost", ExactSpelling = true)] - public static unsafe extern void SetTCost(Argon2Params* self, uint value); - - /// - /// Sets the degree of parallelism. Between 1 and 255. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Argon2Params_set_p_cost", ExactSpelling = true)] - public static unsafe extern void SetPCost(Argon2Params* self, uint value); - - /// - /// Sets the size of the KDF output in bytes. Default 32. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Argon2Params_set_output_len", ExactSpelling = true)] - public static unsafe extern void SetOutputLen(Argon2Params* self, nuint value); - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Argon2Params_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Argon2Params* self); -} + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Argon2Params_new", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Argon2Params* New(); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Argon2Params_set_m_cost", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetMCost(Argon2Params* handle, uint value); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Argon2Params_set_t_cost", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetTCost(Argon2Params* handle, uint value); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Argon2Params_set_p_cost", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetPCost(Argon2Params* handle, uint value); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Argon2Params_set_output_len", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetOutputLen(Argon2Params* handle, nuint value); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Argon2Params_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Argon2Params* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAttribute.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAttribute.cs index 454f0040..3bfcb659 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAttribute.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAttribute.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Attribute +internal partial struct Attribute { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Attribute_get_type", ExactSpelling = true)] - public static unsafe extern IntPtr GetType(Attribute* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Attribute_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetType(Attribute* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Attribute_get_values", ExactSpelling = true)] - public static unsafe extern AttributeValues* GetValues(Attribute* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Attribute_get_values", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AttributeValues* GetValues(Attribute* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Attribute_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Attribute* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Attribute_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Attribute* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeIterator.cs index ba79218d..bcd4af33 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AttributeIterator +internal partial struct AttributeIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeIterator_next", ExactSpelling = true)] - public static unsafe extern Attribute* Next(AttributeIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Attribute* Next(AttributeIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AttributeIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AttributeIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValue.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValue.cs index fe2d1ef8..8b3d4971 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValue.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValue.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AttributeTypeAndValue +internal partial struct AttributeTypeAndValue { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValue_get_type_id", ExactSpelling = true)] - public static unsafe extern IntPtr GetTypeId(AttributeTypeAndValue* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValue_get_type_id", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetTypeId(AttributeTypeAndValue* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValue_get_value", ExactSpelling = true)] - public static unsafe extern AttributeTypeAndValueParameters* GetValue(AttributeTypeAndValue* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValue_get_value", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AttributeTypeAndValueParameters* GetValue(AttributeTypeAndValue* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValue_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AttributeTypeAndValue* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValue_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AttributeTypeAndValue* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueIterator.cs index e5e76628..0899dbfd 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AttributeTypeAndValueIterator +internal partial struct AttributeTypeAndValueIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueIterator_next", ExactSpelling = true)] - public static unsafe extern AttributeTypeAndValue* Next(AttributeTypeAndValueIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AttributeTypeAndValue* Next(AttributeTypeAndValueIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AttributeTypeAndValueIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AttributeTypeAndValueIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueNestedIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueNestedIterator.cs index 75d5e28e..d56dd69a 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueNestedIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueNestedIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AttributeTypeAndValueNestedIterator +internal partial struct AttributeTypeAndValueNestedIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueNestedIterator_next", ExactSpelling = true)] - public static unsafe extern AttributeTypeAndValueIterator* Next(AttributeTypeAndValueNestedIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueNestedIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AttributeTypeAndValueIterator* Next(AttributeTypeAndValueNestedIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueNestedIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AttributeTypeAndValueNestedIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueNestedIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AttributeTypeAndValueNestedIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueParameters.cs index b238e6a0..1a19b97f 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueParameters.cs @@ -1,67 +1,56 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AttributeTypeAndValueParameters +internal partial struct AttributeTypeAndValueParameters { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_get_type", ExactSpelling = true)] - public static unsafe extern AttributeTypeAndValueParametersType GetType(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AttributeTypeAndValueParametersType GetType(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_common_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToCommonName(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_common_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToCommonName(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_surname", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToSurname(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_surname", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToSurname(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_serial_number", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToSerialNumber(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_serial_number", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToSerialNumber(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_country_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToCountryName(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_country_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToCountryName(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_locality_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToLocalityName(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_locality_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToLocalityName(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_state_or_province_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToStateOrProvinceName(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_state_or_province_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToStateOrProvinceName(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_street_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToStreetName(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_street_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToStreetName(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_organization_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToOrganizationName(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_organization_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToOrganizationName(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_organizational_unit_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToOrganizationalUnitName(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_organizational_unit_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToOrganizationalUnitName(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_email_address", ExactSpelling = true)] - public static unsafe extern VecU8* ToEmailAddress(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_email_address", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* ToEmailAddress(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_given_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToGivenName(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_given_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToGivenName(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_phone", ExactSpelling = true)] - public static unsafe extern DirectoryString* ToPhone(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_phone", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* ToPhone(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_to_custom", ExactSpelling = true)] - public static unsafe extern VecU8* ToCustom(AttributeTypeAndValueParameters* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_to_custom", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* ToCustom(AttributeTypeAndValueParameters* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeTypeAndValueParameters_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AttributeTypeAndValueParameters* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeTypeAndValueParameters_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AttributeTypeAndValueParameters* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueParametersType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueParametersType.cs deleted file mode 100644 index cee02968..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeTypeAndValueParametersType.cs +++ /dev/null @@ -1,29 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum AttributeTypeAndValueParametersType -{ - CommonName = 0, - Surname = 1, - SerialNumber = 2, - CountryName = 3, - LocalityName = 4, - StateOrProvinceName = 5, - StreetName = 6, - OrganizationName = 7, - OrganizationalUnitName = 8, - EmailAddress = 9, - GivenName = 10, - Phone = 11, - Custom = 12, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeValueType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeValueType.cs deleted file mode 100644 index 668b6603..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeValueType.cs +++ /dev/null @@ -1,23 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum AttributeValueType -{ - Extensions = 0, - ContentType = 1, - SpcStatementType = 2, - MessageDigest = 3, - SigningTime = 4, - SpcSpOpusInfo = 5, - Custom = 6, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeValues.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeValues.cs index 2b0e7264..f0ff995e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeValues.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAttributeValues.cs @@ -1,49 +1,38 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AttributeValues +internal partial struct AttributeValues { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeValues_get_type", ExactSpelling = true)] - public static unsafe extern AttributeValueType GetType(AttributeValues* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeValues_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AttributeValueType GetType(AttributeValues* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeValues_to_custom", ExactSpelling = true)] - public static unsafe extern VecU8* ToCustom(AttributeValues* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeValues_to_custom", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* ToCustom(AttributeValues* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeValues_to_extensions", ExactSpelling = true)] - public static unsafe extern ExtensionIterator* ToExtensions(AttributeValues* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeValues_to_extensions", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ExtensionIterator* ToExtensions(AttributeValues* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeValues_to_content_type", ExactSpelling = true)] - public static unsafe extern StringIterator* ToContentType(AttributeValues* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeValues_to_content_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern StringIterator* ToContentType(AttributeValues* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeValues_to_spc_statement_type", ExactSpelling = true)] - public static unsafe extern StringNestedIterator* ToSpcStatementType(AttributeValues* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeValues_to_spc_statement_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern StringNestedIterator* ToSpcStatementType(AttributeValues* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeValues_to_message_digest", ExactSpelling = true)] - public static unsafe extern StringIterator* ToMessageDigest(AttributeValues* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeValues_to_message_digest", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern StringIterator* ToMessageDigest(AttributeValues* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeValues_to_signing_time", ExactSpelling = true)] - public static unsafe extern UTCTimeIterator* ToSigningTime(AttributeValues* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeValues_to_signing_time", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UTCTimeIterator* ToSigningTime(AttributeValues* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeValues_to_spc_sp_opus_info", ExactSpelling = true)] - public static unsafe extern SpcSpOpusInfoIterator* ToSpcSpOpusInfo(AttributeValues* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeValues_to_spc_sp_opus_info", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SpcSpOpusInfoIterator* ToSpcSpOpusInfo(AttributeValues* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AttributeValues_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AttributeValues* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AttributeValues_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AttributeValues* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeSignature.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeSignature.cs index 5566e9ef..231588c3 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeSignature.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeSignature.cs @@ -1,61 +1,50 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AuthenticodeSignature +internal partial struct AuthenticodeSignature { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_new", ExactSpelling = true)] - public static unsafe extern IntPtr New(Pkcs7* pkcs7, VecU8* fileHash, ShaVariant hashAlgorithm, PrivateKey* privateKey, RsString* programName); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_new", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultAuthenticodeSignaturePickyError New(Pkcs7* pkcs7, VecU8* fileHash, ShaVariant hashAlgorithm, PrivateKey* privateKey, RsString* programName); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_timestamp", ExactSpelling = true)] - public static unsafe extern IntPtr Timestamp(AuthenticodeSignature* self, AuthenticodeTimestamper* timestamper, HashAlgorithm hashAlgo); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_timestamp", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError Timestamp(AuthenticodeSignature* handle, AuthenticodeTimestamper* timestamper, HashAlgorithm hashAlgo); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_from_der", ExactSpelling = true)] - public static unsafe extern IntPtr FromDer(VecU8* der); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_from_der", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultAuthenticodeSignaturePickyError FromDer(VecU8* der); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_from_pem", ExactSpelling = true)] - public static unsafe extern IntPtr FromPem(Pem* pem); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_from_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultAuthenticodeSignaturePickyError FromPem(Pem* pem); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_from_pem_str", ExactSpelling = true)] - public static unsafe extern IntPtr FromPemStr(byte* pem, nuint pemSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_from_pem_str", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultAuthenticodeSignaturePickyError FromPemStr(DiplomatSliceU8 pem); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_to_der", ExactSpelling = true)] - public static unsafe extern IntPtr ToDer(AuthenticodeSignature* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_to_der", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVecU8PickyError ToDer(AuthenticodeSignature* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_to_pem", ExactSpelling = true)] - public static unsafe extern IntPtr ToPem(AuthenticodeSignature* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_to_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError ToPem(AuthenticodeSignature* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_signing_certificate", ExactSpelling = true)] - public static unsafe extern IntPtr SigningCertificate(AuthenticodeSignature* self, CertIterator* cert); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_signing_certificate", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultCertPickyError SigningCertificate(AuthenticodeSignature* handle, CertIterator* cert); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_authenticode_verifier", ExactSpelling = true)] - public static unsafe extern AuthenticodeValidator* AuthenticodeVerifier(AuthenticodeSignature* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_authenticode_verifier", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AuthenticodeValidator* AuthenticodeVerifier(AuthenticodeSignature* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_file_hash", ExactSpelling = true)] - public static unsafe extern VecU8* FileHash(AuthenticodeSignature* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_file_hash", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* FileHash(AuthenticodeSignature* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_authenticate_attributes", ExactSpelling = true)] - public static unsafe extern AttributeIterator* AuthenticateAttributes(AuthenticodeSignature* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_authenticate_attributes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AttributeIterator* AuthenticateAttributes(AuthenticodeSignature* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_unauthenticated_attributes", ExactSpelling = true)] - public static unsafe extern UnsignedAttributeIterator* UnauthenticatedAttributes(AuthenticodeSignature* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_unauthenticated_attributes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UnsignedAttributeIterator* UnauthenticatedAttributes(AuthenticodeSignature* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeSignature_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AuthenticodeSignature* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeSignature_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AuthenticodeSignature* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeTimestamper.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeTimestamper.cs index 6a537c57..efc864bc 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeTimestamper.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeTimestamper.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AuthenticodeTimestamper +internal partial struct AuthenticodeTimestamper { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeTimestamper_new", ExactSpelling = true)] - public static unsafe extern IntPtr New(byte* url, nuint urlSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeTimestamper_new", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultAuthenticodeTimestamperPickyError New(DiplomatSliceU8 url); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeTimestamper_timestamp", ExactSpelling = true)] - public static unsafe extern IntPtr Timestamp(AuthenticodeTimestamper* self, VecU8* digest, HashAlgorithm hashAlgo); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeTimestamper_timestamp", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPkcs7PickyError Timestamp(AuthenticodeTimestamper* handle, VecU8* digest, HashAlgorithm hashAlgo); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeTimestamper_modify_signed_data", ExactSpelling = true)] - public static unsafe extern void ModifySignedData(AuthenticodeTimestamper* self, Pkcs7* token, SignedData* signedData); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeTimestamper_modify_signed_data", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void ModifySignedData(AuthenticodeTimestamper* handle, Pkcs7* token, SignedData* signedData); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeTimestamper_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AuthenticodeTimestamper* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeTimestamper_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AuthenticodeTimestamper* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeValidator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeValidator.cs index eed98deb..c4b41c2f 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeValidator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAuthenticodeValidator.cs @@ -1,67 +1,56 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AuthenticodeValidator +internal partial struct AuthenticodeValidator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_exact_date", ExactSpelling = true)] - public static unsafe extern void ExactDate(AuthenticodeValidator* self, UtcDate* exact); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_exact_date", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void ExactDate(AuthenticodeValidator* handle, UtcDate* exact); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_interval_date", ExactSpelling = true)] - public static unsafe extern void IntervalDate(AuthenticodeValidator* self, UtcDate* lower, UtcDate* upper); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_interval_date", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void IntervalDate(AuthenticodeValidator* handle, UtcDate* lower, UtcDate* upper); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_require_not_before_check", ExactSpelling = true)] - public static unsafe extern void RequireNotBeforeCheck(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_require_not_before_check", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void RequireNotBeforeCheck(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_require_not_after_check", ExactSpelling = true)] - public static unsafe extern void RequireNotAfterCheck(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_require_not_after_check", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void RequireNotAfterCheck(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_ignore_not_before_check", ExactSpelling = true)] - public static unsafe extern void IgnoreNotBeforeCheck(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_ignore_not_before_check", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void IgnoreNotBeforeCheck(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_ignore_not_after_check", ExactSpelling = true)] - public static unsafe extern void IgnoreNotAfterCheck(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_ignore_not_after_check", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void IgnoreNotAfterCheck(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_require_signing_certificate_check", ExactSpelling = true)] - public static unsafe extern void RequireSigningCertificateCheck(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_require_signing_certificate_check", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void RequireSigningCertificateCheck(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_ignore_signing_certificate_check", ExactSpelling = true)] - public static unsafe extern void IgnoreSigningCertificateCheck(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_ignore_signing_certificate_check", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void IgnoreSigningCertificateCheck(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_require_basic_authenticode_validation", ExactSpelling = true)] - public static unsafe extern void RequireBasicAuthenticodeValidation(AuthenticodeValidator* self, VecU8* expectedFileHash); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_require_basic_authenticode_validation", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void RequireBasicAuthenticodeValidation(AuthenticodeValidator* handle, VecU8* expectedFileHash); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_ignore_basic_authenticode_validation", ExactSpelling = true)] - public static unsafe extern void IgnoreBasicAuthenticodeValidation(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_ignore_basic_authenticode_validation", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void IgnoreBasicAuthenticodeValidation(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_require_chain_check", ExactSpelling = true)] - public static unsafe extern void RequireChainCheck(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_require_chain_check", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void RequireChainCheck(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_ignore_chain_check", ExactSpelling = true)] - public static unsafe extern void IgnoreChainCheck(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_ignore_chain_check", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void IgnoreChainCheck(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_exclude_cert_authorities", ExactSpelling = true)] - public static unsafe extern void ExcludeCertAuthorities(AuthenticodeValidator* self, DirectoryNameIterator* certAuths); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_exclude_cert_authorities", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void ExcludeCertAuthorities(AuthenticodeValidator* handle, DirectoryNameIterator* certAuths); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_verify", ExactSpelling = true)] - public static unsafe extern IntPtr Verify(AuthenticodeValidator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_verify", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError Verify(AuthenticodeValidator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthenticodeValidator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AuthenticodeValidator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthenticodeValidator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AuthenticodeValidator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawAuthorityKeyIdentifier.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawAuthorityKeyIdentifier.cs index 95733d86..d14e28fe 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawAuthorityKeyIdentifier.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawAuthorityKeyIdentifier.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct AuthorityKeyIdentifier +internal partial struct AuthorityKeyIdentifier { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthorityKeyIdentifier_get_key_identifier", ExactSpelling = true)] - public static unsafe extern VecU8* GetKeyIdentifier(AuthorityKeyIdentifier* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthorityKeyIdentifier_get_key_identifier", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetKeyIdentifier(AuthorityKeyIdentifier* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthorityKeyIdentifier_get_authority_cert_issuer", ExactSpelling = true)] - public static unsafe extern GeneralName* GetAuthorityCertIssuer(AuthorityKeyIdentifier* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthorityKeyIdentifier_get_authority_cert_issuer", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern GeneralName* GetAuthorityCertIssuer(AuthorityKeyIdentifier* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthorityKeyIdentifier_get_authority_cert_serial_number", ExactSpelling = true)] - public static unsafe extern VecU8* GetAuthorityCertSerialNumber(AuthorityKeyIdentifier* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthorityKeyIdentifier_get_authority_cert_serial_number", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetAuthorityCertSerialNumber(AuthorityKeyIdentifier* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "AuthorityKeyIdentifier_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(AuthorityKeyIdentifier* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "AuthorityKeyIdentifier_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(AuthorityKeyIdentifier* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawBasicConstraints.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawBasicConstraints.cs index 21f56b77..30163848 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawBasicConstraints.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawBasicConstraints.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct BasicConstraints +internal partial struct BasicConstraints { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "BasicConstraints_get_ca", ExactSpelling = true)] - public static unsafe extern GetCaResult GetCa(BasicConstraints* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "BasicConstraints_get_ca", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern GetCaResult GetCa(BasicConstraints* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "BasicConstraints_get_pathlen", ExactSpelling = true)] - public static unsafe extern U8* GetPathlen(BasicConstraints* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "BasicConstraints_get_pathlen", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern U8* GetPathlen(BasicConstraints* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "BasicConstraints_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(BasicConstraints* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "BasicConstraints_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(BasicConstraints* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawBufferTooSmallError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawBufferTooSmallError.cs index 135966ca..2a574e65 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawBufferTooSmallError.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawBufferTooSmallError.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct BufferTooSmallError +internal partial struct BufferTooSmallError { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "BufferTooSmallError_to_display", ExactSpelling = true)] - public static unsafe extern void ToDisplay(BufferTooSmallError* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "BufferTooSmallError_to_display", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void ToDisplay(BufferTooSmallError* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "BufferTooSmallError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(BufferTooSmallError* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "BufferTooSmallError_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(BufferTooSmallError* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawCert.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawCert.cs index aec29b0e..c7b73be3 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawCert.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawCert.cs @@ -1,67 +1,47 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Cert +internal partial struct Cert { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Parses a X509 certificate from its DER representation. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_from_der", ExactSpelling = true)] - public static unsafe extern IntPtr FromDer(byte* der, nuint derSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_from_der", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultCertPickyError FromDer(DiplomatSliceU8 der); - /// - /// Extracts X509 certificate from PEM object. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_from_pem", ExactSpelling = true)] - public static unsafe extern IntPtr FromPem(Pem* pem); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_from_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultCertPickyError FromPem(Pem* pem); - /// - /// Exports the X509 certificate into a PEM object - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_to_pem", ExactSpelling = true)] - public static unsafe extern IntPtr ToPem(Cert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_to_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError ToPem(Cert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_get_ty", ExactSpelling = true)] - public static unsafe extern CertType GetTy(Cert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_get_ty", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern CertType GetTy(Cert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_get_public_key", ExactSpelling = true)] - public static unsafe extern PublicKey* GetPublicKey(Cert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_get_public_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PublicKey* GetPublicKey(Cert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_get_cert_type", ExactSpelling = true)] - public static unsafe extern CertType GetCertType(Cert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_get_cert_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern CertType GetCertType(Cert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_get_valid_not_before", ExactSpelling = true)] - public static unsafe extern UtcDate* GetValidNotBefore(Cert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_get_valid_not_before", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UtcDate* GetValidNotBefore(Cert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_get_valid_not_after", ExactSpelling = true)] - public static unsafe extern UtcDate* GetValidNotAfter(Cert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_get_valid_not_after", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UtcDate* GetValidNotAfter(Cert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_get_subject_key_id_hex", ExactSpelling = true)] - public static unsafe extern IntPtr GetSubjectKeyIdHex(Cert* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_get_subject_key_id_hex", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetSubjectKeyIdHex(Cert* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_get_subject_name", ExactSpelling = true)] - public static unsafe extern IntPtr GetSubjectName(Cert* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_get_subject_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetSubjectName(Cert* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_get_issuer_name", ExactSpelling = true)] - public static unsafe extern IntPtr GetIssuerName(Cert* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_get_issuer_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetIssuerName(Cert* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Cert_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Cert* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Cert_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Cert* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawCertIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawCertIterator.cs index a0618a4b..1a2c189d 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawCertIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawCertIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct CertIterator +internal partial struct CertIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertIterator_next", ExactSpelling = true)] - public static unsafe extern Cert* Next(CertIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Cert* Next(CertIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(CertIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(CertIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawCertType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawCertType.cs deleted file mode 100644 index 2598b1e7..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawCertType.cs +++ /dev/null @@ -1,20 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum CertType -{ - Root = 0, - Intermediate = 1, - Leaf = 2, - Unknown = 3, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateBuilder.cs index 591ec6df..094211a6 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateBuilder.cs @@ -1,55 +1,44 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct CertificateBuilder +internal partial struct CertificateBuilder { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_new", ExactSpelling = true)] - public static unsafe extern CertificateBuilder* New(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_new", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern CertificateBuilder* New(); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_set_valid_from", ExactSpelling = true)] - public static unsafe extern void SetValidFrom(CertificateBuilder* self, UtcDate* validFrom); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_set_valid_from", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetValidFrom(CertificateBuilder* handle, UtcDate* validFrom); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_set_valid_to", ExactSpelling = true)] - public static unsafe extern void SetValidTo(CertificateBuilder* self, UtcDate* validTo); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_set_valid_to", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetValidTo(CertificateBuilder* handle, UtcDate* validTo); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_set_issuer_common_name", ExactSpelling = true)] - public static unsafe extern void SetIssuerCommonName(CertificateBuilder* self, byte* name, nuint nameSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_set_issuer_common_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetIssuerCommonName(CertificateBuilder* handle, DiplomatSliceU8 name); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_set_subject_dns_name", ExactSpelling = true)] - public static unsafe extern void SetSubjectDnsName(CertificateBuilder* self, byte* name, nuint nameSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_set_subject_dns_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetSubjectDnsName(CertificateBuilder* handle, DiplomatSliceU8 name); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_set_issuer_key", ExactSpelling = true)] - public static unsafe extern void SetIssuerKey(CertificateBuilder* self, PrivateKey* key); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_set_issuer_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetIssuerKey(CertificateBuilder* handle, PrivateKey* key); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_set_self_signed", ExactSpelling = true)] - public static unsafe extern void SetSelfSigned(CertificateBuilder* self, [MarshalAs(UnmanagedType.U1)] bool isSelfSigned); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_set_self_signed", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetSelfSigned(CertificateBuilder* handle, [MarshalAs(UnmanagedType.U1)] bool isSelfSigned); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_set_ku_digital_signature", ExactSpelling = true)] - public static unsafe extern void SetKuDigitalSignature(CertificateBuilder* self, [MarshalAs(UnmanagedType.U1)] bool enable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_set_ku_digital_signature", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetKuDigitalSignature(CertificateBuilder* handle, [MarshalAs(UnmanagedType.U1)] bool enable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_set_kp_server_auth", ExactSpelling = true)] - public static unsafe extern void SetKpServerAuth(CertificateBuilder* self, [MarshalAs(UnmanagedType.U1)] bool enable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_set_kp_server_auth", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetKpServerAuth(CertificateBuilder* handle, [MarshalAs(UnmanagedType.U1)] bool enable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_build", ExactSpelling = true)] - public static unsafe extern IntPtr Build(CertificateBuilder* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_build", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultCertPickyError Build(CertificateBuilder* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateBuilder_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(CertificateBuilder* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateBuilder_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(CertificateBuilder* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateChoices.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateChoices.cs index 2b7413c8..6344f6e2 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateChoices.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateChoices.cs @@ -1,35 +1,24 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct CertificateChoices +internal partial struct CertificateChoices { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateChoices_get_certificate", ExactSpelling = true)] - public static unsafe extern VecU8* GetCertificate(CertificateChoices* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateChoices_get_certificate", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetCertificate(CertificateChoices* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateChoices_get_other", ExactSpelling = true)] - public static unsafe extern VecU8* GetOther(CertificateChoices* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateChoices_get_other", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetOther(CertificateChoices* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateChoices_is_certificate", ExactSpelling = true)] + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateChoices_is_certificate", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] - public static unsafe extern bool IsCertificate(CertificateChoices* self); + internal static unsafe extern bool IsCertificate(CertificateChoices* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateChoices_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(CertificateChoices* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateChoices_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(CertificateChoices* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateChoicesIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateChoicesIterator.cs index cd2725da..9f1f9da4 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateChoicesIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateChoicesIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct CertificateChoicesIterator +internal partial struct CertificateChoicesIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateChoicesIterator_next", ExactSpelling = true)] - public static unsafe extern CertificateChoices* Next(CertificateChoicesIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateChoicesIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern CertificateChoices* Next(CertificateChoicesIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateChoicesIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(CertificateChoicesIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateChoicesIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(CertificateChoicesIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateList.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateList.cs index 0248ebf8..2c8d4836 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateList.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawCertificateList.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct CertificateList +internal partial struct CertificateList { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateList_get_tbs_cert_list", ExactSpelling = true)] - public static unsafe extern TbsCertList* GetTbsCertList(CertificateList* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateList_get_tbs_cert_list", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern TbsCertList* GetTbsCertList(CertificateList* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateList_get_signature_algorithm", ExactSpelling = true)] - public static unsafe extern AlgorithmIdentifier* GetSignatureAlgorithm(CertificateList* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateList_get_signature_algorithm", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AlgorithmIdentifier* GetSignatureAlgorithm(CertificateList* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateList_get_signature_value", ExactSpelling = true)] - public static unsafe extern VecU8* GetSignatureValue(CertificateList* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateList_get_signature_value", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetSignatureValue(CertificateList* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "CertificateList_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(CertificateList* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "CertificateList_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(CertificateList* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawCmsVersion.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawCmsVersion.cs deleted file mode 100644 index cf71349e..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawCmsVersion.cs +++ /dev/null @@ -1,22 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum CmsVersion -{ - V0 = 0, - V1 = 1, - V2 = 2, - V3 = 3, - V4 = 4, - V5 = 5, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawDateFfiResultBoxUtcDateBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawDateFfiResultBoxUtcDateBoxPickyError.cs deleted file mode 100644 index 53073b56..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawDateFfiResultBoxUtcDateBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct DateFfiResultBoxUtcDateBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal UtcDate* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe UtcDate* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_UtcDate_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawDateFfiResultI64BoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawDateFfiResultI64BoxPickyError.cs deleted file mode 100644 index cd21fd13..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawDateFfiResultI64BoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct DateFfiResultI64BoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal long ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe long Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_i64_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryName.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryName.cs index fda1a061..f27b8023 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryName.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryName.cs @@ -1,40 +1,29 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct DirectoryName +internal partial struct DirectoryName { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryName_new", ExactSpelling = true)] - public static unsafe extern DirectoryName* New(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryName_new", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryName* New(); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryName_new_common_name", ExactSpelling = true)] - public static unsafe extern DirectoryName* NewCommonName(byte* name, nuint nameSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryName_new_common_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryName* NewCommonName(DiplomatSliceU8 name); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryName_find_common_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* FindCommonName(DirectoryName* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryName_find_common_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* FindCommonName(DirectoryName* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryName_add_attr", ExactSpelling = true)] - public static unsafe extern void AddAttr(DirectoryName* self, NameAttr attr, byte* value, nuint valueSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryName_add_attr", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void AddAttr(DirectoryName* handle, NameAttr attr, DiplomatSliceU8 value); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryName_add_email", ExactSpelling = true)] - public static unsafe extern IntPtr AddEmail(DirectoryName* self, byte* email, nuint emailSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryName_add_email", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError AddEmail(DirectoryName* handle, DiplomatSliceU8 email); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryName_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(DirectoryName* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryName_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(DirectoryName* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryNameIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryNameIterator.cs index 52d06773..ed8c0562 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryNameIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryNameIterator.cs @@ -1,25 +1,14 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct DirectoryNameIterator +internal partial struct DirectoryNameIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryNameIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(DirectoryNameIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryNameIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(DirectoryNameIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryString.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryString.cs index 67064289..eacfab34 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryString.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryString.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct DirectoryString +internal partial struct DirectoryString { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryString_get_type", ExactSpelling = true)] - public static unsafe extern DirectoryStringType GetType(DirectoryString* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryString_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryStringType GetType(DirectoryString* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryString_get_as_string", ExactSpelling = true)] - public static unsafe extern IntPtr GetAsString(DirectoryString* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryString_get_as_string", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetAsString(DirectoryString* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryString_get_as_bytes", ExactSpelling = true)] - public static unsafe extern VecU8* GetAsBytes(DirectoryString* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryString_get_as_bytes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetAsBytes(DirectoryString* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "DirectoryString_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(DirectoryString* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "DirectoryString_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(DirectoryString* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryStringType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryStringType.cs deleted file mode 100644 index cecf54e5..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawDirectoryStringType.cs +++ /dev/null @@ -1,19 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum DirectoryStringType -{ - PrintableString = 0, - Utf8String = 1, - BmpString = 2, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawEcCurve.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawEcCurve.cs deleted file mode 100644 index 5b80944c..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawEcCurve.cs +++ /dev/null @@ -1,31 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// Known elliptic curve name used for ECDSA arithmetic operations -/// -public enum EcCurve -{ - /// - /// NIST P-256 - /// - NistP256 = 0, - /// - /// NIST P-384 - /// - NistP384 = 1, - /// - /// NIST P-521 - /// - NistP521 = 2, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawEcParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawEcParameters.cs index 38460115..f3b23d27 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawEcParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawEcParameters.cs @@ -1,25 +1,14 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct EcParameters +internal partial struct EcParameters { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "EcParameters_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(EcParameters* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "EcParameters_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(EcParameters* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawEdAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawEdAlgorithm.cs deleted file mode 100644 index d2c36c98..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawEdAlgorithm.cs +++ /dev/null @@ -1,27 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// Known Edwards curve-based algorithm name -/// -public enum EdAlgorithm -{ - /// - /// Ed25519 signing algorithm - /// - Ed25519 = 0, - /// - /// X25519 key agreement algorithm - /// - X25519 = 1, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawEdiPartyName.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawEdiPartyName.cs index 569a1ace..90c3b578 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawEdiPartyName.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawEdiPartyName.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct EdiPartyName +internal partial struct EdiPartyName { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "EdiPartyName_get_name_assigner", ExactSpelling = true)] - public static unsafe extern DirectoryString* GetNameAssigner(EdiPartyName* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "EdiPartyName_get_name_assigner", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* GetNameAssigner(EdiPartyName* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "EdiPartyName_get_party_name", ExactSpelling = true)] - public static unsafe extern DirectoryString* GetPartyName(EdiPartyName* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "EdiPartyName_get_party_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DirectoryString* GetPartyName(EdiPartyName* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "EdiPartyName_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(EdiPartyName* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "EdiPartyName_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(EdiPartyName* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawEncapsulatedContentInfo.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawEncapsulatedContentInfo.cs index eaf88763..e34ea4b8 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawEncapsulatedContentInfo.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawEncapsulatedContentInfo.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct EncapsulatedContentInfo +internal partial struct EncapsulatedContentInfo { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "EncapsulatedContentInfo_content_type", ExactSpelling = true)] - public static unsafe extern IntPtr ContentType(EncapsulatedContentInfo* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "EncapsulatedContentInfo_content_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ContentType(EncapsulatedContentInfo* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "EncapsulatedContentInfo_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(EncapsulatedContentInfo* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "EncapsulatedContentInfo_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(EncapsulatedContentInfo* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawExtension.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawExtension.cs index 64ecea00..7df70402 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawExtension.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawExtension.cs @@ -1,35 +1,24 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Extension +internal partial struct Extension { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Extension_get_extn_id", ExactSpelling = true)] - public static unsafe extern IntPtr GetExtnId(Extension* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Extension_get_extn_id", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetExtnId(Extension* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Extension_get_critical", ExactSpelling = true)] + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Extension_get_critical", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] - public static unsafe extern bool GetCritical(Extension* self); + internal static unsafe extern bool GetCritical(Extension* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Extension_get_value", ExactSpelling = true)] - public static unsafe extern ExtensionView* GetValue(Extension* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Extension_get_value", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ExtensionView* GetValue(Extension* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Extension_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Extension* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Extension_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Extension* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionIterator.cs index efc1aa41..3158554a 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct ExtensionIterator +internal partial struct ExtensionIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionIterator_next", ExactSpelling = true)] - public static unsafe extern Extension* Next(ExtensionIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Extension* Next(ExtensionIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(ExtensionIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(ExtensionIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionView.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionView.cs index c41d8e92..aa77f425 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionView.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionView.cs @@ -1,55 +1,44 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct ExtensionView +internal partial struct ExtensionView { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_get_type", ExactSpelling = true)] - public static unsafe extern ExtensionViewType GetType(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ExtensionViewType GetType(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_to_authority_key_identifier", ExactSpelling = true)] - public static unsafe extern AuthorityKeyIdentifier* ToAuthorityKeyIdentifier(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_to_authority_key_identifier", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AuthorityKeyIdentifier* ToAuthorityKeyIdentifier(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_to_subject_key_identifier", ExactSpelling = true)] - public static unsafe extern VecU8* ToSubjectKeyIdentifier(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_to_subject_key_identifier", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* ToSubjectKeyIdentifier(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_to_key_usage", ExactSpelling = true)] - public static unsafe extern VecU8* ToKeyUsage(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_to_key_usage", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* ToKeyUsage(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_to_subject_alt_name", ExactSpelling = true)] - public static unsafe extern GeneralNameIterator* ToSubjectAltName(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_to_subject_alt_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern GeneralNameIterator* ToSubjectAltName(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_to_issuer_alt_name", ExactSpelling = true)] - public static unsafe extern GeneralNameIterator* ToIssuerAltName(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_to_issuer_alt_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern GeneralNameIterator* ToIssuerAltName(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_to_basic_constraints", ExactSpelling = true)] - public static unsafe extern BasicConstraints* ToBasicConstraints(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_to_basic_constraints", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern BasicConstraints* ToBasicConstraints(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_to_extended_key_usage", ExactSpelling = true)] - public static unsafe extern OidIterator* ToExtendedKeyUsage(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_to_extended_key_usage", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern OidIterator* ToExtendedKeyUsage(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_to_generic", ExactSpelling = true)] - public static unsafe extern VecU8* ToGeneric(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_to_generic", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* ToGeneric(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_to_crl_number", ExactSpelling = true)] - public static unsafe extern VecU8* ToCrlNumber(ExtensionView* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_to_crl_number", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* ToCrlNumber(ExtensionView* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ExtensionView_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(ExtensionView* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "ExtensionView_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(ExtensionView* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionViewType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionViewType.cs deleted file mode 100644 index fbc6eb48..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawExtensionViewType.cs +++ /dev/null @@ -1,25 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum ExtensionViewType -{ - AuthorityKeyIdentifier = 0, - SubjectKeyIdentifier = 1, - KeyUsage = 2, - SubjectAltName = 3, - IssuerAltName = 4, - BasicConstraints = 5, - ExtendedKeyUsage = 6, - Generic = 7, - CrlNumber = 8, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralName.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralName.cs index 13db10d7..d52a8d3c 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralName.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralName.cs @@ -1,52 +1,41 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct GeneralName +internal partial struct GeneralName { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_get_type", ExactSpelling = true)] - public static unsafe extern GeneralNameType GetType(GeneralName* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern GeneralNameType GetType(GeneralName* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_to_other_name", ExactSpelling = true)] - public static unsafe extern OtherName* ToOtherName(GeneralName* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_to_other_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern OtherName* ToOtherName(GeneralName* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_to_rfc822_name", ExactSpelling = true)] - public static unsafe extern IntPtr ToRfc822Name(GeneralName* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_to_rfc822_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToRfc822Name(GeneralName* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_to_dns_name", ExactSpelling = true)] - public static unsafe extern IntPtr ToDnsName(GeneralName* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_to_dns_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToDnsName(GeneralName* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_to_directory_name", ExactSpelling = true)] - public static unsafe extern AttributeTypeAndValueNestedIterator* ToDirectoryName(GeneralName* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_to_directory_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AttributeTypeAndValueNestedIterator* ToDirectoryName(GeneralName* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_to_edi_party_name", ExactSpelling = true)] - public static unsafe extern EdiPartyName* ToEdiPartyName(GeneralName* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_to_edi_party_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern EdiPartyName* ToEdiPartyName(GeneralName* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_to_uri", ExactSpelling = true)] - public static unsafe extern IntPtr ToUri(GeneralName* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_to_uri", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToUri(GeneralName* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_to_ip_address", ExactSpelling = true)] - public static unsafe extern VecU8* ToIpAddress(GeneralName* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_to_ip_address", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* ToIpAddress(GeneralName* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_to_registered_id", ExactSpelling = true)] - public static unsafe extern IntPtr ToRegisteredId(GeneralName* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_to_registered_id", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToRegisteredId(GeneralName* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralName_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(GeneralName* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralName_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(GeneralName* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralNameIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralNameIterator.cs index 87003a1a..39b23a27 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralNameIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralNameIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct GeneralNameIterator +internal partial struct GeneralNameIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralNameIterator_next", ExactSpelling = true)] - public static unsafe extern GeneralName* Next(GeneralNameIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralNameIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern GeneralName* Next(GeneralNameIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "GeneralNameIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(GeneralNameIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "GeneralNameIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(GeneralNameIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralNameType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralNameType.cs deleted file mode 100644 index 5192f4d8..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawGeneralNameType.cs +++ /dev/null @@ -1,24 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum GeneralNameType -{ - OtherName = 0, - Rfc822Name = 1, - DnsName = 2, - DirectoryName = 3, - EdiPartyName = 4, - Uri = 5, - IpAddress = 6, - RegisteredId = 7, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawGetCaResult.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawGetCaResult.cs deleted file mode 100644 index 36c899ee..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawGetCaResult.cs +++ /dev/null @@ -1,19 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum GetCaResult -{ - None = 0, - True = 1, - False = 2, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawHashAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawHashAlgorithm.cs deleted file mode 100644 index ba8e5adb..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawHashAlgorithm.cs +++ /dev/null @@ -1,25 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum HashAlgorithm -{ - MD5 = 0, - SHA1 = 1, - SHA2_224 = 2, - SHA2_256 = 3, - SHA2_384 = 4, - SHA2_512 = 5, - SHA3_384 = 6, - SHA3_512 = 7, - Unknown = 8, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawIssuerAndSerialNumber.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawIssuerAndSerialNumber.cs index 13904ab0..3c9a6f22 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawIssuerAndSerialNumber.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawIssuerAndSerialNumber.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct IssuerAndSerialNumber +internal partial struct IssuerAndSerialNumber { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "IssuerAndSerialNumber_get_issuer", ExactSpelling = true)] - public static unsafe extern IntPtr GetIssuer(IssuerAndSerialNumber* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "IssuerAndSerialNumber_get_issuer", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetIssuer(IssuerAndSerialNumber* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "IssuerAndSerialNumber_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IssuerAndSerialNumber* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "IssuerAndSerialNumber_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(IssuerAndSerialNumber* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawJwsAlg.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawJwsAlg.cs deleted file mode 100644 index f473326c..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawJwsAlg.cs +++ /dev/null @@ -1,79 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// `alg` header parameter values for JWS -/// -public enum JwsAlg -{ - /// - /// RSASSA-PKCS-v1_5 using SHA-256 - /// - RS256 = 0, - /// - /// RSASSA-PKCS-v1_5 using SHA-384 - /// - RS384 = 1, - /// - /// RSASSA-PKCS-v1_5 using SHA-512 - /// - RS512 = 2, - /// - /// HMAC using SHA-256 (unsupported) - /// - HS256 = 3, - /// - /// HMAC using SHA-384 (unsupported) - /// - HS384 = 4, - /// - /// HMAC using SHA-512 (unsupported) - /// - HS512 = 5, - /// - /// ECDSA using P-256 and SHA-256 - /// - ES256 = 6, - /// - /// ECDSA using P-384 and SHA-384 - /// - ES384 = 7, - /// - /// ECDSA using P-521 and SHA-512 - /// - ES512 = 8, - /// - /// RSASSA-PSS using SHA-256 and MGF1 with SHA-256 (unsupported) - /// - PS256 = 9, - /// - /// RSASSA-PSS using SHA-384 and MGF1 with SHA-384 (unsupported) - /// - PS384 = 10, - /// - /// RSASSA-PSS using SHA-512 and MGF1 with SHA-512 (unsupported) - /// - PS512 = 11, - /// - /// EdDSA using Ed25519/Ed448 - /// - EdDSA = 12, - /// - /// [DO NOT USE] EdDSA using Ed25519 - /// - /// - /// This value is used by some popular libraries (e.g. `golang-jwt) instead of `EdDSA` due to - /// mistake in the implementation. This value is deprecated and should not be used. - /// - ED25519 = 13, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtFfiResultBoxJwtSigBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawJwtFfiResultBoxJwtSigBoxPickyError.cs deleted file mode 100644 index d2717a26..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtFfiResultBoxJwtSigBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct JwtFfiResultBoxJwtSigBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal JwtSig* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe JwtSig* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_JwtSig_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawJwtFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 8208c331..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct JwtFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtSig.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawJwtSig.cs index fbcc0d77..9c841deb 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtSig.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawJwtSig.cs @@ -1,76 +1,38 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// Signed JSON Web Token object. -/// -/// -/// This is a JWS (JSON Web Signature) structure with JWT claims contained in a JSON payload. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct JwtSig +internal partial struct JwtSig { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSig_builder", ExactSpelling = true)] - public static unsafe extern JwtSigBuilder* Builder(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSig_builder", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern JwtSigBuilder* Builder(); - /// - /// Returns the content type. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSig_get_content_type", ExactSpelling = true)] - public static unsafe extern IntPtr GetContentType(JwtSig* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSig_get_content_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetContentType(JwtSig* handle, DiplomatWrite* writeable); - /// - /// Returns the key ID. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSig_get_kid", ExactSpelling = true)] - public static unsafe extern IntPtr GetKid(JwtSig* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSig_get_kid", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetKid(JwtSig* handle, DiplomatWrite* writeable); - /// - /// Returns the header as a JSON encoded payload. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSig_get_header", ExactSpelling = true)] - public static unsafe extern IntPtr GetHeader(JwtSig* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSig_get_header", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetHeader(JwtSig* handle, DiplomatWrite* writeable); - /// - /// Returns the claims as a JSON encoded payload. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSig_get_claims", ExactSpelling = true)] - public static unsafe extern IntPtr GetClaims(JwtSig* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSig_get_claims", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetClaims(JwtSig* handle, DiplomatWrite* writeable); - /// - /// Decode JWT and check signature using provided public key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSig_decode", ExactSpelling = true)] - public static unsafe extern IntPtr Decode(byte* compactRepr, nuint compactReprSz, PublicKey* publicKey, JwtValidator* validator); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSig_decode", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultJwtSigPickyError Decode(DiplomatSliceU8 compactRepr, PublicKey* publicKey, JwtValidator* validator); - /// - /// Decode JWT WITHOUT CHECKING THE SIGNATURE. Useful for token inspection. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSig_decode_unchecked", ExactSpelling = true)] - public static unsafe extern IntPtr DecodeUnchecked(byte* compactRepr, nuint compactReprSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSig_decode_unchecked", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultJwtSigPickyError DecodeUnchecked(DiplomatSliceU8 compactRepr); - /// - /// Encode using the given private key and returns the compact representation of this token. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSig_encode", ExactSpelling = true)] - public static unsafe extern IntPtr Encode(JwtSig* self, PrivateKey* key, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSig_encode", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError Encode(JwtSig* handle, PrivateKey* key, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSig_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(JwtSig* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSig_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(JwtSig* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtSigBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawJwtSigBuilder.cs index b89f97fc..e16bcea2 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtSigBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawJwtSigBuilder.cs @@ -1,103 +1,50 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct JwtSigBuilder +internal partial struct JwtSigBuilder { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_init", ExactSpelling = true)] - public static unsafe extern JwtSigBuilder* Init(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_init", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern JwtSigBuilder* Init(); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_set_algorithm", ExactSpelling = true)] - public static unsafe extern void SetAlgorithm(JwtSigBuilder* self, JwsAlg alg); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_set_algorithm", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetAlgorithm(JwtSigBuilder* handle, JwsAlg alg); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_set_content_type", ExactSpelling = true)] - public static unsafe extern void SetContentType(JwtSigBuilder* self, byte* cty, nuint ctySz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_set_content_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetContentType(JwtSigBuilder* handle, DiplomatSliceU8 cty); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_set_kid", ExactSpelling = true)] - public static unsafe extern void SetKid(JwtSigBuilder* self, byte* kid, nuint kidSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_set_kid", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetKid(JwtSigBuilder* handle, DiplomatSliceU8 kid); - /// - /// Adds a JSON object as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_add_additional_parameter_object", ExactSpelling = true)] - public static unsafe extern IntPtr AddAdditionalParameterObject(JwtSigBuilder* self, byte* name, nuint nameSz, byte* obj, nuint objSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_add_additional_parameter_object", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError AddAdditionalParameterObject(JwtSigBuilder* handle, DiplomatSliceU8 name, DiplomatSliceU8 obj); - /// - /// Adds a boolean as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_add_additional_parameter_bool", ExactSpelling = true)] - public static unsafe extern void AddAdditionalParameterBool(JwtSigBuilder* self, byte* name, nuint nameSz, [MarshalAs(UnmanagedType.U1)] bool value); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_add_additional_parameter_bool", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void AddAdditionalParameterBool(JwtSigBuilder* handle, DiplomatSliceU8 name, [MarshalAs(UnmanagedType.U1)] bool value); - /// - /// Adds a positive number as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_add_additional_parameter_pos_int", ExactSpelling = true)] - public static unsafe extern void AddAdditionalParameterPosInt(JwtSigBuilder* self, byte* name, nuint nameSz, ulong value); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_add_additional_parameter_pos_int", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void AddAdditionalParameterPosInt(JwtSigBuilder* handle, DiplomatSliceU8 name, ulong value); - /// - /// Adds a possibly negative number as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_add_additional_parameter_neg_int", ExactSpelling = true)] - public static unsafe extern void AddAdditionalParameterNegInt(JwtSigBuilder* self, byte* name, nuint nameSz, long value); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_add_additional_parameter_neg_int", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void AddAdditionalParameterNegInt(JwtSigBuilder* handle, DiplomatSliceU8 name, long value); - /// - /// Adds a float as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_add_additional_parameter_float", ExactSpelling = true)] - public static unsafe extern void AddAdditionalParameterFloat(JwtSigBuilder* self, byte* name, nuint nameSz, long value); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_add_additional_parameter_float", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void AddAdditionalParameterFloat(JwtSigBuilder* handle, DiplomatSliceU8 name, long value); - /// - /// Adds a float as additional header parameter. - /// - /// - /// This additional header parameter may be either public or private. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_add_additional_parameter_string", ExactSpelling = true)] - public static unsafe extern void AddAdditionalParameterString(JwtSigBuilder* self, byte* name, nuint nameSz, byte* value, nuint valueSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_add_additional_parameter_string", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void AddAdditionalParameterString(JwtSigBuilder* handle, DiplomatSliceU8 name, DiplomatSliceU8 value); - /// - /// Sets the given JSON payload. - /// - /// - /// Claims should be a valid JSON payload. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_set_claims", ExactSpelling = true)] - public static unsafe extern IntPtr SetClaims(JwtSigBuilder* self, byte* claims, nuint claimsSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_set_claims", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError SetClaims(JwtSigBuilder* handle, DiplomatSliceU8 claims); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_build", ExactSpelling = true)] - public static unsafe extern JwtSig* Build(JwtSigBuilder* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_build", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern JwtSig* Build(JwtSigBuilder* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtSigBuilder_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(JwtSigBuilder* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtSigBuilder_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(JwtSigBuilder* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtValidator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawJwtValidator.cs index 03fd2bf2..397e1db9 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawJwtValidator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawJwtValidator.cs @@ -1,43 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct JwtValidator +internal partial struct JwtValidator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Check signature and the registered exp and nbf claims. If a claim is missing token is rejected. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtValidator_strict", ExactSpelling = true)] - public static unsafe extern JwtValidator* Strict(long numericDate, ushort leeway); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtValidator_strict", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern JwtValidator* Strict(long numericDate, ushort leeway); - /// - /// Check signature and the registered exp and nbf claims. Token isn't rejected if a claim is missing. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtValidator_lenient", ExactSpelling = true)] - public static unsafe extern JwtValidator* Lenient(long numericDate, ushort leeway); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtValidator_lenient", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern JwtValidator* Lenient(long numericDate, ushort leeway); - /// - /// No check. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtValidator_no_check", ExactSpelling = true)] - public static unsafe extern JwtValidator* NoCheck(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtValidator_no_check", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern JwtValidator* NoCheck(); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "JwtValidator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(JwtValidator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "JwtValidator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(JwtValidator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawKeyFfiResultBoxPemBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawKeyFfiResultBoxPemBoxPickyError.cs deleted file mode 100644 index c5b4d63b..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawKeyFfiResultBoxPemBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct KeyFfiResultBoxPemBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pem* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pem* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pem_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawKeyFfiResultBoxPrivateKeyBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawKeyFfiResultBoxPrivateKeyBoxPickyError.cs deleted file mode 100644 index e0609cbb..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawKeyFfiResultBoxPrivateKeyBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct KeyFfiResultBoxPrivateKeyBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PrivateKey* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PrivateKey* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_PrivateKey_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawKeyFfiResultBoxPublicKeyBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawKeyFfiResultBoxPublicKeyBoxPickyError.cs deleted file mode 100644 index 0bd9ac3f..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawKeyFfiResultBoxPublicKeyBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct KeyFfiResultBoxPublicKeyBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PublicKey* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PublicKey* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_PublicKey_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawKeyKind.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawKeyKind.cs deleted file mode 100644 index e499fb37..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawKeyKind.cs +++ /dev/null @@ -1,35 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// Known key kinds -/// -public enum KeyKind -{ - /// - /// RSA (Rivest–Shamir–Adleman) - /// - Rsa = 0, - /// - /// Elliptic-curve - /// - Ec = 1, - /// - /// Edwards-curve - /// - Ed = 2, - /// - /// MLDSA (Module-Lattice-Based Digital Signature Algorithm) - /// - Mldsa = 3, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawMsCounterSign.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawMsCounterSign.cs index 24c26088..dabe6488 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawMsCounterSign.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawMsCounterSign.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct MsCounterSign +internal partial struct MsCounterSign { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MsCounterSign_get_oid", ExactSpelling = true)] - public static unsafe extern IntPtr GetOid(MsCounterSign* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "MsCounterSign_get_oid", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetOid(MsCounterSign* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MsCounterSign_get_signed_data", ExactSpelling = true)] - public static unsafe extern SignedData* GetSignedData(MsCounterSign* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "MsCounterSign_get_signed_data", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SignedData* GetSignedData(MsCounterSign* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MsCounterSign_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(MsCounterSign* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "MsCounterSign_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(MsCounterSign* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawMsCounterSignIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawMsCounterSignIterator.cs index a4bc9521..ecaf4f33 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawMsCounterSignIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawMsCounterSignIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct MsCounterSignIterator +internal partial struct MsCounterSignIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MsCounterSignIterator_next", ExactSpelling = true)] - public static unsafe extern MsCounterSign* Next(MsCounterSignIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "MsCounterSignIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern MsCounterSign* Next(MsCounterSignIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "MsCounterSignIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(MsCounterSignIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "MsCounterSignIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(MsCounterSignIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawNameAttr.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawNameAttr.cs deleted file mode 100644 index 261772b8..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawNameAttr.cs +++ /dev/null @@ -1,27 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum NameAttr -{ - CommonName = 0, - Surname = 1, - SerialNumber = 2, - CountryName = 3, - LocalityName = 4, - StateOrProvinceName = 5, - StreetName = 6, - OrganizationName = 7, - OrganizationalUnitName = 8, - GivenName = 9, - Phone = 10, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawOidIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawOidIterator.cs index 77dc0752..8b126c16 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawOidIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawOidIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct OidIterator +internal partial struct OidIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "OidIterator_next", ExactSpelling = true)] - public static unsafe extern IntPtr Next(OidIterator* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "OidIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError Next(OidIterator* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "OidIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(OidIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "OidIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(OidIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawOtherName.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawOtherName.cs index 0d3975b0..34942174 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawOtherName.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawOtherName.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct OtherName +internal partial struct OtherName { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "OtherName_get_type_id", ExactSpelling = true)] - public static unsafe extern IntPtr GetTypeId(OtherName* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "OtherName_get_type_id", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetTypeId(OtherName* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "OtherName_get_value", ExactSpelling = true)] - public static unsafe extern VecU8* GetValue(OtherName* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "OtherName_get_value", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetValue(OtherName* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "OtherName_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(OtherName* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "OtherName_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(OtherName* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPbes1Cipher.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPbes1Cipher.cs deleted file mode 100644 index d54ac89e..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPbes1Cipher.cs +++ /dev/null @@ -1,21 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// Pkcs12Pbe is deprecated and should not be used in general. -/// -public enum Pbes1Cipher -{ - ShaAnd40BitRc2Cbc = 0, - ShaAnd3Key3DesCbc = 1, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPbes2Cipher.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPbes2Cipher.cs deleted file mode 100644 index 9444173e..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPbes2Cipher.cs +++ /dev/null @@ -1,22 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// PBES2 cipher algorithm -/// -public enum Pbes2Cipher -{ - Aes128Cbc = 0, - Aes192Cbc = 1, - Aes256Cbc = 2, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPem.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPem.cs index 1d93f293..d5a8ba69 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPem.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPem.cs @@ -1,70 +1,35 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// PEM object. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct Pem +internal partial struct Pem { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Creates a PEM object with the given label and data. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pem_new", ExactSpelling = true)] - public static unsafe extern IntPtr New(byte* label, nuint labelSz, byte* data, nuint dataSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pem_new", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError New(DiplomatSliceU8 label, DiplomatSliceU8 data); - /// - /// Loads a PEM from the filesystem. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pem_load_from_file", ExactSpelling = true)] - public static unsafe extern IntPtr LoadFromFile(byte* path, nuint pathSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pem_load_from_file", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError LoadFromFile(DiplomatSliceU8 path); - /// - /// Saves this PEM object to the filesystem. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pem_save_to_file", ExactSpelling = true)] - public static unsafe extern IntPtr SaveToFile(Pem* self, byte* path, nuint pathSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pem_save_to_file", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError SaveToFile(Pem* handle, DiplomatSliceU8 path); - /// - /// Parses a PEM-encoded string representation. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pem_parse", ExactSpelling = true)] - public static unsafe extern IntPtr Parse(byte* input, nuint inputSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pem_parse", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError Parse(DiplomatSliceU8 input); - /// - /// Returns the length of the data contained by this PEM object. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pem_get_data_length", ExactSpelling = true)] - public static unsafe extern ulong GetDataLength(Pem* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pem_get_data_length", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ulong GetDataLength(Pem* handle); - /// - /// Returns the label of this PEM object. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pem_get_label", ExactSpelling = true)] - public static unsafe extern IntPtr GetLabel(Pem* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pem_get_label", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetLabel(Pem* handle, DiplomatWrite* writeable); - /// - /// Returns the string representation of this PEM object. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pem_to_repr", ExactSpelling = true)] - public static unsafe extern IntPtr ToRepr(Pem* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pem_to_repr", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToRepr(Pem* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pem_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Pem* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pem_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Pem* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPemFfiResultBoxPemBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPemFfiResultBoxPemBoxPickyError.cs deleted file mode 100644 index 62703455..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPemFfiResultBoxPemBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct PemFfiResultBoxPemBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pem* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pem* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pem_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPemFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPemFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 61b06f52..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPemFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct PemFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPfx.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPfx.cs index e400f890..1705877a 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPfx.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPfx.cs @@ -1,66 +1,33 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// A PKCS12 archive. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct Pfx +internal partial struct Pfx { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pfx_builder", ExactSpelling = true)] - public static unsafe extern PfxBuilder* Builder(Pkcs12CryptoContext* cryptoContext); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pfx_builder", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PfxBuilder* Builder(Pkcs12CryptoContext* cryptoContext); - /// - /// Parses a PKCS12 archive (PFX) from its DER representation. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pfx_from_der", ExactSpelling = true)] - public static unsafe extern IntPtr FromDer(byte* der, nuint derSz, Pkcs12CryptoContext* cryptoContext, Pkcs12ParsingParams* parsingParams); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pfx_from_der", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPfxPickyError FromDer(DiplomatSliceU8 der, Pkcs12CryptoContext* cryptoContext, Pkcs12ParsingParams* parsingParams); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pfx_hmac_algorithm", ExactSpelling = true)] - public static unsafe extern Pkcs12MacAlgorithmHmac* HmacAlgorithm(Pfx* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pfx_hmac_algorithm", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12MacAlgorithmHmac* HmacAlgorithm(Pfx* handle); - /// - /// Saves this PKCS12 archive to the filesystem. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pfx_save_to_file", ExactSpelling = true)] - public static unsafe extern IntPtr SaveToFile(Pfx* self, byte* path, nuint pathSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pfx_save_to_file", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError SaveToFile(Pfx* handle, DiplomatSliceU8 path); - /// - /// Returns a `SafeBagIterator` to inspect PFX data - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pfx_safe_bags", ExactSpelling = true)] - public static unsafe extern SafeBagIterator* SafeBags(Pfx* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pfx_safe_bags", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SafeBagIterator* SafeBags(Pfx* handle); - /// - /// Crawls all safe contents and safe bags and returns true if one of them is unknown. - /// - /// - /// "Unknown" in this context means that the content is encrypted and most - /// likely the provided password was wrong, or no password at all was provided. - /// It is required to relax parsing strictness by modifying parsing - /// parameters via the `Pkcs12ParsingParams` object in order to allow a - /// `Pfx` object with unknown items. This is useful for partial inspection. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pfx_has_unknown", ExactSpelling = true)] + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pfx_has_unknown", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] - public static unsafe extern bool HasUnknown(Pfx* self); + internal static unsafe extern bool HasUnknown(Pfx* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pfx_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Pfx* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pfx_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Pfx* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPfxBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPfxBuilder.cs index f1f5739d..8956357e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPfxBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPfxBuilder.cs @@ -1,46 +1,32 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// PFX (PKCS12 archive) builder. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct PfxBuilder +internal partial struct PfxBuilder { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PfxBuilder_init", ExactSpelling = true)] - public static unsafe extern PfxBuilder* Init(Pkcs12CryptoContext* cryptoContext); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PfxBuilder_init", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PfxBuilder* Init(Pkcs12CryptoContext* cryptoContext); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PfxBuilder_add_safe_bag_to_current_safe_contents", ExactSpelling = true)] - public static unsafe extern void AddSafeBagToCurrentSafeContents(PfxBuilder* self, SafeBag* safeBag); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PfxBuilder_add_safe_bag_to_current_safe_contents", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void AddSafeBagToCurrentSafeContents(PfxBuilder* handle, SafeBag* safeBag); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PfxBuilder_mark_safe_contents_as_ready", ExactSpelling = true)] - public static unsafe extern void MarkSafeContentsAsReady(PfxBuilder* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PfxBuilder_mark_safe_contents_as_ready", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void MarkSafeContentsAsReady(PfxBuilder* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PfxBuilder_mark_encrypted_safe_contents_as_ready", ExactSpelling = true)] - public static unsafe extern IntPtr MarkEncryptedSafeContentsAsReady(PfxBuilder* self, Pkcs12Encryption* encryption); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PfxBuilder_mark_encrypted_safe_contents_as_ready", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError MarkEncryptedSafeContentsAsReady(PfxBuilder* handle, Pkcs12Encryption* encryption); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PfxBuilder_set_hmac_algorithm", ExactSpelling = true)] - public static unsafe extern void SetHmacAlgorithm(PfxBuilder* self, Pkcs12MacAlgorithmHmac* macAlgorithm); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PfxBuilder_set_hmac_algorithm", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetHmacAlgorithm(PfxBuilder* handle, Pkcs12MacAlgorithmHmac* macAlgorithm); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PfxBuilder_build", ExactSpelling = true)] - public static unsafe extern IntPtr Build(PfxBuilder* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PfxBuilder_build", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPfxPickyError Build(PfxBuilder* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PfxBuilder_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(PfxBuilder* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PfxBuilder_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(PfxBuilder* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPickyError.cs index 91dd735c..5db69161 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPickyError.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPickyError.cs @@ -1,46 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// Stringified Picky error along with an error kind. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct PickyError +internal partial struct PickyError { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Returns the error as a string. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PickyError_to_display", ExactSpelling = true)] - public static unsafe extern void ToDisplay(PickyError* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PickyError_to_display", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void ToDisplay(PickyError* handle, DiplomatWrite* writeable); - /// - /// Prints the error string. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PickyError_print", ExactSpelling = true)] - public static unsafe extern void Print(PickyError* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PickyError_print", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Print(PickyError* handle); - /// - /// Returns the error kind. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PickyError_get_kind", ExactSpelling = true)] - public static unsafe extern PickyErrorKind GetKind(PickyError* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PickyError_get_kind", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PickyErrorKind GetKind(PickyError* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(PickyError* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PickyError_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(PickyError* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPickyErrorKind.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPickyErrorKind.cs deleted file mode 100644 index 8ac48bfc..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPickyErrorKind.cs +++ /dev/null @@ -1,39 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// Kind associated to a Picky Error -/// -public enum PickyErrorKind -{ - /// - /// Generic Picky error - /// - Generic = 0, - /// - /// Token or certificate not yet valid - /// - NotYetValid = 1, - /// - /// Token or certificate expired - /// - Expired = 2, - /// - /// Bad signature for token or certificate - /// - BadSignature = 3, - /// - /// MAC validation failed (wrong password or corrupted data) - /// - Pkcs12MacValidation = 4, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12Attribute.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12Attribute.cs index ad448779..dec4a5e9 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12Attribute.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12Attribute.cs @@ -1,48 +1,26 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// Attributes which can be used to store additional information about safe (e.g. friendly name, key ID). -/// [StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12Attribute +internal partial struct Pkcs12Attribute { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Creates a new `friendly name` attribute. This attribute is used to store a human-readable - /// name of the safe bag contents (e.g. certificate name). - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12Attribute_new_friendly_name", ExactSpelling = true)] - public static unsafe extern IntPtr NewFriendlyName(byte* name, nuint nameSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12Attribute_new_friendly_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPkcs12AttributePickyError NewFriendlyName(DiplomatSliceU8 name); - /// - /// Creates a new `local key id` attribute. This attribute is used to indicate relation between - /// private key and certificate (when set to same value on both objects). - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12Attribute_new_local_key_id", ExactSpelling = true)] - public static unsafe extern Pkcs12Attribute* NewLocalKeyId(byte* value, nuint valueSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12Attribute_new_local_key_id", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12Attribute* NewLocalKeyId(DiplomatSliceU8 value); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12Attribute_get_kind", ExactSpelling = true)] - public static unsafe extern Pkcs12AttributeKind GetKind(Pkcs12Attribute* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12Attribute_get_kind", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12AttributeKind GetKind(Pkcs12Attribute* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12Attribute_get_friendly_name", ExactSpelling = true)] - public static unsafe extern IntPtr GetFriendlyName(Pkcs12Attribute* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12Attribute_get_friendly_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetFriendlyName(Pkcs12Attribute* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12Attribute_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Pkcs12Attribute* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12Attribute_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Pkcs12Attribute* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12AttributeIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12AttributeIterator.cs index bd821d5f..f0774fd1 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12AttributeIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12AttributeIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12AttributeIterator +internal partial struct Pkcs12AttributeIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12AttributeIterator_next", ExactSpelling = true)] - public static unsafe extern Pkcs12Attribute* Next(Pkcs12AttributeIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12AttributeIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12Attribute* Next(Pkcs12AttributeIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12AttributeIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Pkcs12AttributeIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12AttributeIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Pkcs12AttributeIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12AttributeKind.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12AttributeKind.cs deleted file mode 100644 index 4a9e5fd2..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12AttributeKind.cs +++ /dev/null @@ -1,19 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum Pkcs12AttributeKind -{ - FriendlyName = 0, - LocalKeyId = 1, - Custom = 2, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12CryptoContext.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12CryptoContext.cs index ef75e030..ed51499f 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12CryptoContext.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12CryptoContext.cs @@ -1,34 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// Crypto context to use when building a PFX. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12CryptoContext +internal partial struct Pkcs12CryptoContext { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12CryptoContext_with_password", ExactSpelling = true)] - public static unsafe extern Pkcs12CryptoContext* WithPassword(byte* password, nuint passwordSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12CryptoContext_with_password", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPkcs12CryptoContextPickyError WithPassword(DiplomatSliceU8 password); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12CryptoContext_no_password", ExactSpelling = true)] - public static unsafe extern Pkcs12CryptoContext* NoPassword(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12CryptoContext_no_password", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPkcs12CryptoContextPickyError NoPassword(); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12CryptoContext_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Pkcs12CryptoContext* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12CryptoContext_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Pkcs12CryptoContext* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12Encryption.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12Encryption.cs index a82675b9..d3816586 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12Encryption.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12Encryption.cs @@ -1,37 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// Encryption mode to use for the PFX file -/// [StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12Encryption +internal partial struct Pkcs12Encryption { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12Encryption_default", ExactSpelling = true)] - public static unsafe extern Pkcs12Encryption* Default(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12Encryption_default", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12Encryption* Default(); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12Encryption_new_pbes2", ExactSpelling = true)] - public static unsafe extern Pkcs12Encryption* NewPbes2(Pbes2Cipher cipher, Pkcs12HashAlgorithm hmacKdf); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12Encryption_new_pbes2", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12Encryption* NewPbes2(Pbes2Cipher cipher, Pkcs12HashAlgorithm hmacKdf); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12Encryption_new_pbes1", ExactSpelling = true)] - public static unsafe extern Pkcs12Encryption* NewPbes1(Pbes1Cipher cipher); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12Encryption_new_pbes1", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12Encryption* NewPbes1(Pbes1Cipher cipher); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12Encryption_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Pkcs12Encryption* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12Encryption_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Pkcs12Encryption* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultBoxPfxBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultBoxPfxBoxPickyError.cs deleted file mode 100644 index ee6c7a49..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultBoxPfxBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12FfiResultBoxPfxBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pfx* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pfx* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pfx_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultBoxPkcs12AttributeBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultBoxPkcs12AttributeBoxPickyError.cs deleted file mode 100644 index ab6d6102..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultBoxPkcs12AttributeBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12FfiResultBoxPkcs12AttributeBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pkcs12Attribute* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pkcs12Attribute* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pkcs12Attribute_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultBoxSafeBagBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultBoxSafeBagBoxPickyError.cs deleted file mode 100644 index 218f90ce..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultBoxSafeBagBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12FfiResultBoxSafeBagBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal SafeBag* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe SafeBag* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_SafeBag_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultVoidBoxPickyError.cs deleted file mode 100644 index dec1ed3e..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12FfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12FfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12HashAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12HashAlgorithm.cs deleted file mode 100644 index 46968508..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12HashAlgorithm.cs +++ /dev/null @@ -1,24 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// Hashing algorithm used for MAC or KDF in PFX file -/// -public enum Pkcs12HashAlgorithm -{ - Sha1 = 0, - Sha224 = 1, - Sha256 = 2, - Sha384 = 3, - Sha512 = 4, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12MacAlgorithmHmac.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12MacAlgorithmHmac.cs index 1919a94e..78ba9d21 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12MacAlgorithmHmac.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12MacAlgorithmHmac.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12MacAlgorithmHmac +internal partial struct Pkcs12MacAlgorithmHmac { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12MacAlgorithmHmac_new_hmac", ExactSpelling = true)] - public static unsafe extern Pkcs12MacAlgorithmHmac* NewHmac(Pkcs12HashAlgorithm hashAlgorithm); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12MacAlgorithmHmac_new_hmac", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12MacAlgorithmHmac* NewHmac(Pkcs12HashAlgorithm hashAlgorithm); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12MacAlgorithmHmac_new_hmac_with_iterations", ExactSpelling = true)] - public static unsafe extern Pkcs12MacAlgorithmHmac* NewHmacWithIterations(Pkcs12HashAlgorithm hashAlgorithm, uint iterations); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12MacAlgorithmHmac_new_hmac_with_iterations", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12MacAlgorithmHmac* NewHmacWithIterations(Pkcs12HashAlgorithm hashAlgorithm, uint iterations); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12MacAlgorithmHmac_hash_algorithm", ExactSpelling = true)] - public static unsafe extern Pkcs12HashAlgorithm HashAlgorithm(Pkcs12MacAlgorithmHmac* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12MacAlgorithmHmac_hash_algorithm", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12HashAlgorithm HashAlgorithm(Pkcs12MacAlgorithmHmac* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12MacAlgorithmHmac_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Pkcs12MacAlgorithmHmac* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12MacAlgorithmHmac_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Pkcs12MacAlgorithmHmac* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12ParsingParams.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12ParsingParams.cs index 5cbceb56..d5163994 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12ParsingParams.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs12ParsingParams.cs @@ -1,52 +1,26 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs12ParsingParams +internal partial struct Pkcs12ParsingParams { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12ParsingParams_new", ExactSpelling = true)] - public static unsafe extern Pkcs12ParsingParams* New(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12ParsingParams_new", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12ParsingParams* New(); - /// - /// Continue parsing even if conversion to high level picky data structure fails (e.g. due to - /// unsupported private key or certificate kind) - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12ParsingParams_set_skip_soft_parsing_errors", ExactSpelling = true)] - public static unsafe extern void SetSkipSoftParsingErrors(Pkcs12ParsingParams* self, [MarshalAs(UnmanagedType.U1)] bool value); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12ParsingParams_set_skip_soft_parsing_errors", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetSkipSoftParsingErrors(Pkcs12ParsingParams* handle, [MarshalAs(UnmanagedType.U1)] bool value); - /// - /// Continue parsing even if decryption fails and keep data in encrypted form - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12ParsingParams_set_skip_decryption_errors", ExactSpelling = true)] - public static unsafe extern void SetSkipDecryptionErrors(Pkcs12ParsingParams* self, [MarshalAs(UnmanagedType.U1)] bool value); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12ParsingParams_set_skip_decryption_errors", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetSkipDecryptionErrors(Pkcs12ParsingParams* handle, [MarshalAs(UnmanagedType.U1)] bool value); - /// - /// Continue parsing even if MAC validation fails. - /// - /// - /// This is useful for parsing available unencrypted data from - /// password-protected PFX files. Also could be useful if PFX integrity has been intentionally - /// violated for testing purposes. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12ParsingParams_set_skip_mac_validation", ExactSpelling = true)] - public static unsafe extern void SetSkipMacValidation(Pkcs12ParsingParams* self, [MarshalAs(UnmanagedType.U1)] bool value); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12ParsingParams_set_skip_mac_validation", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetSkipMacValidation(Pkcs12ParsingParams* handle, [MarshalAs(UnmanagedType.U1)] bool value); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs12ParsingParams_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Pkcs12ParsingParams* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs12ParsingParams_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Pkcs12ParsingParams* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7.cs index 4018f093..63a168b3 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7.cs @@ -1,49 +1,38 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs7 +internal partial struct Pkcs7 { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs7_from_der", ExactSpelling = true)] - public static unsafe extern IntPtr FromDer(byte* data, nuint dataSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs7_from_der", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPkcs7PickyError FromDer(DiplomatSliceU8 data); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs7_from_pem", ExactSpelling = true)] - public static unsafe extern IntPtr FromPem(Pem* pem); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs7_from_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPkcs7PickyError FromPem(Pem* pem); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs7_to_der", ExactSpelling = true)] - public static unsafe extern IntPtr ToDer(Pkcs7* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs7_to_der", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVecU8PickyError ToDer(Pkcs7* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs7_to_pem", ExactSpelling = true)] - public static unsafe extern IntPtr ToPem(Pkcs7* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs7_to_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError ToPem(Pkcs7* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs7_digest_algorithms", ExactSpelling = true)] - public static unsafe extern AlgorithmIdentifierIterator* DigestAlgorithms(Pkcs7* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs7_digest_algorithms", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AlgorithmIdentifierIterator* DigestAlgorithms(Pkcs7* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs7_signer_infos", ExactSpelling = true)] - public static unsafe extern SignerInfoIterator* SignerInfos(Pkcs7* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs7_signer_infos", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SignerInfoIterator* SignerInfos(Pkcs7* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs7_encapsulated_content_info", ExactSpelling = true)] - public static unsafe extern EncapsulatedContentInfo* EncapsulatedContentInfo(Pkcs7* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs7_encapsulated_content_info", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern EncapsulatedContentInfo* EncapsulatedContentInfo(Pkcs7* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs7_decode_certificates", ExactSpelling = true)] - public static unsafe extern CertIterator* DecodeCertificates(Pkcs7* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs7_decode_certificates", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern CertIterator* DecodeCertificates(Pkcs7* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Pkcs7_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Pkcs7* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Pkcs7_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Pkcs7* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7FfiResultBoxPemBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7FfiResultBoxPemBoxPickyError.cs deleted file mode 100644 index a42c5ac4..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7FfiResultBoxPemBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs7FfiResultBoxPemBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pem* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pem* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pem_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7FfiResultBoxPkcs7BoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7FfiResultBoxPkcs7BoxPickyError.cs deleted file mode 100644 index 9c168e13..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7FfiResultBoxPkcs7BoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs7FfiResultBoxPkcs7BoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pkcs7* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pkcs7* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pkcs7_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7FfiResultBoxVecU8BoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7FfiResultBoxVecU8BoxPickyError.cs deleted file mode 100644 index 1bef0352..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPkcs7FfiResultBoxVecU8BoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct Pkcs7FfiResultBoxVecU8BoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal VecU8* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe VecU8* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_VecU8_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPrivateKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPrivateKey.cs index 676a4297..2054563e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPrivateKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPrivateKey.cs @@ -1,92 +1,44 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct PrivateKey +internal partial struct PrivateKey { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Extracts private key from PEM object. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_from_pem", ExactSpelling = true)] - public static unsafe extern IntPtr FromPem(Pem* pem); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_from_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPrivateKeyPickyError FromPem(Pem* pem); - /// - /// Reads a private key from its PKCS8 storage. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_from_pkcs8", ExactSpelling = true)] - public static unsafe extern IntPtr FromPkcs8(byte* pkcs8, nuint pkcs8Sz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_from_pkcs8", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPrivateKeyPickyError FromPkcs8(DiplomatSliceU8 pkcs8); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_from_pem_str", ExactSpelling = true)] - public static unsafe extern IntPtr FromPemStr(byte* pem, nuint pemSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_from_pem_str", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPrivateKeyPickyError FromPemStr(DiplomatSliceU8 pem); - /// - /// Generates a new RSA private key. - /// - /// - /// This is slow in debug builds. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_generate_rsa", ExactSpelling = true)] - public static unsafe extern IntPtr GenerateRsa(nuint bits); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_generate_rsa", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPrivateKeyPickyError GenerateRsa(nuint bits); - /// - /// Generates a new EC private key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_generate_ec", ExactSpelling = true)] - public static unsafe extern IntPtr GenerateEc(EcCurve curve); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_generate_ec", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPrivateKeyPickyError GenerateEc(EcCurve curve); - /// - /// Generates new ed key pair with specified supported algorithm. - /// - /// - /// `write_public_key` specifies whether to include public key in the private key file. - /// Note that OpenSSL does not support ed keys with public key included. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_generate_ed", ExactSpelling = true)] - public static unsafe extern IntPtr GenerateEd(EdAlgorithm algorithm, [MarshalAs(UnmanagedType.U1)] bool writePublicKey); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_generate_ed", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPrivateKeyPickyError GenerateEd(EdAlgorithm algorithm, [MarshalAs(UnmanagedType.U1)] bool writePublicKey); - /// - /// Exports the private key into a PEM object - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_to_pem", ExactSpelling = true)] - public static unsafe extern IntPtr ToPem(PrivateKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_to_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError ToPem(PrivateKey* handle); - /// - /// Exports the private key into a PEM object using the PKCS 1 format - /// - /// - /// This format can only be used for RSA keys. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_to_pkcs1_pem", ExactSpelling = true)] - public static unsafe extern IntPtr ToPkcs1Pem(PrivateKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_to_pkcs1_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError ToPkcs1Pem(PrivateKey* handle); - /// - /// Extracts the public part of this private key - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_to_public_key", ExactSpelling = true)] - public static unsafe extern IntPtr ToPublicKey(PrivateKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_to_public_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPublicKeyPickyError ToPublicKey(PrivateKey* handle); - /// - /// Retrieves the key kind for this private key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_get_kind", ExactSpelling = true)] - public static unsafe extern KeyKind GetKind(PrivateKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_get_kind", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern KeyKind GetKind(PrivateKey* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PrivateKey_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(PrivateKey* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PrivateKey_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(PrivateKey* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPublicKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPublicKey.cs index 275af8a8..e473321f 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPublicKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPublicKey.cs @@ -1,64 +1,32 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct PublicKey +internal partial struct PublicKey { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Extracts public key from PEM object. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PublicKey_from_pem", ExactSpelling = true)] - public static unsafe extern IntPtr FromPem(Pem* pem); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PublicKey_from_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPublicKeyPickyError FromPem(Pem* pem); - /// - /// Reads a public key from its DER encoding (i.e.: SubjectPublicKeyInfo structure). - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PublicKey_from_der", ExactSpelling = true)] - public static unsafe extern IntPtr FromDer(byte* der, nuint derSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PublicKey_from_der", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPublicKeyPickyError FromDer(DiplomatSliceU8 der); - /// - /// Reads a RSA public key from its DER encoding (i.e.: PKCS1). - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PublicKey_from_pkcs1", ExactSpelling = true)] - public static unsafe extern IntPtr FromPkcs1(byte* der, nuint derSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PublicKey_from_pkcs1", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPublicKeyPickyError FromPkcs1(DiplomatSliceU8 der); - /// - /// Exports the public key into a PEM object. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PublicKey_to_pem", ExactSpelling = true)] - public static unsafe extern IntPtr ToPem(PublicKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PublicKey_to_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError ToPem(PublicKey* handle); - /// - /// Exports the public key into a PEM object using the PKCS 1 format - /// - /// - /// This format can only be used for RSA keys. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PublicKey_to_pkcs1_pem", ExactSpelling = true)] - public static unsafe extern IntPtr ToPkcs1Pem(PublicKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PublicKey_to_pkcs1_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError ToPkcs1Pem(PublicKey* handle); - /// - /// Retrieves the key kind for this public key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PublicKey_get_kind", ExactSpelling = true)] - public static unsafe extern KeyKind GetKind(PublicKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PublicKey_get_kind", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern KeyKind GetKind(PublicKey* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PublicKey_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(PublicKey* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PublicKey_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(PublicKey* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyArgon2Flavour.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyArgon2Flavour.cs deleted file mode 100644 index 36c48f89..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyArgon2Flavour.cs +++ /dev/null @@ -1,22 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// Argon2 key derivation function flavour. -/// -public enum PuttyArgon2Flavour -{ - Argon2d = 0, - Argon2i = 1, - Argon2id = 2, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyArgon2Params.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyArgon2Params.cs index da3bbb39..9cb4f6df 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyArgon2Params.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyArgon2Params.cs @@ -1,43 +1,29 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// Argon2 key derivation function parameters. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct PuttyArgon2Params +internal partial struct PuttyArgon2Params { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyArgon2Params_get_flavor", ExactSpelling = true)] - public static unsafe extern PuttyArgon2Flavour GetFlavor(PuttyArgon2Params* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyArgon2Params_get_flavor", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PuttyArgon2Flavour GetFlavor(PuttyArgon2Params* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyArgon2Params_get_memory", ExactSpelling = true)] - public static unsafe extern uint GetMemory(PuttyArgon2Params* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyArgon2Params_get_memory", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern uint GetMemory(PuttyArgon2Params* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyArgon2Params_get_passes", ExactSpelling = true)] - public static unsafe extern uint GetPasses(PuttyArgon2Params* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyArgon2Params_get_passes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern uint GetPasses(PuttyArgon2Params* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyArgon2Params_get_parallelism", ExactSpelling = true)] - public static unsafe extern uint GetParallelism(PuttyArgon2Params* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyArgon2Params_get_parallelism", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern uint GetParallelism(PuttyArgon2Params* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyArgon2Params_get_salt", ExactSpelling = true)] - public static unsafe extern VecU8* GetSalt(PuttyArgon2Params* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyArgon2Params_get_salt", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetSalt(PuttyArgon2Params* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyArgon2Params_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(PuttyArgon2Params* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyArgon2Params_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(PuttyArgon2Params* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPrivateKeyBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPrivateKeyBoxPickyError.cs deleted file mode 100644 index e05b8085..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPrivateKeyBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyFfiResultBoxPrivateKeyBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PrivateKey* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PrivateKey* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_PrivateKey_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPublicKeyBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPublicKeyBoxPickyError.cs deleted file mode 100644 index e4ee227b..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPublicKeyBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyFfiResultBoxPublicKeyBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PublicKey* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PublicKey* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_PublicKey_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPuttyPpkBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPuttyPpkBoxPickyError.cs deleted file mode 100644 index e544cc68..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPuttyPpkBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyFfiResultBoxPuttyPpkBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PuttyPpk* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PuttyPpk* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_PuttyPpk_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPuttyPublicKeyBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPuttyPublicKeyBoxPickyError.cs deleted file mode 100644 index 95007e7c..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxPuttyPublicKeyBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyFfiResultBoxPuttyPublicKeyBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PuttyPublicKey* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PuttyPublicKey* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_PuttyPublicKey_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxSshPrivateKeyBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxSshPrivateKeyBoxPickyError.cs deleted file mode 100644 index 31c68f14..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxSshPrivateKeyBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyFfiResultBoxSshPrivateKeyBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal SshPrivateKey* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe SshPrivateKey* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_SshPrivateKey_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxSshPublicKeyBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxSshPublicKeyBoxPickyError.cs deleted file mode 100644 index 3547545c..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultBoxSshPublicKeyBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyFfiResultBoxSshPublicKeyBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal SshPublicKey* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe SshPublicKey* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_SshPublicKey_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 55ae0bf1..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpk.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpk.cs index 8a9379b5..9dad04de 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpk.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpk.cs @@ -1,163 +1,75 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// PuTTY Private Key (PPK) format. -/// -/// -/// ### Functionality -/// - Generation of new keys. -/// - Conversion to/from OpenSSH format. -/// - Encoding/decoding to/from string. -/// - Version upgrade/downgrade. -///
-/// ### Usage notes -/// - Ppk structure is immutable. All operations that modify the key return a new instance. -/// - When input file is encrypted, all operations with the private key will be unavailable until -/// ppk is decrypted via `PuttyPpk::decrypt`. -/// - Newly generated keys are always unencrypted. They should be encrypted via `PuttyPpk::encrypt` -/// when required -///
[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyPpk +internal partial struct PuttyPpk { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - /// - /// Generate a new RSA key file. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_generate_rsa", ExactSpelling = true)] - public static unsafe extern IntPtr GenerateRsa(nuint bits, byte* comment, nuint commentSz); - - /// - /// Generate a new EC key file. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_generate_ec", ExactSpelling = true)] - public static unsafe extern IntPtr GenerateEc(EcCurve curve, byte* comment, nuint commentSz); - - /// - /// Generate a new Ed25519 key file. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_generate_ed25519", ExactSpelling = true)] - public static unsafe extern IntPtr GenerateEd25519(byte* comment, nuint commentSz); - - /// - /// Encode PPK key file to a string. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_to_repr", ExactSpelling = true)] - public static unsafe extern IntPtr ToRepr(PuttyPpk* self, DiplomatWriteable* writeable); - - /// - /// Parse a PPK key file from a string. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_parse", ExactSpelling = true)] - public static unsafe extern IntPtr Parse(byte* ppk, nuint ppkSz); - - /// - /// Convert an OpenSSH private key to a PPK key file. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_from_openssh", ExactSpelling = true)] - public static unsafe extern IntPtr FromOpenssh(SshPrivateKey* key); - - /// - /// Convert a PPK key file to an OpenSSH private key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_to_openssh", ExactSpelling = true)] - public static unsafe extern IntPtr ToOpenssh(PuttyPpk* self, byte* passphrase, nuint passphraseSz); - - /// - /// Wrap a private key - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_from_key", ExactSpelling = true)] - public static unsafe extern IntPtr FromKey(PrivateKey* privateKey); - - /// - /// Get the public key from the PPK key file. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_get_public_key", ExactSpelling = true)] - public static unsafe extern IntPtr GetPublicKey(PuttyPpk* self); - - /// - /// Get the private key from the PPK key file. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_get_private_key", ExactSpelling = true)] - public static unsafe extern IntPtr GetPrivateKey(PuttyPpk* self); - - /// - /// Extract the public key file (PuTTY format) from the PPK key file. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_extract_putty_public_key", ExactSpelling = true)] - public static unsafe extern IntPtr ExtractPuttyPublicKey(PuttyPpk* self); - - /// - /// Get the PPK key file version. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_get_version", ExactSpelling = true)] - public static unsafe extern PuttyPpkVersion GetVersion(PuttyPpk* self); - - /// - /// Get the PPK key file algorithm. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_get_algorithm", ExactSpelling = true)] - public static unsafe extern PuttyPpkKeyAlgorithm GetAlgorithm(PuttyPpk* self); - - /// - /// Get the PPK key file comment. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_get_comment", ExactSpelling = true)] - public static unsafe extern IntPtr GetComment(PuttyPpk* self, DiplomatWriteable* writeable); - - /// - /// Returns a new PPK key instance with a different comment. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_with_comment", ExactSpelling = true)] - public static unsafe extern IntPtr WithComment(PuttyPpk* self, byte* comment, nuint commentSz); - - /// - /// Convert the PPK key file to a different version. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_to_version", ExactSpelling = true)] - public static unsafe extern IntPtr ToVersion(PuttyPpk* self, PuttyPpkVersion version); - - /// - /// Check if the PPK key file is encrypted. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_is_encrypted", ExactSpelling = true)] + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_generate_rsa", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError GenerateRsa(nuint bits, DiplomatSliceU8 comment); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_generate_ec", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError GenerateEc(EcCurve curve, DiplomatSliceU8 comment); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_generate_ed25519", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError GenerateEd25519(DiplomatSliceU8 comment); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_to_repr", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToRepr(PuttyPpk* handle, DiplomatWrite* writeable); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_parse", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError Parse(DiplomatSliceU8 ppk); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_from_openssh", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError FromOpenssh(SshPrivateKey* key); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_to_openssh", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshPrivateKeyPickyError ToOpenssh(PuttyPpk* handle, DiplomatSliceU8 passphrase); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_from_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError FromKey(PrivateKey* privateKey); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_get_public_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPublicKeyPickyError GetPublicKey(PuttyPpk* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_get_private_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPrivateKeyPickyError GetPrivateKey(PuttyPpk* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_extract_putty_public_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPublicKeyPickyError ExtractPuttyPublicKey(PuttyPpk* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_get_version", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PuttyPpkVersion GetVersion(PuttyPpk* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_get_algorithm", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PuttyPpkKeyAlgorithm GetAlgorithm(PuttyPpk* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_get_comment", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetComment(PuttyPpk* handle, DiplomatWrite* writeable); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_with_comment", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError WithComment(PuttyPpk* handle, DiplomatSliceU8 comment); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_to_version", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError ToVersion(PuttyPpk* handle, PuttyPpkVersion version); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_is_encrypted", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] - public static unsafe extern bool IsEncrypted(PuttyPpk* self); - - /// - /// Get the Argon2 key derivation function parameters (if the key is encrypted). - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_argon2_params", ExactSpelling = true)] - public static unsafe extern PuttyArgon2Params* Argon2Params(PuttyPpk* self); - - /// - /// Decrypt the PPK key file and return as a new instance. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_decrypt", ExactSpelling = true)] - public static unsafe extern IntPtr Decrypt(PuttyPpk* self, byte* passphrase, nuint passphraseSz); - - /// - /// Encrypt the PPK key file and return as a new instance. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_encrypt", ExactSpelling = true)] - public static unsafe extern IntPtr Encrypt(PuttyPpk* self, byte* passphrase, nuint passphraseSz, PuttyPpkEncryptionConfig* config); - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpk_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(PuttyPpk* self); -} + internal static unsafe extern bool IsEncrypted(PuttyPpk* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_argon2_params", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PuttyArgon2Params* Argon2Params(PuttyPpk* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_decrypt", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError Decrypt(PuttyPpk* handle, DiplomatSliceU8 passphrase); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_encrypt", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPpkPickyError Encrypt(PuttyPpk* handle, DiplomatSliceU8 passphrase, PuttyPpkEncryptionConfig* config); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpk_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(PuttyPpk* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkEncryptionConfig.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkEncryptionConfig.cs index ad02ae6c..70533155 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkEncryptionConfig.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkEncryptionConfig.cs @@ -1,39 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// PPK encryption configuration. -/// -/// -/// Could be either constructed via `PuttyPpkEncryptionConfig::default()` or `PuttyPpkEncryptionConfig::builder()` -///
-/// Defaults are the same as in PuTTY. -///
[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyPpkEncryptionConfig +internal partial struct PuttyPpkEncryptionConfig { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfig_default", ExactSpelling = true)] - public static unsafe extern PuttyPpkEncryptionConfig* Default(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfig_default", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PuttyPpkEncryptionConfig* Default(); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfig_builder", ExactSpelling = true)] - public static unsafe extern PuttyPpkEncryptionConfigBuilder* Builder(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfig_builder", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PuttyPpkEncryptionConfigBuilder* Builder(); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfig_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(PuttyPpkEncryptionConfig* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfig_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(PuttyPpkEncryptionConfig* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkEncryptionConfigBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkEncryptionConfigBuilder.cs index cd6db54f..7ea07cc1 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkEncryptionConfigBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkEncryptionConfigBuilder.cs @@ -1,49 +1,32 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// PPK encryption configuration builder. -/// -/// -/// Could be constructed via `PuttyPpkEncryptionConfig::builder()`. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct PuttyPpkEncryptionConfigBuilder +internal partial struct PuttyPpkEncryptionConfigBuilder { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfigBuilder_get_argon2_flavour", ExactSpelling = true)] - public static unsafe extern void GetArgon2Flavour(PuttyPpkEncryptionConfigBuilder* self, PuttyArgon2Flavour argon2Flavour); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfigBuilder_get_argon2_flavour", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void GetArgon2Flavour(PuttyPpkEncryptionConfigBuilder* handle, PuttyArgon2Flavour argon2Flavour); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfigBuilder_set_argon2_memory", ExactSpelling = true)] - public static unsafe extern void SetArgon2Memory(PuttyPpkEncryptionConfigBuilder* self, uint argon2Memory); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfigBuilder_set_argon2_memory", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetArgon2Memory(PuttyPpkEncryptionConfigBuilder* handle, uint argon2Memory); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfigBuilder_set_argon2_passes", ExactSpelling = true)] - public static unsafe extern void SetArgon2Passes(PuttyPpkEncryptionConfigBuilder* self, uint argon2Passes); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfigBuilder_set_argon2_passes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetArgon2Passes(PuttyPpkEncryptionConfigBuilder* handle, uint argon2Passes); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfigBuilder_set_argon2_parallelism", ExactSpelling = true)] - public static unsafe extern void SetArgon2Parallelism(PuttyPpkEncryptionConfigBuilder* self, uint argon2Parallelism); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfigBuilder_set_argon2_parallelism", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetArgon2Parallelism(PuttyPpkEncryptionConfigBuilder* handle, uint argon2Parallelism); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfigBuilder_set_argon2_salt_size", ExactSpelling = true)] - public static unsafe extern void SetArgon2SaltSize(PuttyPpkEncryptionConfigBuilder* self, uint argon2SaltSize); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfigBuilder_set_argon2_salt_size", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetArgon2SaltSize(PuttyPpkEncryptionConfigBuilder* handle, uint argon2SaltSize); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfigBuilder_build", ExactSpelling = true)] - public static unsafe extern PuttyPpkEncryptionConfig* Build(PuttyPpkEncryptionConfigBuilder* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfigBuilder_build", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PuttyPpkEncryptionConfig* Build(PuttyPpkEncryptionConfigBuilder* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPpkEncryptionConfigBuilder_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(PuttyPpkEncryptionConfigBuilder* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPpkEncryptionConfigBuilder_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(PuttyPpkEncryptionConfigBuilder* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkKeyAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkKeyAlgorithm.cs deleted file mode 100644 index 0724d89b..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkKeyAlgorithm.cs +++ /dev/null @@ -1,26 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// PuTTY Private Key (PPK) algorithm. -/// -public enum PuttyPpkKeyAlgorithm -{ - Rsa = 0, - Dss = 1, - EcdsaSha2Nistp256 = 2, - EcdsaSha2Nistp384 = 3, - EcdsaSha2Nistp521 = 4, - Ed25519 = 5, - Ed448 = 6, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkVersion.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkVersion.cs deleted file mode 100644 index f5a5db41..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPpkVersion.cs +++ /dev/null @@ -1,21 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// PuTTY Private Key (PPK) version. -/// -public enum PuttyPpkVersion -{ - V2 = 0, - V3 = 1, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPublicKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPublicKey.cs index 1b546002..0a54fe0e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPublicKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawPuttyPublicKey.cs @@ -1,74 +1,32 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// PuTTY public key format. -/// -/// -/// ### Functionality: -/// - Conversion to/from OpenSSH format. -/// - Encoding/decoding to/from string. -/// - Could be extracted from `PuttyPpk` private keys. -///
-/// ### Notes -/// - Although top-level containeris similar to PEM, it is not compatible with it because of -/// additional comment field after the header. -///
[StructLayout(LayoutKind.Sequential)] -public partial struct PuttyPublicKey +internal partial struct PuttyPublicKey { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Converts an OpenSSH public key to a PuTTY public key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPublicKey_from_openssh", ExactSpelling = true)] - public static unsafe extern IntPtr FromOpenssh(SshPublicKey* key); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPublicKey_from_openssh", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPuttyPublicKeyPickyError FromOpenssh(SshPublicKey* key); - /// - /// Converts the key to an OpenSSH public key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPublicKey_to_openssh", ExactSpelling = true)] - public static unsafe extern IntPtr ToOpenssh(PuttyPublicKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPublicKey_to_openssh", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshPublicKeyPickyError ToOpenssh(PuttyPublicKey* handle); - /// - /// Get the comment of the public key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPublicKey_get_comment", ExactSpelling = true)] - public static unsafe extern IntPtr GetComment(PuttyPublicKey* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPublicKey_get_comment", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetComment(PuttyPublicKey* handle, DiplomatWrite* writeable); - /// - /// Returns a new public key instance with a different comment. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPublicKey_with_comment", ExactSpelling = true)] - public static unsafe extern PuttyPublicKey* WithComment(PuttyPublicKey* self, byte* comment, nuint commentSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPublicKey_with_comment", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PuttyPublicKey* WithComment(PuttyPublicKey* handle, DiplomatSliceU8 comment); - /// - /// Converts the public key to a string (PuTTY format). - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPublicKey_to_repr", ExactSpelling = true)] - public static unsafe extern IntPtr ToRepr(PuttyPublicKey* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPublicKey_to_repr", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToRepr(PuttyPublicKey* handle, DiplomatWrite* writeable); - /// - /// Parses and returns the inner key as standard picky key type. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPublicKey_to_inner_key", ExactSpelling = true)] - public static unsafe extern IntPtr ToInnerKey(PuttyPublicKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPublicKey_to_inner_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPublicKeyPickyError ToInnerKey(PuttyPublicKey* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "PuttyPublicKey_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(PuttyPublicKey* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "PuttyPublicKey_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(PuttyPublicKey* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawRevocationInfoChoice.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawRevocationInfoChoice.cs index 51f89f35..3ebf6271 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawRevocationInfoChoice.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawRevocationInfoChoice.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct RevocationInfoChoice +internal partial struct RevocationInfoChoice { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevocationInfoChoice_get_crl", ExactSpelling = true)] - public static unsafe extern CertificateList* GetCrl(RevocationInfoChoice* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevocationInfoChoice_get_crl", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern CertificateList* GetCrl(RevocationInfoChoice* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevocationInfoChoice_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(RevocationInfoChoice* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevocationInfoChoice_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(RevocationInfoChoice* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawRevocationInfoChoiceIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawRevocationInfoChoiceIterator.cs index e27c13cd..f51ab21a 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawRevocationInfoChoiceIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawRevocationInfoChoiceIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct RevocationInfoChoiceIterator +internal partial struct RevocationInfoChoiceIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevocationInfoChoiceIterator_next", ExactSpelling = true)] - public static unsafe extern RevocationInfoChoice* Next(RevocationInfoChoiceIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevocationInfoChoiceIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern RevocationInfoChoice* Next(RevocationInfoChoiceIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevocationInfoChoiceIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(RevocationInfoChoiceIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevocationInfoChoiceIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(RevocationInfoChoiceIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawRevokedCertificate.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawRevokedCertificate.cs index 315eefb2..cb0ecab7 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawRevokedCertificate.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawRevokedCertificate.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct RevokedCertificate +internal partial struct RevokedCertificate { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevokedCertificate_get_user_certificate", ExactSpelling = true)] - public static unsafe extern VecU8* GetUserCertificate(RevokedCertificate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevokedCertificate_get_user_certificate", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetUserCertificate(RevokedCertificate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevokedCertificate_get_revocation_date", ExactSpelling = true)] - public static unsafe extern Time* GetRevocationDate(RevokedCertificate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevokedCertificate_get_revocation_date", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Time* GetRevocationDate(RevokedCertificate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevokedCertificate_get_extensions", ExactSpelling = true)] - public static unsafe extern ExtensionIterator* GetExtensions(RevokedCertificate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevokedCertificate_get_extensions", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ExtensionIterator* GetExtensions(RevokedCertificate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevokedCertificate_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(RevokedCertificate* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevokedCertificate_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(RevokedCertificate* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawRevokedCertificateIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawRevokedCertificateIterator.cs index 9b04e4de..db75020e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawRevokedCertificateIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawRevokedCertificateIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct RevokedCertificateIterator +internal partial struct RevokedCertificateIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevokedCertificateIterator_next", ExactSpelling = true)] - public static unsafe extern RevokedCertificate* Next(RevokedCertificateIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevokedCertificateIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern RevokedCertificate* Next(RevokedCertificateIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RevokedCertificateIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(RevokedCertificateIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RevokedCertificateIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(RevokedCertificateIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawRsString.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawRsString.cs index f5cca2e0..649b3194 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawRsString.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawRsString.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct RsString +internal partial struct RsString { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RsString_from_string", ExactSpelling = true)] - public static unsafe extern RsString* FromString(byte* s, nuint sSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RsString_from_string", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern RsString* FromString(DiplomatSliceU8 s); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RsString_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(RsString* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RsString_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(RsString* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawRsassaPssParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawRsassaPssParameters.cs index 4c84453c..25be7919 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawRsassaPssParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawRsassaPssParameters.cs @@ -1,25 +1,14 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct RsassaPssParameters +internal partial struct RsassaPssParameters { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "RsassaPssParameters_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(RsassaPssParameters* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "RsassaPssParameters_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(RsassaPssParameters* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBag.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBag.cs index 4a852c07..62b60d71 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBag.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBag.cs @@ -1,72 +1,46 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// PFX safe bag, the polymorphic container for all the data in a PKCS12 archive. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct SafeBag +internal partial struct SafeBag { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Creates new safe bag holding a private key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_new_key", ExactSpelling = true)] - public static unsafe extern IntPtr NewKey(PrivateKey* key); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_new_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSafeBagPickyError NewKey(PrivateKey* key); - /// - /// Creates new safe bag holding an encrypted private key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_new_encrypted_key", ExactSpelling = true)] - public static unsafe extern IntPtr NewEncryptedKey(PrivateKey* key, Pkcs12Encryption* encryption, Pkcs12CryptoContext* cryptoContext); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_new_encrypted_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSafeBagPickyError NewEncryptedKey(PrivateKey* key, Pkcs12Encryption* encryption, Pkcs12CryptoContext* cryptoContext); - /// - /// Creates new safe bag holding a certificate. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_new_certificate", ExactSpelling = true)] - public static unsafe extern IntPtr NewCertificate(Cert* cert); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_new_certificate", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSafeBagPickyError NewCertificate(Cert* cert); - /// - /// Adds a PKCS12 attribute to this safe bag. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_add_attribute", ExactSpelling = true)] - public static unsafe extern void AddAttribute(SafeBag* self, Pkcs12Attribute* attribute); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_add_attribute", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void AddAttribute(SafeBag* handle, Pkcs12Attribute* attribute); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_get_kind", ExactSpelling = true)] - public static unsafe extern SafeBagKind GetKind(SafeBag* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_get_kind", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SafeBagKind GetKind(SafeBag* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_get_private_key", ExactSpelling = true)] - public static unsafe extern PrivateKey* GetPrivateKey(SafeBag* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_get_private_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PrivateKey* GetPrivateKey(SafeBag* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_get_certificate", ExactSpelling = true)] - public static unsafe extern Cert* GetCertificate(SafeBag* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_get_certificate", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Cert* GetCertificate(SafeBag* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_contains_friendly_name", ExactSpelling = true)] + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_contains_friendly_name", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] - public static unsafe extern bool ContainsFriendlyName(SafeBag* self, byte* value, nuint valueSz); + internal static unsafe extern bool ContainsFriendlyName(SafeBag* handle, DiplomatSliceU8 value); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_contains_local_key_id", ExactSpelling = true)] + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_contains_local_key_id", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] - public static unsafe extern bool ContainsLocalKeyId(SafeBag* self, byte* value, nuint valueSz); + internal static unsafe extern bool ContainsLocalKeyId(SafeBag* handle, DiplomatSliceU8 value); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_attributes", ExactSpelling = true)] - public static unsafe extern Pkcs12AttributeIterator* Attributes(SafeBag* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_attributes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Pkcs12AttributeIterator* Attributes(SafeBag* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBag_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SafeBag* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBag_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SafeBag* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBagIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBagIterator.cs index 4b250162..3522805f 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBagIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBagIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SafeBagIterator +internal partial struct SafeBagIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBagIterator_next", ExactSpelling = true)] - public static unsafe extern SafeBag* Next(SafeBagIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBagIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SafeBag* Next(SafeBagIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SafeBagIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SafeBagIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SafeBagIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SafeBagIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBagKind.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBagKind.cs deleted file mode 100644 index 36307886..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSafeBagKind.cs +++ /dev/null @@ -1,20 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum SafeBagKind -{ - PrivateKey = 0, - Certificate = 1, - Secret = 2, - Unknown = 3, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawShaVariant.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawShaVariant.cs deleted file mode 100644 index 0bb87a9d..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawShaVariant.cs +++ /dev/null @@ -1,30 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum ShaVariant -{ - MD5 = 0, - SHA1 = 1, - SHA2_224 = 2, - SHA2_256 = 3, - SHA2_384 = 4, - SHA2_512 = 5, - SHA2_512_224 = 6, - SHA2_512_256 = 7, - SHA3_224 = 8, - SHA3_256 = 9, - SHA3_384 = 10, - SHA3_512 = 11, - SHAKE128 = 12, - SHAKE256 = 13, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureAlgorithm.cs index 1e7d3c0c..0ea727d0 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureAlgorithm.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureAlgorithm.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SignatureAlgorithm +internal partial struct SignatureAlgorithm { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignatureAlgorithm_new_rsa_pkcs_1v15", ExactSpelling = true)] - public static unsafe extern IntPtr NewRsaPkcs1v15(HashAlgorithm hashAlgorithm); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignatureAlgorithm_new_rsa_pkcs_1v15", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSignatureAlgorithmPickyError NewRsaPkcs1v15(HashAlgorithm hashAlgorithm); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignatureAlgorithm_new_ecdsa", ExactSpelling = true)] - public static unsafe extern IntPtr NewEcdsa(HashAlgorithm hashAlgorithm); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignatureAlgorithm_new_ecdsa", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSignatureAlgorithmPickyError NewEcdsa(HashAlgorithm hashAlgorithm); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignatureAlgorithm_verify", ExactSpelling = true)] - public static unsafe extern IntPtr Verify(SignatureAlgorithm* self, PublicKey* publicKey, byte* msg, nuint msgSz, byte* signature, nuint signatureSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignatureAlgorithm_verify", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError Verify(SignatureAlgorithm* handle, PublicKey* publicKey, DiplomatSliceU8 msg, DiplomatSliceU8 signature); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignatureAlgorithm_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SignatureAlgorithm* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignatureAlgorithm_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SignatureAlgorithm* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureFfiResultBoxSignatureAlgorithmBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureFfiResultBoxSignatureAlgorithmBoxPickyError.cs deleted file mode 100644 index 065acc16..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureFfiResultBoxSignatureAlgorithmBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct SignatureFfiResultBoxSignatureAlgorithmBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal SignatureAlgorithm* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe SignatureAlgorithm* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_SignatureAlgorithm_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 14ce1594..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSignatureFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct SignatureFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSignedData.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSignedData.cs index 96127fa8..e12437d1 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSignedData.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSignedData.cs @@ -1,43 +1,32 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SignedData +internal partial struct SignedData { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignedData_get_version", ExactSpelling = true)] - public static unsafe extern CmsVersion GetVersion(SignedData* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignedData_get_version", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern CmsVersion GetVersion(SignedData* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignedData_get_digest_algorithms", ExactSpelling = true)] - public static unsafe extern AlgorithmIdentifierIterator* GetDigestAlgorithms(SignedData* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignedData_get_digest_algorithms", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AlgorithmIdentifierIterator* GetDigestAlgorithms(SignedData* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignedData_get_content_info", ExactSpelling = true)] - public static unsafe extern EncapsulatedContentInfo* GetContentInfo(SignedData* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignedData_get_content_info", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern EncapsulatedContentInfo* GetContentInfo(SignedData* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignedData_get_crls", ExactSpelling = true)] - public static unsafe extern RevocationInfoChoiceIterator* GetCrls(SignedData* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignedData_get_crls", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern RevocationInfoChoiceIterator* GetCrls(SignedData* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignedData_get_certificates", ExactSpelling = true)] - public static unsafe extern CertificateChoicesIterator* GetCertificates(SignedData* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignedData_get_certificates", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern CertificateChoicesIterator* GetCertificates(SignedData* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignedData_get_signers_infos", ExactSpelling = true)] - public static unsafe extern SignerInfoIterator* GetSignersInfos(SignedData* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignedData_get_signers_infos", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SignerInfoIterator* GetSignersInfos(SignedData* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignedData_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SignedData* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignedData_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SignedData* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSignerInfo.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSignerInfo.cs index 7e2c5861..8246b2b0 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSignerInfo.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSignerInfo.cs @@ -1,46 +1,35 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SignerInfo +internal partial struct SignerInfo { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfo_get_version", ExactSpelling = true)] - public static unsafe extern CmsVersion GetVersion(SignerInfo* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfo_get_version", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern CmsVersion GetVersion(SignerInfo* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfo_get_sid", ExactSpelling = true)] - public static unsafe extern SingerIdentifier* GetSid(SignerInfo* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfo_get_sid", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SingerIdentifier* GetSid(SignerInfo* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfo_get_digest_algorithm", ExactSpelling = true)] - public static unsafe extern AlgorithmIdentifier* GetDigestAlgorithm(SignerInfo* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfo_get_digest_algorithm", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AlgorithmIdentifier* GetDigestAlgorithm(SignerInfo* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfo_get_signature_algorithm", ExactSpelling = true)] - public static unsafe extern AlgorithmIdentifier* GetSignatureAlgorithm(SignerInfo* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfo_get_signature_algorithm", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AlgorithmIdentifier* GetSignatureAlgorithm(SignerInfo* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfo_get_signature", ExactSpelling = true)] - public static unsafe extern VecU8* GetSignature(SignerInfo* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfo_get_signature", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetSignature(SignerInfo* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfo_get_unsigned_attributes", ExactSpelling = true)] - public static unsafe extern UnsignedAttributeIterator* GetUnsignedAttributes(SignerInfo* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfo_get_unsigned_attributes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UnsignedAttributeIterator* GetUnsignedAttributes(SignerInfo* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfo_get_signed_attributes", ExactSpelling = true)] - public static unsafe extern AttributeIterator* GetSignedAttributes(SignerInfo* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfo_get_signed_attributes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AttributeIterator* GetSignedAttributes(SignerInfo* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfo_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SignerInfo* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfo_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SignerInfo* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSignerInfoIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSignerInfoIterator.cs index 8f456820..4f28e751 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSignerInfoIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSignerInfoIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SignerInfoIterator +internal partial struct SignerInfoIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfoIterator_next", ExactSpelling = true)] - public static unsafe extern SignerInfo* Next(SignerInfoIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfoIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SignerInfo* Next(SignerInfoIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SignerInfoIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SignerInfoIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SignerInfoIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SignerInfoIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSingerIdentifier.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSingerIdentifier.cs index a5b75d9f..4ac2fa98 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSingerIdentifier.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSingerIdentifier.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SingerIdentifier +internal partial struct SingerIdentifier { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SingerIdentifier_get_issure_and_serial_number", ExactSpelling = true)] - public static unsafe extern IssuerAndSerialNumber* GetIssureAndSerialNumber(SingerIdentifier* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SingerIdentifier_get_issure_and_serial_number", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern IssuerAndSerialNumber* GetIssureAndSerialNumber(SingerIdentifier* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SingerIdentifier_get_subject_key_identifier", ExactSpelling = true)] - public static unsafe extern VecU8* GetSubjectKeyIdentifier(SingerIdentifier* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SingerIdentifier_get_subject_key_identifier", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetSubjectKeyIdentifier(SingerIdentifier* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SingerIdentifier_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SingerIdentifier* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SingerIdentifier_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SingerIdentifier* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcLink.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcLink.cs index 76ad6342..f39309f3 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcLink.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcLink.cs @@ -1,37 +1,26 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SpcLink +internal partial struct SpcLink { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcLink_get_type", ExactSpelling = true)] - public static unsafe extern SpcLinkType GetType(SpcLink* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcLink_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SpcLinkType GetType(SpcLink* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcLink_get_url", ExactSpelling = true)] - public static unsafe extern VecU8* GetUrl(SpcLink* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcLink_get_url", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetUrl(SpcLink* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcLink_get_moniker", ExactSpelling = true)] - public static unsafe extern SpcSerializedObject* GetMoniker(SpcLink* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcLink_get_moniker", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SpcSerializedObject* GetMoniker(SpcLink* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcLink_get_file", ExactSpelling = true)] - public static unsafe extern SpcString* GetFile(SpcLink* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcLink_get_file", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SpcString* GetFile(SpcLink* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcLink_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SpcLink* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcLink_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SpcLink* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcLinkType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcLinkType.cs deleted file mode 100644 index 9816d43d..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcLinkType.cs +++ /dev/null @@ -1,19 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum SpcLinkType -{ - Url = 0, - Moniker = 1, - File = 2, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSerializedObject.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSerializedObject.cs index 5047beca..013050c5 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSerializedObject.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSerializedObject.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SpcSerializedObject +internal partial struct SpcSerializedObject { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcSerializedObject_get_class_id", ExactSpelling = true)] - public static unsafe extern VecU8* GetClassId(SpcSerializedObject* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcSerializedObject_get_class_id", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetClassId(SpcSerializedObject* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcSerializedObject_get_object_id", ExactSpelling = true)] - public static unsafe extern VecU8* GetObjectId(SpcSerializedObject* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcSerializedObject_get_object_id", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetObjectId(SpcSerializedObject* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcSerializedObject_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SpcSerializedObject* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcSerializedObject_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SpcSerializedObject* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSpOpusInfo.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSpOpusInfo.cs index 13ae20f1..b1a04764 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSpOpusInfo.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSpOpusInfo.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SpcSpOpusInfo +internal partial struct SpcSpOpusInfo { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcSpOpusInfo_get_program_name", ExactSpelling = true)] - public static unsafe extern SpcString* GetProgramName(SpcSpOpusInfo* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcSpOpusInfo_get_program_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SpcString* GetProgramName(SpcSpOpusInfo* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcSpOpusInfo_get_more_info", ExactSpelling = true)] - public static unsafe extern SpcLink* GetMoreInfo(SpcSpOpusInfo* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcSpOpusInfo_get_more_info", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SpcLink* GetMoreInfo(SpcSpOpusInfo* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcSpOpusInfo_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SpcSpOpusInfo* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcSpOpusInfo_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SpcSpOpusInfo* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSpOpusInfoIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSpOpusInfoIterator.cs index addb4807..b2817d9e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSpOpusInfoIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcSpOpusInfoIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SpcSpOpusInfoIterator +internal partial struct SpcSpOpusInfoIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcSpOpusInfoIterator_next", ExactSpelling = true)] - public static unsafe extern SpcSpOpusInfo* Next(SpcSpOpusInfoIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcSpOpusInfoIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SpcSpOpusInfo* Next(SpcSpOpusInfoIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcSpOpusInfoIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SpcSpOpusInfoIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcSpOpusInfoIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SpcSpOpusInfoIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcString.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcString.cs index d1786df8..91393332 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcString.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcString.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SpcString +internal partial struct SpcString { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcString_get_type", ExactSpelling = true)] - public static unsafe extern SpcStringType GetType(SpcString* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcString_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SpcStringType GetType(SpcString* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcString_get_as_string", ExactSpelling = true)] - public static unsafe extern IntPtr GetAsString(SpcString* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcString_get_as_string", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetAsString(SpcString* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcString_get_as_bytes", ExactSpelling = true)] - public static unsafe extern VecU8* GetAsBytes(SpcString* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcString_get_as_bytes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* GetAsBytes(SpcString* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SpcString_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SpcString* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SpcString_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SpcString* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcStringType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSpcStringType.cs deleted file mode 100644 index 9b7d71ce..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSpcStringType.cs +++ /dev/null @@ -1,18 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum SpcStringType -{ - Unicode = 0, - Ancii = 1, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshCert.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshCert.cs index c022990d..462b7425 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshCert.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSshCert.cs @@ -1,64 +1,47 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct SshCert +internal partial struct SshCert { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_builder", ExactSpelling = true)] - public static unsafe extern SshCertBuilder* Builder(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_builder", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SshCertBuilder* Builder(); - /// - /// Parses string representation of a SSH Certificate. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_parse", ExactSpelling = true)] - public static unsafe extern IntPtr Parse(byte* repr, nuint reprSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_parse", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshCertPickyError Parse(DiplomatSliceU8 repr); - /// - /// Returns the SSH Certificate string representation. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_to_repr", ExactSpelling = true)] - public static unsafe extern IntPtr ToRepr(SshCert* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_to_repr", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToRepr(SshCert* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_get_public_key", ExactSpelling = true)] - public static unsafe extern SshPublicKey* GetPublicKey(SshCert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_get_public_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SshPublicKey* GetPublicKey(SshCert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_get_ssh_key_type", ExactSpelling = true)] - public static unsafe extern SshCertKeyType GetSshKeyType(SshCert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_get_ssh_key_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SshCertKeyType GetSshKeyType(SshCert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_get_cert_type", ExactSpelling = true)] - public static unsafe extern SshCertType GetCertType(SshCert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_get_cert_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SshCertType GetCertType(SshCert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_get_valid_after", ExactSpelling = true)] - public static unsafe extern ulong GetValidAfter(SshCert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_get_valid_after", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ulong GetValidAfter(SshCert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_get_valid_before", ExactSpelling = true)] - public static unsafe extern ulong GetValidBefore(SshCert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_get_valid_before", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ulong GetValidBefore(SshCert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_get_signature_key", ExactSpelling = true)] - public static unsafe extern SshPublicKey* GetSignatureKey(SshCert* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_get_signature_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SshPublicKey* GetSignatureKey(SshCert* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_get_key_id", ExactSpelling = true)] - public static unsafe extern IntPtr GetKeyId(SshCert* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_get_key_id", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetKeyId(SshCert* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_get_comment", ExactSpelling = true)] - public static unsafe extern IntPtr GetComment(SshCert* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_get_comment", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetComment(SshCert* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCert_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SshCert* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCert_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SshCert* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertBuilder.cs index 6660fadc..150d7077 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertBuilder.cs @@ -1,94 +1,50 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// SSH Certificate Builder. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct SshCertBuilder +internal partial struct SshCertBuilder { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_init", ExactSpelling = true)] - public static unsafe extern SshCertBuilder* Init(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_init", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SshCertBuilder* Init(); - /// - /// Required - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_cert_key_type", ExactSpelling = true)] - public static unsafe extern void SetCertKeyType(SshCertBuilder* self, SshCertKeyType keyType); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_cert_key_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetCertKeyType(SshCertBuilder* handle, SshCertKeyType keyType); - /// - /// Required - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_key", ExactSpelling = true)] - public static unsafe extern void SetKey(SshCertBuilder* self, SshPublicKey* key); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetKey(SshCertBuilder* handle, SshPublicKey* key); - /// - /// Optional (set to 0 by default) - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_serial", ExactSpelling = true)] - public static unsafe extern void SetSerial(SshCertBuilder* self, ulong serial); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_serial", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetSerial(SshCertBuilder* handle, ulong serial); - /// - /// Required - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_cert_type", ExactSpelling = true)] - public static unsafe extern void SetCertType(SshCertBuilder* self, SshCertType certType); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_cert_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetCertType(SshCertBuilder* handle, SshCertType certType); - /// - /// Optional - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_key_id", ExactSpelling = true)] - public static unsafe extern void SetKeyId(SshCertBuilder* self, byte* keyId, nuint keyIdSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_key_id", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetKeyId(SshCertBuilder* handle, DiplomatSliceU8 keyId); - /// - /// Required - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_valid_before", ExactSpelling = true)] - public static unsafe extern void SetValidBefore(SshCertBuilder* self, ulong validBefore); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_valid_before", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetValidBefore(SshCertBuilder* handle, ulong validBefore); - /// - /// Required - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_valid_after", ExactSpelling = true)] - public static unsafe extern void SetValidAfter(SshCertBuilder* self, ulong validAfter); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_valid_after", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetValidAfter(SshCertBuilder* handle, ulong validAfter); - /// - /// Required - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_signature_key", ExactSpelling = true)] - public static unsafe extern void SetSignatureKey(SshCertBuilder* self, SshPrivateKey* signatureKey); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_signature_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetSignatureKey(SshCertBuilder* handle, SshPrivateKey* signatureKey); - /// - /// Optional. RsaPkcs1v15 with SHA256 is used by default. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_signature_algo", ExactSpelling = true)] - public static unsafe extern void SetSignatureAlgo(SshCertBuilder* self, SignatureAlgorithm* signatureAlgo); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_signature_algo", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetSignatureAlgo(SshCertBuilder* handle, SignatureAlgorithm* signatureAlgo); - /// - /// Optional - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_set_comment", ExactSpelling = true)] - public static unsafe extern void SetComment(SshCertBuilder* self, byte* comment, nuint commentSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_set_comment", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void SetComment(SshCertBuilder* handle, DiplomatSliceU8 comment); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_build", ExactSpelling = true)] - public static unsafe extern IntPtr Build(SshCertBuilder* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_build", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshCertPickyError Build(SshCertBuilder* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshCertBuilder_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SshCertBuilder* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshCertBuilder_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SshCertBuilder* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertKeyType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertKeyType.cs deleted file mode 100644 index f3d0905e..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertKeyType.cs +++ /dev/null @@ -1,29 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// SSH key type. -/// -public enum SshCertKeyType -{ - SshRsaV01 = 0, - SshDssV01 = 1, - RsaSha2_256V01 = 2, - RsaSha2_512v01 = 3, - EcdsaSha2Nistp256V01 = 4, - EcdsaSha2Nistp384V01 = 5, - EcdsaSha2Nistp521V01 = 6, - SshEd25519V01 = 7, - SkSshSha2Nistp256V01 = 8, - SkSshEd25519V01 = 9, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertType.cs deleted file mode 100644 index 7b4fe34a..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshCertType.cs +++ /dev/null @@ -1,21 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// SSH certificate type. -/// -public enum SshCertType -{ - Client = 0, - Host = 1, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxPemBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxPemBoxPickyError.cs deleted file mode 100644 index 1d015026..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxPemBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct SshFfiResultBoxPemBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pem* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pem* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pem_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxSshCertBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxSshCertBoxPickyError.cs deleted file mode 100644 index 2c8701d7..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxSshCertBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct SshFfiResultBoxSshCertBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal SshCert* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe SshCert* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_SshCert_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxSshPrivateKeyBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxSshPrivateKeyBoxPickyError.cs deleted file mode 100644 index 55219000..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxSshPrivateKeyBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct SshFfiResultBoxSshPrivateKeyBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal SshPrivateKey* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe SshPrivateKey* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_SshPrivateKey_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxSshPublicKeyBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxSshPublicKeyBoxPickyError.cs deleted file mode 100644 index 4382e58c..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxSshPublicKeyBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct SshFfiResultBoxSshPublicKeyBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal SshPublicKey* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe SshPublicKey* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_SshPublicKey_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxVecU8BoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxVecU8BoxPickyError.cs deleted file mode 100644 index 4d70da33..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultBoxVecU8BoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct SshFfiResultBoxVecU8BoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal VecU8* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe VecU8* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_VecU8_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 1ca59957..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct SshFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshPrivateKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshPrivateKey.cs index 3d93ce38..d5ef91e2 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshPrivateKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSshPrivateKey.cs @@ -1,102 +1,47 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// SSH Private Key. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct SshPrivateKey +internal partial struct SshPrivateKey { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - /// - /// Generates a new SSH RSA Private Key. - /// - /// - /// No passphrase is set if `passphrase` is empty. - ///
- /// No comment is set if `comment` is empty. - ///
- /// This is slow in debug builds. - ///
- [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_generate_rsa", ExactSpelling = true)] - public static unsafe extern IntPtr GenerateRsa(nuint bits, byte* passphrase, nuint passphraseSz, byte* comment, nuint commentSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_generate_rsa", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshPrivateKeyPickyError GenerateRsa(nuint bits, DiplomatSliceU8 passphrase, DiplomatSliceU8 comment); - /// - /// Generates a new SSH EC Private Key. - /// - /// - /// No passphrase is set if `passphrase` is empty. - ///
- /// No comment is set if `comment` is empty. - ///
- [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_generate_ec", ExactSpelling = true)] - public static unsafe extern IntPtr GenerateEc(EcCurve curve, byte* passphrase, nuint passphraseSz, byte* comment, nuint commentSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_generate_ec", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshPrivateKeyPickyError GenerateEc(EcCurve curve, DiplomatSliceU8 passphrase, DiplomatSliceU8 comment); - /// - /// Generates a new SSH ed25519 Private Key. - /// - /// - /// No passphrase is set if `passphrase` is empty. - ///
- /// No comment is set if `comment` is empty. - ///
- [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_generate_ed25519", ExactSpelling = true)] - public static unsafe extern IntPtr GenerateEd25519(byte* passphrase, nuint passphraseSz, byte* comment, nuint commentSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_generate_ed25519", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshPrivateKeyPickyError GenerateEd25519(DiplomatSliceU8 passphrase, DiplomatSliceU8 comment); - /// - /// Extracts SSH Private Key from PEM object. - /// - /// - /// No passphrase is set if `passphrase` is empty. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_from_pem", ExactSpelling = true)] - public static unsafe extern IntPtr FromPem(Pem* pem, byte* passphrase, nuint passphraseSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_from_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshPrivateKeyPickyError FromPem(Pem* pem, DiplomatSliceU8 passphrase); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_from_key", ExactSpelling = true)] - public static unsafe extern IntPtr FromKey(PrivateKey* key); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_from_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshPrivateKeyPickyError FromKey(PrivateKey* key); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_inner_key", ExactSpelling = true)] - public static unsafe extern PrivateKey* InnerKey(SshPrivateKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_inner_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern PrivateKey* InnerKey(SshPrivateKey* handle); - /// - /// Exports the SSH Private Key into a PEM object - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_to_pem", ExactSpelling = true)] - public static unsafe extern IntPtr ToPem(SshPrivateKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_to_pem", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultPemPickyError ToPem(SshPrivateKey* handle); - /// - /// Returns the SSH Private Key string representation. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_to_repr", ExactSpelling = true)] - public static unsafe extern IntPtr ToRepr(SshPrivateKey* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_to_repr", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToRepr(SshPrivateKey* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_get_cipher_name", ExactSpelling = true)] - public static unsafe extern IntPtr GetCipherName(SshPrivateKey* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_get_cipher_name", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetCipherName(SshPrivateKey* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_get_comment", ExactSpelling = true)] - public static unsafe extern IntPtr GetComment(SshPrivateKey* self, DiplomatWriteable* writeable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_get_comment", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetComment(SshPrivateKey* handle, DiplomatWrite* writeable); - /// - /// Extracts the public part of this private key - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_to_public_key", ExactSpelling = true)] - public static unsafe extern SshPublicKey* ToPublicKey(SshPrivateKey* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_to_public_key", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SshPublicKey* ToPublicKey(SshPrivateKey* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPrivateKey_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SshPrivateKey* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPrivateKey_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SshPrivateKey* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawSshPublicKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawSshPublicKey.cs index 64d32b73..b0c650b0 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawSshPublicKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawSshPublicKey.cs @@ -1,57 +1,32 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// SSH Public Key. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct SshPublicKey +internal partial struct SshPublicKey { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - /// - /// Parses string representation of a SSH Public Key. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPublicKey_parse", ExactSpelling = true)] - public static unsafe extern IntPtr Parse(byte* repr, nuint reprSz); - - /// - /// Returns the SSH Public Key string representation. - /// - /// - /// It is generally represented as: - /// "(algorithm) (der for the key) (comment)" - /// where (comment) is usually an email address. - /// - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPublicKey_to_repr", ExactSpelling = true)] - public static unsafe extern IntPtr ToRepr(SshPublicKey* self, DiplomatWriteable* writeable); - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPublicKey_get_comment", ExactSpelling = true)] - public static unsafe extern IntPtr GetComment(SshPublicKey* self, DiplomatWriteable* writeable); - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPublicKey_fingerprint_md5", ExactSpelling = true)] - public static unsafe extern IntPtr FingerprintMd5(SshPublicKey* self); - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPublicKey_fingerprint_sha1", ExactSpelling = true)] - public static unsafe extern IntPtr FingerprintSha1(SshPublicKey* self); - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPublicKey_fingerprint_sha256", ExactSpelling = true)] - public static unsafe extern IntPtr FingerprintSha256(SshPublicKey* self); - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "SshPublicKey_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(SshPublicKey* self); -} + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPublicKey_parse", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultSshPublicKeyPickyError Parse(DiplomatSliceU8 repr); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPublicKey_to_repr", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError ToRepr(SshPublicKey* handle, DiplomatWrite* writeable); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPublicKey_get_comment", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetComment(SshPublicKey* handle, DiplomatWrite* writeable); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPublicKey_fingerprint_md5", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVecU8PickyError FingerprintMd5(SshPublicKey* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPublicKey_fingerprint_sha1", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVecU8PickyError FingerprintSha1(SshPublicKey* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPublicKey_fingerprint_sha256", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVecU8PickyError FingerprintSha256(SshPublicKey* handle); + + [DllImport(DiplomatNativeLib.Name, EntryPoint = "SshPublicKey_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(SshPublicKey* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawStringIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawStringIterator.cs index 8edab8af..7bfdb968 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawStringIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawStringIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct StringIterator +internal partial struct StringIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "StringIterator_next", ExactSpelling = true)] - public static unsafe extern IntPtr Next(StringIterator* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "StringIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError Next(StringIterator* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "StringIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(StringIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "StringIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(StringIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawStringNestedIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawStringNestedIterator.cs index c8399a8a..b577b55b 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawStringNestedIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawStringNestedIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct StringNestedIterator +internal partial struct StringNestedIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "StringNestedIterator_next", ExactSpelling = true)] - public static unsafe extern StringIterator* Next(StringNestedIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "StringNestedIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern StringIterator* Next(StringNestedIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "StringNestedIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(StringNestedIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "StringNestedIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(StringNestedIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawTbsCertList.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawTbsCertList.cs index 3326e8e3..e10f9ec6 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawTbsCertList.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawTbsCertList.cs @@ -1,46 +1,35 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct TbsCertList +internal partial struct TbsCertList { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TbsCertList_get_version", ExactSpelling = true)] - public static unsafe extern Version GetVersion(TbsCertList* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "TbsCertList_get_version", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Version GetVersion(TbsCertList* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TbsCertList_get_signature_algorithm", ExactSpelling = true)] - public static unsafe extern AlgorithmIdentifier* GetSignatureAlgorithm(TbsCertList* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "TbsCertList_get_signature_algorithm", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern AlgorithmIdentifier* GetSignatureAlgorithm(TbsCertList* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TbsCertList_get_issuer", ExactSpelling = true)] - public static unsafe extern IntPtr GetIssuer(TbsCertList* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "TbsCertList_get_issuer", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetIssuer(TbsCertList* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TbsCertList_get_this_upate", ExactSpelling = true)] - public static unsafe extern Time* GetThisUpate(TbsCertList* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "TbsCertList_get_this_upate", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Time* GetThisUpate(TbsCertList* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TbsCertList_get_next_update", ExactSpelling = true)] - public static unsafe extern Time* GetNextUpdate(TbsCertList* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "TbsCertList_get_next_update", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern Time* GetNextUpdate(TbsCertList* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TbsCertList_get_revoked_certificates", ExactSpelling = true)] - public static unsafe extern RevokedCertificateIterator* GetRevokedCertificates(TbsCertList* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "TbsCertList_get_revoked_certificates", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern RevokedCertificateIterator* GetRevokedCertificates(TbsCertList* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TbsCertList_get_extenstions", ExactSpelling = true)] - public static unsafe extern ExtensionIterator* GetExtenstions(TbsCertList* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "TbsCertList_get_extenstions", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ExtensionIterator* GetExtenstions(TbsCertList* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "TbsCertList_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(TbsCertList* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "TbsCertList_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(TbsCertList* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawTime.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawTime.cs index 586d3151..7973e8db 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawTime.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawTime.cs @@ -1,51 +1,40 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct Time +internal partial struct Time { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Time_get_year", ExactSpelling = true)] - public static unsafe extern ushort GetYear(Time* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Time_get_year", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ushort GetYear(Time* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Time_get_month", ExactSpelling = true)] - public static unsafe extern byte GetMonth(Time* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Time_get_month", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetMonth(Time* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Time_get_day", ExactSpelling = true)] - public static unsafe extern byte GetDay(Time* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Time_get_day", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetDay(Time* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Time_get_hour", ExactSpelling = true)] - public static unsafe extern byte GetHour(Time* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Time_get_hour", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetHour(Time* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Time_get_minute", ExactSpelling = true)] - public static unsafe extern byte GetMinute(Time* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Time_get_minute", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetMinute(Time* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Time_get_second", ExactSpelling = true)] - public static unsafe extern byte GetSecond(Time* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Time_get_second", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetSecond(Time* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Time_is_utc", ExactSpelling = true)] + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Time_is_utc", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] - public static unsafe extern bool IsUtc(Time* self); + internal static unsafe extern bool IsUtc(Time* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Time_is_generalized", ExactSpelling = true)] + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Time_is_generalized", CallingConvention = CallingConvention.Cdecl)] [return: MarshalAs(UnmanagedType.U1)] - public static unsafe extern bool IsGeneralized(Time* self); + internal static unsafe extern bool IsGeneralized(Time* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "Time_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(Time* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "Time_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(Time* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawU8.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawU8.cs index 6c90276c..bf035468 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawU8.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawU8.cs @@ -1,31 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// TODO: this could be fixed with future diplomat-tool Diplomat disallow Opion where T is a primitive type, so we need to wrap it in a pointer -/// [StructLayout(LayoutKind.Sequential)] -public partial struct U8 +internal partial struct U8 { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "U8_get_value", ExactSpelling = true)] - public static unsafe extern byte GetValue(U8* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "U8_get_value", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetValue(U8* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "U8_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(U8* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "U8_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(U8* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawUTCTime.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawUTCTime.cs index 8f11e1f7..3a1866dc 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawUTCTime.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawUTCTime.cs @@ -1,43 +1,32 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct UTCTime +internal partial struct UTCTime { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UTCTime_get_year", ExactSpelling = true)] - public static unsafe extern ushort GetYear(UTCTime* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UTCTime_get_year", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ushort GetYear(UTCTime* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UTCTime_get_month", ExactSpelling = true)] - public static unsafe extern byte GetMonth(UTCTime* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UTCTime_get_month", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetMonth(UTCTime* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UTCTime_get_day", ExactSpelling = true)] - public static unsafe extern byte GetDay(UTCTime* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UTCTime_get_day", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetDay(UTCTime* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UTCTime_get_hour", ExactSpelling = true)] - public static unsafe extern byte GetHour(UTCTime* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UTCTime_get_hour", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetHour(UTCTime* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UTCTime_get_minute", ExactSpelling = true)] - public static unsafe extern byte GetMinute(UTCTime* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UTCTime_get_minute", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetMinute(UTCTime* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UTCTime_get_second", ExactSpelling = true)] - public static unsafe extern byte GetSecond(UTCTime* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UTCTime_get_second", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetSecond(UTCTime* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UTCTime_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(UTCTime* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UTCTime_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(UTCTime* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawUTCTimeIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawUTCTimeIterator.cs index 119ecbc1..214f78e8 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawUTCTimeIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawUTCTimeIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct UTCTimeIterator +internal partial struct UTCTimeIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UTCTimeIterator_next", ExactSpelling = true)] - public static unsafe extern UTCTime* Next(UTCTimeIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UTCTimeIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UTCTime* Next(UTCTimeIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UTCTimeIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(UTCTimeIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UTCTimeIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(UTCTimeIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttribute.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttribute.cs index 4c113f9d..ebbc3c5c 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttribute.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttribute.cs @@ -1,31 +1,20 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct UnsignedAttribute +internal partial struct UnsignedAttribute { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UnsignedAttribute_get_type", ExactSpelling = true)] - public static unsafe extern IntPtr GetType(UnsignedAttribute* self, DiplomatWriteable* writable); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UnsignedAttribute_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidPickyError GetType(UnsignedAttribute* handle, DiplomatWrite* writeable); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UnsignedAttribute_get_values", ExactSpelling = true)] - public static unsafe extern UnsignedAttributeValue* GetValues(UnsignedAttribute* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UnsignedAttribute_get_values", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UnsignedAttributeValue* GetValues(UnsignedAttribute* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UnsignedAttribute_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(UnsignedAttribute* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UnsignedAttribute_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(UnsignedAttribute* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeIterator.cs index f6942e16..d6e87315 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeIterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct UnsignedAttributeIterator +internal partial struct UnsignedAttributeIterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UnsignedAttributeIterator_next", ExactSpelling = true)] - public static unsafe extern UnsignedAttribute* Next(UnsignedAttributeIterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UnsignedAttributeIterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UnsignedAttribute* Next(UnsignedAttributeIterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UnsignedAttributeIterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(UnsignedAttributeIterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UnsignedAttributeIterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(UnsignedAttributeIterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeValue.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeValue.cs index 5df20327..9dbf2885 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeValue.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeValue.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct UnsignedAttributeValue +internal partial struct UnsignedAttributeValue { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UnsignedAttributeValue_get_type", ExactSpelling = true)] - public static unsafe extern UnsignedAttributeValueType GetType(UnsignedAttributeValue* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UnsignedAttributeValue_get_type", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UnsignedAttributeValueType GetType(UnsignedAttributeValue* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UnsignedAttributeValue_to_ms_counter_sign", ExactSpelling = true)] - public static unsafe extern MsCounterSignIterator* ToMsCounterSign(UnsignedAttributeValue* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UnsignedAttributeValue_to_ms_counter_sign", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern MsCounterSignIterator* ToMsCounterSign(UnsignedAttributeValue* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UnsignedAttributeValue_to_counter_sign", ExactSpelling = true)] - public static unsafe extern SignerInfoIterator* ToCounterSign(UnsignedAttributeValue* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UnsignedAttributeValue_to_counter_sign", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern SignerInfoIterator* ToCounterSign(UnsignedAttributeValue* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UnsignedAttributeValue_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(UnsignedAttributeValue* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UnsignedAttributeValue_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(UnsignedAttributeValue* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeValueType.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeValueType.cs deleted file mode 100644 index 982fd234..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawUnsignedAttributeValueType.cs +++ /dev/null @@ -1,18 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -public enum UnsignedAttributeValueType -{ - MsCounterSign = 0, - CounterSign = 1, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawUtcDate.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawUtcDate.cs index 1600b894..37a0e495 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawUtcDate.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawUtcDate.cs @@ -1,61 +1,47 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - -/// -/// UTC date and time. -/// [StructLayout(LayoutKind.Sequential)] -public partial struct UtcDate +internal partial struct UtcDate { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_new", ExactSpelling = true)] - public static unsafe extern UtcDate* New(ushort year, byte month, byte day, byte hour, byte minute, byte second); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_new", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UtcDate* New(ushort year, byte month, byte day, byte hour, byte minute, byte second); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_ymd", ExactSpelling = true)] - public static unsafe extern UtcDate* Ymd(ushort year, byte month, byte day); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_ymd", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UtcDate* Ymd(ushort year, byte month, byte day); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_now", ExactSpelling = true)] - public static unsafe extern UtcDate* Now(); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_now", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern UtcDate* Now(); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_from_timestamp", ExactSpelling = true)] - public static unsafe extern IntPtr FromTimestamp(long timestamp); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_from_timestamp", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultUtcDatePickyError FromTimestamp(long timestamp); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_get_timestamp", ExactSpelling = true)] - public static unsafe extern IntPtr GetTimestamp(UtcDate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_get_timestamp", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultLongPickyError GetTimestamp(UtcDate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_get_month", ExactSpelling = true)] - public static unsafe extern byte GetMonth(UtcDate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_get_month", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetMonth(UtcDate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_get_day", ExactSpelling = true)] - public static unsafe extern byte GetDay(UtcDate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_get_day", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetDay(UtcDate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_get_hour", ExactSpelling = true)] - public static unsafe extern byte GetHour(UtcDate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_get_hour", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetHour(UtcDate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_get_minute", ExactSpelling = true)] - public static unsafe extern byte GetMinute(UtcDate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_get_minute", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetMinute(UtcDate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_get_second", ExactSpelling = true)] - public static unsafe extern byte GetSecond(UtcDate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_get_second", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern byte GetSecond(UtcDate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_get_year", ExactSpelling = true)] - public static unsafe extern ushort GetYear(UtcDate* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_get_year", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern ushort GetYear(UtcDate* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "UtcDate_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(UtcDate* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "UtcDate_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(UtcDate* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawUtilsFfiResultVoidBoxBufferTooSmallError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawUtilsFfiResultVoidBoxBufferTooSmallError.cs deleted file mode 100644 index d8c63391..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawUtilsFfiResultVoidBoxBufferTooSmallError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct UtilsFfiResultVoidBoxBufferTooSmallError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal BufferTooSmallError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe BufferTooSmallError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_BufferTooSmallError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawUtilsFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawUtilsFfiResultVoidBoxPickyError.cs deleted file mode 100644 index e007d8eb..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawUtilsFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct UtilsFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawVecU8.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawVecU8.cs index 380a21e2..3b857d04 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawVecU8.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawVecU8.cs @@ -1,34 +1,23 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct VecU8 +internal partial struct VecU8 { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "VecU8_from_bytes", ExactSpelling = true)] - public static unsafe extern VecU8* FromBytes(byte* bytes, nuint bytesSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "VecU8_from_bytes", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* FromBytes(DiplomatSliceU8 bytes); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "VecU8_get_length", ExactSpelling = true)] - public static unsafe extern nuint GetLength(VecU8* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "VecU8_get_length", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern nuint GetLength(VecU8* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "VecU8_fill", ExactSpelling = true)] - public static unsafe extern IntPtr Fill(VecU8* self, byte* buffer, nuint bufferSz); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "VecU8_fill", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern DiplomatResultVoidBufferTooSmallError Fill(VecU8* handle, DiplomatSliceMutU8 buffer); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "VecU8_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(VecU8* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "VecU8_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(VecU8* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawVecU8Iterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawVecU8Iterator.cs index 330f804c..1d241229 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawVecU8Iterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RawVecU8Iterator.cs @@ -1,28 +1,17 @@ -// by Diplomat - -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - +using Devolutions.Picky; using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky.Raw; -#nullable enable - [StructLayout(LayoutKind.Sequential)] -public partial struct VecU8Iterator +internal partial struct VecU8Iterator { -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "VecU8Iterator_next", ExactSpelling = true)] - public static unsafe extern VecU8* Next(VecU8Iterator* self); + [DllImport(DiplomatNativeLib.Name, EntryPoint = "VecU8Iterator_next", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern VecU8* Next(VecU8Iterator* handle); - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "VecU8Iterator_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(VecU8Iterator* self); -} + [DllImport(DiplomatNativeLib.Name, EntryPoint = "VecU8Iterator_destroy", CallingConvention = CallingConvention.Cdecl)] + internal static unsafe extern void Destroy(VecU8Iterator* handle); +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawVersion.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawVersion.cs deleted file mode 100644 index 02082822..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawVersion.cs +++ /dev/null @@ -1,23 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -/// -/// TODO: this could be lifted in future diplomat-tool, Diplomat does not allow Option wrapped enums, so we have to use a None variant -/// -public enum Version -{ - None = 0, - V1 = 1, - V2 = 2, - V3 = 3, -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AlgorithmIdentifierFfiResultBoolBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AlgorithmIdentifierFfiResultBoolBoxPickyError.cs deleted file mode 100644 index be9aaa05..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AlgorithmIdentifierFfiResultBoolBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AlgorithmIdentifierFfiResultBoolBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal bool ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe bool Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_bool_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AlgorithmIdentifierFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AlgorithmIdentifierFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 30b0f7ce..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AlgorithmIdentifierFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AlgorithmIdentifierFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AttributeFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AttributeFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 36274166..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AttributeFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AttributeFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError.cs deleted file mode 100644 index 26b9d558..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AuthenticodeFfiResultBoxAuthenticodeSignatureBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal AuthenticodeSignature* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe AuthenticodeSignature* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_AuthenticodeSignature_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxAuthenticodeTimestamperBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxAuthenticodeTimestamperBoxPickyError.cs deleted file mode 100644 index bd3d1ed4..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxAuthenticodeTimestamperBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AuthenticodeFfiResultBoxAuthenticodeTimestamperBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal AuthenticodeTimestamper* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe AuthenticodeTimestamper* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_AuthenticodeTimestamper_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxCertBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxCertBoxPickyError.cs deleted file mode 100644 index 0f880fcb..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxCertBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AuthenticodeFfiResultBoxCertBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Cert* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Cert* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Cert_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxPemBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxPemBoxPickyError.cs deleted file mode 100644 index 6b8ac704..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxPemBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AuthenticodeFfiResultBoxPemBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pem* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pem* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pem_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxPkcs7BoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxPkcs7BoxPickyError.cs deleted file mode 100644 index 8f4d3bb7..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxPkcs7BoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AuthenticodeFfiResultBoxPkcs7BoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pkcs7* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pkcs7* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pkcs7_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxVecU8BoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxVecU8BoxPickyError.cs deleted file mode 100644 index 367edf6b..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultBoxVecU8BoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AuthenticodeFfiResultBoxVecU8BoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal VecU8* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe VecU8* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_VecU8_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 18630a8a..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509AuthenticodeFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509AuthenticodeFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509ExtensionFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509ExtensionFfiResultVoidBoxPickyError.cs deleted file mode 100644 index dd7eeab2..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509ExtensionFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509ExtensionFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509FfiResultBoxCertBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509FfiResultBoxCertBoxPickyError.cs deleted file mode 100644 index f77240c3..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509FfiResultBoxCertBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509FfiResultBoxCertBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Cert* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Cert* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Cert_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509FfiResultBoxPemBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509FfiResultBoxPemBoxPickyError.cs deleted file mode 100644 index a3cf2e1a..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509FfiResultBoxPemBoxPickyError.cs +++ /dev/null @@ -1,55 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509FfiResultBoxPemBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal Pem* ok; - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe Pem* Ok - { - get - { - return _inner.ok; - } - } - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_box_Pem_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509FfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509FfiResultVoidBoxPickyError.cs deleted file mode 100644 index 8be76f2f..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509FfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509FfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509NameFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509NameFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 40c6ffb2..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509NameFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509NameFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509SingerInfoFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509SingerInfoFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 1eeab55a..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509SingerInfoFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509SingerInfoFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RawX509StringFfiResultVoidBoxPickyError.cs b/ffi/dotnet/Devolutions.Picky/Generated/RawX509StringFfiResultVoidBoxPickyError.cs deleted file mode 100644 index 4ab792b9..00000000 --- a/ffi/dotnet/Devolutions.Picky/Generated/RawX509StringFfiResultVoidBoxPickyError.cs +++ /dev/null @@ -1,45 +0,0 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - -namespace Devolutions.Picky.Raw; - -#nullable enable - -[StructLayout(LayoutKind.Sequential)] -public partial struct X509StringFfiResultVoidBoxPickyError -{ -#if __IOS__ - private const string NativeLib = "libDevolutionsPicky.framework/libDevolutionsPicky"; -#else - private const string NativeLib = "DevolutionsPicky"; -#endif - - [StructLayout(LayoutKind.Explicit)] - private unsafe struct InnerUnion - { - [FieldOffset(0)] - internal PickyError* err; - } - - private InnerUnion _inner; - - [MarshalAs(UnmanagedType.U1)] - public bool isOk; - - public unsafe PickyError* Err - { - get - { - return _inner.err; - } - } - - [DllImport(NativeLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "result_unit_box_PickyError_destroy", ExactSpelling = true)] - public static unsafe extern void Destroy(IntPtr self); -} diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RevocationInfoChoice.cs b/ffi/dotnet/Devolutions.Picky/Generated/RevocationInfoChoice.cs index 8e3d9189..b874f7b3 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RevocationInfoChoice.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RevocationInfoChoice.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class RevocationInfoChoice: IDisposable { - private unsafe Raw.RevocationInfoChoice* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.RevocationInfoChoice.Destroy; public CertificateList? Crl { @@ -27,14 +32,38 @@ public CertificateList? Crl /// Creates a managed RevocationInfoChoice from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe RevocationInfoChoice(Raw.RevocationInfoChoice* handle) + internal unsafe RevocationInfoChoice(Raw.RevocationInfoChoice* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe RevocationInfoChoice(Raw.RevocationInfoChoice* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe RevocationInfoChoice(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -44,25 +73,22 @@ public unsafe RevocationInfoChoice(Raw.RevocationInfoChoice* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("RevocationInfoChoice"); } - Raw.CertificateList* retVal = Raw.RevocationInfoChoice.GetCrl(_inner); - if (retVal == null) - { - return null; - } - return new CertificateList(retVal); + Raw.CertificateList* result = Raw.RevocationInfoChoice.GetCrl(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new CertificateList(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.RevocationInfoChoice* AsFFI() + internal unsafe Raw.RevocationInfoChoice* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -72,13 +98,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.RevocationInfoChoice.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -88,4 +115,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RevocationInfoChoiceIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RevocationInfoChoiceIterator.cs index b6862f8f..e04116a0 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RevocationInfoChoiceIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RevocationInfoChoiceIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class RevocationInfoChoiceIterator: IDisposable { - private unsafe Raw.RevocationInfoChoiceIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.RevocationInfoChoiceIterator.Destroy; /// /// Creates a managed RevocationInfoChoiceIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe RevocationInfoChoiceIterator(Raw.RevocationInfoChoiceIterator* handle) + internal unsafe RevocationInfoChoiceIterator(Raw.RevocationInfoChoiceIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe RevocationInfoChoiceIterator(Raw.RevocationInfoChoiceIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe RevocationInfoChoiceIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe RevocationInfoChoiceIterator(Raw.RevocationInfoChoiceIterator* han { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("RevocationInfoChoiceIterator"); } - Raw.RevocationInfoChoice* retVal = Raw.RevocationInfoChoiceIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new RevocationInfoChoice(retVal); + Raw.RevocationInfoChoice* result = Raw.RevocationInfoChoiceIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new RevocationInfoChoice(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.RevocationInfoChoiceIterator* AsFFI() + internal unsafe Raw.RevocationInfoChoiceIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.RevocationInfoChoiceIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RevokedCertificate.cs b/ffi/dotnet/Devolutions.Picky/Generated/RevokedCertificate.cs index a4118c83..65b2f8cf 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RevokedCertificate.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RevokedCertificate.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class RevokedCertificate: IDisposable { - private unsafe Raw.RevokedCertificate* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.RevokedCertificate.Destroy; public ExtensionIterator? Extensions { @@ -43,14 +48,38 @@ public VecU8 UserCertificate /// Creates a managed RevokedCertificate from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe RevokedCertificate(Raw.RevokedCertificate* handle) + internal unsafe RevokedCertificate(Raw.RevokedCertificate* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe RevokedCertificate(Raw.RevokedCertificate* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe RevokedCertificate(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -60,12 +89,13 @@ public VecU8 GetUserCertificate() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("RevokedCertificate"); } - Raw.VecU8* retVal = Raw.RevokedCertificate.GetUserCertificate(_inner); - return new VecU8(retVal); + Raw.VecU8* result = Raw.RevokedCertificate.GetUserCertificate(AsFFI()); + GC.KeepAlive(this); + return new VecU8(result); } } @@ -76,12 +106,13 @@ public Time GetRevocationDate() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("RevokedCertificate"); } - Raw.Time* retVal = Raw.RevokedCertificate.GetRevocationDate(_inner); - return new Time(retVal); + Raw.Time* result = Raw.RevokedCertificate.GetRevocationDate(AsFFI()); + GC.KeepAlive(this); + return new Time(result); } } @@ -92,25 +123,22 @@ public Time GetRevocationDate() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("RevokedCertificate"); } - Raw.ExtensionIterator* retVal = Raw.RevokedCertificate.GetExtensions(_inner); - if (retVal == null) - { - return null; - } - return new ExtensionIterator(retVal); + Raw.ExtensionIterator* result = Raw.RevokedCertificate.GetExtensions(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new ExtensionIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.RevokedCertificate* AsFFI() + internal unsafe Raw.RevokedCertificate* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -120,13 +148,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.RevokedCertificate.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -136,4 +165,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RevokedCertificateIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/RevokedCertificateIterator.cs index 5cb821bc..b61d36fb 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RevokedCertificateIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RevokedCertificateIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class RevokedCertificateIterator: IDisposable { - private unsafe Raw.RevokedCertificateIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.RevokedCertificateIterator.Destroy; /// /// Creates a managed RevokedCertificateIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe RevokedCertificateIterator(Raw.RevokedCertificateIterator* handle) + internal unsafe RevokedCertificateIterator(Raw.RevokedCertificateIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe RevokedCertificateIterator(Raw.RevokedCertificateIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe RevokedCertificateIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe RevokedCertificateIterator(Raw.RevokedCertificateIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("RevokedCertificateIterator"); } - Raw.RevokedCertificate* retVal = Raw.RevokedCertificateIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new RevokedCertificate(retVal); + Raw.RevokedCertificate* result = Raw.RevokedCertificateIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new RevokedCertificate(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.RevokedCertificateIterator* AsFFI() + internal unsafe Raw.RevokedCertificateIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.RevokedCertificateIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RsString.cs b/ffi/dotnet/Devolutions.Picky/Generated/RsString.cs index 0d04a0fd..7495f618 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RsString.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RsString.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class RsString: IDisposable { - private unsafe Raw.RsString* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.RsString.Destroy; /// /// Creates a managed RsString from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe RsString(Raw.RsString* handle) + internal unsafe RsString(Raw.RsString* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe RsString(Raw.RsString* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe RsString(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -36,12 +65,12 @@ public static RsString FromString(string s) { unsafe { - byte[] sBuf = DiplomatUtils.StringToUtf8(s); - nuint sBufLength = (nuint)sBuf.Length; - fixed (byte* sBufPtr = sBuf) + if (s == null) throw new ArgumentNullException(nameof(s)); + byte[] sBytes = System.Text.Encoding.UTF8.GetBytes(s); + fixed (byte* sPtr = sBytes) { - Raw.RsString* retVal = Raw.RsString.FromString(sBufPtr, sBufLength); - return new RsString(retVal); + Raw.RsString* result = Raw.RsString.FromString(new DiplomatSliceU8 { Ptr = sPtr, Len = (nuint)sBytes.Length }); + return new RsString(result); } } } @@ -49,9 +78,9 @@ public static RsString FromString(string s) /// /// Returns the underlying raw handle. /// - public unsafe Raw.RsString* AsFFI() + internal unsafe Raw.RsString* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -61,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.RsString.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -77,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RsassaPssParameters.cs b/ffi/dotnet/Devolutions.Picky/Generated/RsassaPssParameters.cs index 19bcec00..9ebd608e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/RsassaPssParameters.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/RsassaPssParameters.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,28 +10,60 @@ namespace Devolutions.Picky; public partial class RsassaPssParameters: IDisposable { - private unsafe Raw.RsassaPssParameters* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.RsassaPssParameters.Destroy; /// /// Creates a managed RsassaPssParameters from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe RsassaPssParameters(Raw.RsassaPssParameters* handle) + internal unsafe RsassaPssParameters(Raw.RsassaPssParameters* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe RsassaPssParameters(Raw.RsassaPssParameters* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe RsassaPssParameters(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// /// Returns the underlying raw handle. /// - public unsafe Raw.RsassaPssParameters* AsFFI() + internal unsafe Raw.RsassaPssParameters* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -44,13 +73,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.RsassaPssParameters.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -60,4 +90,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/RustHandle.cs b/ffi/dotnet/Devolutions.Picky/Generated/RustHandle.cs new file mode 100644 index 00000000..964f0eed --- /dev/null +++ b/ffi/dotnet/Devolutions.Picky/Generated/RustHandle.cs @@ -0,0 +1,50 @@ +using System; + +namespace Devolutions.Picky.Diplomat; + +#nullable enable + +/// +/// Frees a Rust-owned by calling its native +/// destructor. Held by an owned so the handle can +/// release the pointer without knowing the concrete type. +/// +internal unsafe delegate void RustDestructor(T* ptr) where T : unmanaged; + +/// +/// A raw pointer that remembers who's responsible for freeing it. An owned +/// handle carries the Rust destructor and runs it when you release the handle; +/// a borrowed handle carries none, so releasing it does nothing — Rust still +/// owns the memory and will free it itself. That's the whole trick: the +/// pointer itself says "free me" or "leave me alone", so the wrapper doesn't +/// need a separate flag bolted onto the class. +/// +internal readonly unsafe struct RustHandle where T : unmanaged +{ + private readonly T* _ptr; + private readonly RustDestructor? _free; + + private RustHandle(T* ptr, RustDestructor? free) + { + _ptr = ptr; + _free = free; + } + + /// The C# side owns the pointer: frees it. + public static RustHandle Owned(T* ptr, RustDestructor free) => new RustHandle(ptr, free); + + /// Rust still owns the pointer: is a no-op. + public static RustHandle Borrowed(T* ptr) => new RustHandle(ptr, null); + + public T* Ptr => _ptr; + + public bool IsNull => _ptr == null; + + public void Release() + { + if (_free != null && _ptr != null) + { + _free(_ptr); + } + } +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SafeBag.cs b/ffi/dotnet/Devolutions.Picky/Generated/SafeBag.cs index 9c69d401..7aa9b803 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SafeBag.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SafeBag.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// PFX safe bag, the polymorphic container for all the data in a PKCS12 archive. -/// public partial class SafeBag: IDisposable { - private unsafe Raw.SafeBag* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SafeBag.Destroy; public Cert? Certificate { @@ -46,19 +48,40 @@ public PrivateKey? PrivateKey /// Creates a managed SafeBag from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SafeBag(Raw.SafeBag* handle) + internal unsafe SafeBag(Raw.SafeBag* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SafeBag(Raw.SafeBag* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Creates new safe bag holding a private key. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe SafeBag(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A SafeBag allocated on Rust side. @@ -67,27 +90,19 @@ public static SafeBag NewKey(PrivateKey key) { unsafe { - Raw.PrivateKey* keyRaw; - keyRaw = key.AsFFI(); - if (keyRaw == null) - { - throw new ObjectDisposedException("PrivateKey"); - } - IntPtr resultPtr = Raw.SafeBag.NewKey(keyRaw); - Raw.Pkcs12FfiResultBoxSafeBagBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultBoxSafeBagBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (key == null) throw new ArgumentNullException(nameof(key)); + Raw.PrivateKey* keyRaw = key.AsFFI(); + if (keyRaw == null) throw new ObjectDisposedException(nameof(PrivateKey)); + var result = Raw.SafeBag.NewKey(keyRaw); + GC.KeepAlive(key); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SafeBag* retVal = result.Ok; - return new SafeBag(retVal); + return new SafeBag(result.Ok); } } - /// - /// Creates new safe bag holding an encrypted private key. - /// /// /// /// A SafeBag allocated on Rust side. @@ -96,39 +111,27 @@ public static SafeBag NewEncryptedKey(PrivateKey key, Pkcs12Encryption encryptio { unsafe { - Raw.PrivateKey* keyRaw; - keyRaw = key.AsFFI(); - if (keyRaw == null) - { - throw new ObjectDisposedException("PrivateKey"); - } - Raw.Pkcs12Encryption* encryptionRaw; - encryptionRaw = encryption.AsFFI(); - if (encryptionRaw == null) - { - throw new ObjectDisposedException("Pkcs12Encryption"); - } - Raw.Pkcs12CryptoContext* cryptoContextRaw; - cryptoContextRaw = cryptoContext.AsFFI(); - if (cryptoContextRaw == null) - { - throw new ObjectDisposedException("Pkcs12CryptoContext"); - } - IntPtr resultPtr = Raw.SafeBag.NewEncryptedKey(keyRaw, encryptionRaw, cryptoContextRaw); - Raw.Pkcs12FfiResultBoxSafeBagBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultBoxSafeBagBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (key == null) throw new ArgumentNullException(nameof(key)); + Raw.PrivateKey* keyRaw = key.AsFFI(); + if (keyRaw == null) throw new ObjectDisposedException(nameof(PrivateKey)); + if (encryption == null) throw new ArgumentNullException(nameof(encryption)); + Raw.Pkcs12Encryption* encryptionRaw = encryption.AsFFI(); + if (encryptionRaw == null) throw new ObjectDisposedException(nameof(Pkcs12Encryption)); + if (cryptoContext == null) throw new ArgumentNullException(nameof(cryptoContext)); + Raw.Pkcs12CryptoContext* cryptoContextRaw = cryptoContext.AsFFI(); + if (cryptoContextRaw == null) throw new ObjectDisposedException(nameof(Pkcs12CryptoContext)); + var result = Raw.SafeBag.NewEncryptedKey(keyRaw, encryptionRaw, cryptoContextRaw); + GC.KeepAlive(key); + GC.KeepAlive(encryption); + GC.KeepAlive(cryptoContext); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SafeBag* retVal = result.Ok; - return new SafeBag(retVal); + return new SafeBag(result.Ok); } } - /// - /// Creates new safe bag holding a certificate. - /// /// /// /// A SafeBag allocated on Rust side. @@ -137,58 +140,47 @@ public static SafeBag NewCertificate(Cert cert) { unsafe { - Raw.Cert* certRaw; - certRaw = cert.AsFFI(); - if (certRaw == null) - { - throw new ObjectDisposedException("Cert"); - } - IntPtr resultPtr = Raw.SafeBag.NewCertificate(certRaw); - Raw.Pkcs12FfiResultBoxSafeBagBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.Pkcs12FfiResultBoxSafeBagBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (cert == null) throw new ArgumentNullException(nameof(cert)); + Raw.Cert* certRaw = cert.AsFFI(); + if (certRaw == null) throw new ObjectDisposedException(nameof(Cert)); + var result = Raw.SafeBag.NewCertificate(certRaw); + GC.KeepAlive(cert); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SafeBag* retVal = result.Ok; - return new SafeBag(retVal); + return new SafeBag(result.Ok); } } - /// - /// Adds a PKCS12 attribute to this safe bag. - /// public void AddAttribute(Pkcs12Attribute attribute) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SafeBag"); } - Raw.Pkcs12Attribute* attributeRaw; - attributeRaw = attribute.AsFFI(); - if (attributeRaw == null) - { - throw new ObjectDisposedException("Pkcs12Attribute"); - } - Raw.SafeBag.AddAttribute(_inner, attributeRaw); + if (attribute == null) throw new ArgumentNullException(nameof(attribute)); + Raw.Pkcs12Attribute* attributeRaw = attribute.AsFFI(); + if (attributeRaw == null) throw new ObjectDisposedException(nameof(Pkcs12Attribute)); + Raw.SafeBag.AddAttribute(AsFFI(), attributeRaw); + GC.KeepAlive(this); + GC.KeepAlive(attribute); } } - /// - /// A SafeBagKind allocated on C# side. - /// public SafeBagKind GetKind() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SafeBag"); } - Raw.SafeBagKind retVal = Raw.SafeBag.GetKind(_inner); - return (SafeBagKind)retVal; + var result = Raw.SafeBag.GetKind(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -199,16 +191,13 @@ public SafeBagKind GetKind() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SafeBag"); } - Raw.PrivateKey* retVal = Raw.SafeBag.GetPrivateKey(_inner); - if (retVal == null) - { - return null; - } - return new PrivateKey(retVal); + Raw.PrivateKey* result = Raw.SafeBag.GetPrivateKey(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new PrivateKey(result); } } @@ -219,16 +208,13 @@ public SafeBagKind GetKind() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SafeBag"); } - Raw.Cert* retVal = Raw.SafeBag.GetCertificate(_inner); - if (retVal == null) - { - return null; - } - return new Cert(retVal); + Raw.Cert* result = Raw.SafeBag.GetCertificate(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new Cert(result); } } @@ -236,16 +222,17 @@ public bool ContainsFriendlyName(string value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SafeBag"); } - byte[] valueBuf = DiplomatUtils.StringToUtf8(value); - nuint valueBufLength = (nuint)valueBuf.Length; - fixed (byte* valueBufPtr = valueBuf) + if (value == null) throw new ArgumentNullException(nameof(value)); + byte[] valueBytes = System.Text.Encoding.UTF8.GetBytes(value); + fixed (byte* valuePtr = valueBytes) { - bool retVal = Raw.SafeBag.ContainsFriendlyName(_inner, valueBufPtr, valueBufLength); - return retVal; + var result = Raw.SafeBag.ContainsFriendlyName(AsFFI(), new DiplomatSliceU8 { Ptr = valuePtr, Len = (nuint)valueBytes.Length }); + GC.KeepAlive(this); + return result; } } } @@ -254,15 +241,16 @@ public bool ContainsLocalKeyId(byte[] value) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SafeBag"); } - nuint valueLength = (nuint)value.Length; + if (value == null) throw new ArgumentNullException(nameof(value)); fixed (byte* valuePtr = value) { - bool retVal = Raw.SafeBag.ContainsLocalKeyId(_inner, valuePtr, valueLength); - return retVal; + var result = Raw.SafeBag.ContainsLocalKeyId(AsFFI(), new DiplomatSliceU8 { Ptr = valuePtr, Len = (nuint)value.Length }); + GC.KeepAlive(this); + return result; } } } @@ -274,21 +262,22 @@ public Pkcs12AttributeIterator Attributes() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SafeBag"); } - Raw.Pkcs12AttributeIterator* retVal = Raw.SafeBag.Attributes(_inner); - return new Pkcs12AttributeIterator(retVal); + Raw.Pkcs12AttributeIterator* result = Raw.SafeBag.Attributes(AsFFI()); + GC.KeepAlive(this); + return new Pkcs12AttributeIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SafeBag* AsFFI() + internal unsafe Raw.SafeBag* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -298,13 +287,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SafeBag.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -314,4 +304,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SafeBagIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/SafeBagIterator.cs index 18017aad..09a203ba 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SafeBagIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SafeBagIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class SafeBagIterator: IDisposable { - private unsafe Raw.SafeBagIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SafeBagIterator.Destroy; /// /// Creates a managed SafeBagIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SafeBagIterator(Raw.SafeBagIterator* handle) + internal unsafe SafeBagIterator(Raw.SafeBagIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SafeBagIterator(Raw.SafeBagIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SafeBagIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe SafeBagIterator(Raw.SafeBagIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SafeBagIterator"); } - Raw.SafeBag* retVal = Raw.SafeBagIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new SafeBag(retVal); + Raw.SafeBag* result = Raw.SafeBagIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new SafeBag(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SafeBagIterator* AsFFI() + internal unsafe Raw.SafeBagIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SafeBagIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SafeBagKind.cs b/ffi/dotnet/Devolutions.Picky/Generated/SafeBagKind.cs index c98737fe..ed8726cf 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SafeBagKind.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SafeBagKind.cs @@ -1,20 +1,9 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum SafeBagKind +public enum SafeBagKind : int { PrivateKey = 0, Certificate = 1, Secret = 2, Unknown = 3, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/ShaVariant.cs b/ffi/dotnet/Devolutions.Picky/Generated/ShaVariant.cs index ee7903eb..f5d8d532 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/ShaVariant.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/ShaVariant.cs @@ -1,30 +1,19 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum ShaVariant +public enum ShaVariant : int { - MD5 = 0, - SHA1 = 1, - SHA2_224 = 2, - SHA2_256 = 3, - SHA2_384 = 4, - SHA2_512 = 5, - SHA2_512_224 = 6, - SHA2_512_256 = 7, - SHA3_224 = 8, - SHA3_256 = 9, - SHA3_384 = 10, - SHA3_512 = 11, - SHAKE128 = 12, - SHAKE256 = 13, -} + Md5 = 0, + Sha1 = 1, + Sha2224 = 2, + Sha2256 = 3, + Sha2384 = 4, + Sha2512 = 5, + Sha2512224 = 6, + Sha2512256 = 7, + Sha3224 = 8, + Sha3256 = 9, + Sha3384 = 10, + Sha3512 = 11, + Shake128 = 12, + Shake256 = 13, +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SignatureAlgorithm.cs b/ffi/dotnet/Devolutions.Picky/Generated/SignatureAlgorithm.cs index 4ab8afa6..5a5a2379 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SignatureAlgorithm.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SignatureAlgorithm.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class SignatureAlgorithm: IDisposable { - private unsafe Raw.SignatureAlgorithm* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SignatureAlgorithm.Destroy; /// /// Creates a managed SignatureAlgorithm from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SignatureAlgorithm(Raw.SignatureAlgorithm* handle) + internal unsafe SignatureAlgorithm(Raw.SignatureAlgorithm* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SignatureAlgorithm(Raw.SignatureAlgorithm* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SignatureAlgorithm(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -37,17 +66,12 @@ public static SignatureAlgorithm NewRsaPkcs1v15(HashAlgorithm hashAlgorithm) { unsafe { - Raw.HashAlgorithm hashAlgorithmRaw; - hashAlgorithmRaw = (Raw.HashAlgorithm)hashAlgorithm; - IntPtr resultPtr = Raw.SignatureAlgorithm.NewRsaPkcs1v15(hashAlgorithmRaw); - Raw.SignatureFfiResultBoxSignatureAlgorithmBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SignatureFfiResultBoxSignatureAlgorithmBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SignatureAlgorithm.NewRsaPkcs1v15(hashAlgorithm); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SignatureAlgorithm* retVal = result.Ok; - return new SignatureAlgorithm(retVal); + return new SignatureAlgorithm(result.Ok); } } @@ -59,17 +83,12 @@ public static SignatureAlgorithm NewEcdsa(HashAlgorithm hashAlgorithm) { unsafe { - Raw.HashAlgorithm hashAlgorithmRaw; - hashAlgorithmRaw = (Raw.HashAlgorithm)hashAlgorithm; - IntPtr resultPtr = Raw.SignatureAlgorithm.NewEcdsa(hashAlgorithmRaw); - Raw.SignatureFfiResultBoxSignatureAlgorithmBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SignatureFfiResultBoxSignatureAlgorithmBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SignatureAlgorithm.NewEcdsa(hashAlgorithm); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SignatureAlgorithm* retVal = result.Ok; - return new SignatureAlgorithm(retVal); + return new SignatureAlgorithm(result.Ok); } } @@ -78,30 +97,26 @@ public void Verify(PublicKey publicKey, byte[] msg, byte[] signature) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignatureAlgorithm"); } - nuint msgLength = (nuint)msg.Length; - nuint signatureLength = (nuint)signature.Length; - Raw.PublicKey* publicKeyRaw; - publicKeyRaw = publicKey.AsFFI(); - if (publicKeyRaw == null) - { - throw new ObjectDisposedException("PublicKey"); - } + if (publicKey == null) throw new ArgumentNullException(nameof(publicKey)); + Raw.PublicKey* publicKeyRaw = publicKey.AsFFI(); + if (publicKeyRaw == null) throw new ObjectDisposedException(nameof(PublicKey)); + if (msg == null) throw new ArgumentNullException(nameof(msg)); + if (signature == null) throw new ArgumentNullException(nameof(signature)); fixed (byte* msgPtr = msg) + fixed (byte* signaturePtr = signature) { - fixed (byte* signaturePtr = signature) + var result = Raw.SignatureAlgorithm.Verify(AsFFI(), publicKeyRaw, new DiplomatSliceU8 { Ptr = msgPtr, Len = (nuint)msg.Length }, new DiplomatSliceU8 { Ptr = signaturePtr, Len = (nuint)signature.Length }); + GC.KeepAlive(this); + GC.KeepAlive(publicKey); + if (!result.IsOk) { - IntPtr resultPtr = Raw.SignatureAlgorithm.Verify(_inner, publicKeyRaw, msgPtr, msgLength, signaturePtr, signatureLength); - Raw.SignatureFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SignatureFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } + throw new PickyException(new PickyError(result.Err)); } + return; } } } @@ -109,9 +124,9 @@ public void Verify(PublicKey publicKey, byte[] msg, byte[] signature) /// /// Returns the underlying raw handle. /// - public unsafe Raw.SignatureAlgorithm* AsFFI() + internal unsafe Raw.SignatureAlgorithm* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -121,13 +136,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SignatureAlgorithm.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -137,4 +153,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SignedData.cs b/ffi/dotnet/Devolutions.Picky/Generated/SignedData.cs index 8b1aae7d..62bdc96d 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SignedData.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SignedData.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class SignedData: IDisposable { - private unsafe Raw.SignedData* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SignedData.Destroy; public CertificateChoicesIterator Certificates { @@ -67,29 +72,51 @@ public CmsVersion Version /// Creates a managed SignedData from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SignedData(Raw.SignedData* handle) + internal unsafe SignedData(Raw.SignedData* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SignedData(Raw.SignedData* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SignedData(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A CmsVersion allocated on C# side. - /// public CmsVersion GetVersion() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignedData"); } - Raw.CmsVersion retVal = Raw.SignedData.GetVersion(_inner); - return (CmsVersion)retVal; + var result = Raw.SignedData.GetVersion(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -100,12 +127,13 @@ public AlgorithmIdentifierIterator GetDigestAlgorithms() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignedData"); } - Raw.AlgorithmIdentifierIterator* retVal = Raw.SignedData.GetDigestAlgorithms(_inner); - return new AlgorithmIdentifierIterator(retVal); + Raw.AlgorithmIdentifierIterator* result = Raw.SignedData.GetDigestAlgorithms(AsFFI()); + GC.KeepAlive(this); + return new AlgorithmIdentifierIterator(result); } } @@ -116,12 +144,13 @@ public EncapsulatedContentInfo GetContentInfo() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignedData"); } - Raw.EncapsulatedContentInfo* retVal = Raw.SignedData.GetContentInfo(_inner); - return new EncapsulatedContentInfo(retVal); + Raw.EncapsulatedContentInfo* result = Raw.SignedData.GetContentInfo(AsFFI()); + GC.KeepAlive(this); + return new EncapsulatedContentInfo(result); } } @@ -132,16 +161,13 @@ public EncapsulatedContentInfo GetContentInfo() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignedData"); } - Raw.RevocationInfoChoiceIterator* retVal = Raw.SignedData.GetCrls(_inner); - if (retVal == null) - { - return null; - } - return new RevocationInfoChoiceIterator(retVal); + Raw.RevocationInfoChoiceIterator* result = Raw.SignedData.GetCrls(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new RevocationInfoChoiceIterator(result); } } @@ -152,12 +178,13 @@ public CertificateChoicesIterator GetCertificates() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignedData"); } - Raw.CertificateChoicesIterator* retVal = Raw.SignedData.GetCertificates(_inner); - return new CertificateChoicesIterator(retVal); + Raw.CertificateChoicesIterator* result = Raw.SignedData.GetCertificates(AsFFI()); + GC.KeepAlive(this); + return new CertificateChoicesIterator(result); } } @@ -168,21 +195,22 @@ public SignerInfoIterator GetSignersInfos() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignedData"); } - Raw.SignerInfoIterator* retVal = Raw.SignedData.GetSignersInfos(_inner); - return new SignerInfoIterator(retVal); + Raw.SignerInfoIterator* result = Raw.SignedData.GetSignersInfos(AsFFI()); + GC.KeepAlive(this); + return new SignerInfoIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SignedData* AsFFI() + internal unsafe Raw.SignedData* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -192,13 +220,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SignedData.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -208,4 +237,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SignerInfo.cs b/ffi/dotnet/Devolutions.Picky/Generated/SignerInfo.cs index 0afaeea8..b698a000 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SignerInfo.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SignerInfo.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class SignerInfo: IDisposable { - private unsafe Raw.SignerInfo* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SignerInfo.Destroy; public AlgorithmIdentifier DigestAlgorithm { @@ -75,29 +80,51 @@ public CmsVersion Version /// Creates a managed SignerInfo from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SignerInfo(Raw.SignerInfo* handle) + internal unsafe SignerInfo(Raw.SignerInfo* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SignerInfo(Raw.SignerInfo* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SignerInfo(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A CmsVersion allocated on C# side. - /// public CmsVersion GetVersion() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignerInfo"); } - Raw.CmsVersion retVal = Raw.SignerInfo.GetVersion(_inner); - return (CmsVersion)retVal; + var result = Raw.SignerInfo.GetVersion(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -108,12 +135,13 @@ public SingerIdentifier GetSid() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignerInfo"); } - Raw.SingerIdentifier* retVal = Raw.SignerInfo.GetSid(_inner); - return new SingerIdentifier(retVal); + Raw.SingerIdentifier* result = Raw.SignerInfo.GetSid(AsFFI()); + GC.KeepAlive(this); + return new SingerIdentifier(result); } } @@ -124,12 +152,13 @@ public AlgorithmIdentifier GetDigestAlgorithm() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignerInfo"); } - Raw.AlgorithmIdentifier* retVal = Raw.SignerInfo.GetDigestAlgorithm(_inner); - return new AlgorithmIdentifier(retVal); + Raw.AlgorithmIdentifier* result = Raw.SignerInfo.GetDigestAlgorithm(AsFFI()); + GC.KeepAlive(this); + return new AlgorithmIdentifier(result); } } @@ -140,12 +169,13 @@ public AlgorithmIdentifier GetSignatureAlgorithm() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignerInfo"); } - Raw.AlgorithmIdentifier* retVal = Raw.SignerInfo.GetSignatureAlgorithm(_inner); - return new AlgorithmIdentifier(retVal); + Raw.AlgorithmIdentifier* result = Raw.SignerInfo.GetSignatureAlgorithm(AsFFI()); + GC.KeepAlive(this); + return new AlgorithmIdentifier(result); } } @@ -156,12 +186,13 @@ public VecU8 GetSignature() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignerInfo"); } - Raw.VecU8* retVal = Raw.SignerInfo.GetSignature(_inner); - return new VecU8(retVal); + Raw.VecU8* result = Raw.SignerInfo.GetSignature(AsFFI()); + GC.KeepAlive(this); + return new VecU8(result); } } @@ -172,12 +203,13 @@ public UnsignedAttributeIterator GetUnsignedAttributes() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignerInfo"); } - Raw.UnsignedAttributeIterator* retVal = Raw.SignerInfo.GetUnsignedAttributes(_inner); - return new UnsignedAttributeIterator(retVal); + Raw.UnsignedAttributeIterator* result = Raw.SignerInfo.GetUnsignedAttributes(AsFFI()); + GC.KeepAlive(this); + return new UnsignedAttributeIterator(result); } } @@ -188,21 +220,22 @@ public AttributeIterator GetSignedAttributes() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignerInfo"); } - Raw.AttributeIterator* retVal = Raw.SignerInfo.GetSignedAttributes(_inner); - return new AttributeIterator(retVal); + Raw.AttributeIterator* result = Raw.SignerInfo.GetSignedAttributes(AsFFI()); + GC.KeepAlive(this); + return new AttributeIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SignerInfo* AsFFI() + internal unsafe Raw.SignerInfo* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -212,13 +245,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SignerInfo.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -228,4 +262,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SignerInfoIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/SignerInfoIterator.cs index cb71bcc4..47721cc0 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SignerInfoIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SignerInfoIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class SignerInfoIterator: IDisposable { - private unsafe Raw.SignerInfoIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SignerInfoIterator.Destroy; /// /// Creates a managed SignerInfoIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SignerInfoIterator(Raw.SignerInfoIterator* handle) + internal unsafe SignerInfoIterator(Raw.SignerInfoIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SignerInfoIterator(Raw.SignerInfoIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SignerInfoIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe SignerInfoIterator(Raw.SignerInfoIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SignerInfoIterator"); } - Raw.SignerInfo* retVal = Raw.SignerInfoIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new SignerInfo(retVal); + Raw.SignerInfo* result = Raw.SignerInfoIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new SignerInfo(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SignerInfoIterator* AsFFI() + internal unsafe Raw.SignerInfoIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SignerInfoIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SingerIdentifier.cs b/ffi/dotnet/Devolutions.Picky/Generated/SingerIdentifier.cs index 2627edbf..e1411b92 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SingerIdentifier.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SingerIdentifier.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class SingerIdentifier: IDisposable { - private unsafe Raw.SingerIdentifier* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SingerIdentifier.Destroy; public IssuerAndSerialNumber? IssureAndSerialNumber { @@ -35,14 +40,38 @@ public VecU8? SubjectKeyIdentifier /// Creates a managed SingerIdentifier from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SingerIdentifier(Raw.SingerIdentifier* handle) + internal unsafe SingerIdentifier(Raw.SingerIdentifier* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SingerIdentifier(Raw.SingerIdentifier* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SingerIdentifier(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -52,16 +81,13 @@ public unsafe SingerIdentifier(Raw.SingerIdentifier* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SingerIdentifier"); } - Raw.IssuerAndSerialNumber* retVal = Raw.SingerIdentifier.GetIssureAndSerialNumber(_inner); - if (retVal == null) - { - return null; - } - return new IssuerAndSerialNumber(retVal); + Raw.IssuerAndSerialNumber* result = Raw.SingerIdentifier.GetIssureAndSerialNumber(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new IssuerAndSerialNumber(result); } } @@ -72,25 +98,22 @@ public unsafe SingerIdentifier(Raw.SingerIdentifier* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SingerIdentifier"); } - Raw.VecU8* retVal = Raw.SingerIdentifier.GetSubjectKeyIdentifier(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.SingerIdentifier.GetSubjectKeyIdentifier(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SingerIdentifier* AsFFI() + internal unsafe Raw.SingerIdentifier* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -100,13 +123,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SingerIdentifier.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -116,4 +140,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SpcLink.cs b/ffi/dotnet/Devolutions.Picky/Generated/SpcLink.cs index e0bb718b..ab70fd76 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SpcLink.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SpcLink.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class SpcLink: IDisposable { - private unsafe Raw.SpcLink* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SpcLink.Destroy; public SpcString? File { @@ -51,29 +56,51 @@ public VecU8? Url /// Creates a managed SpcLink from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SpcLink(Raw.SpcLink* handle) + internal unsafe SpcLink(Raw.SpcLink* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SpcLink(Raw.SpcLink* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SpcLink(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A SpcLinkType allocated on C# side. - /// public SpcLinkType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcLink"); } - Raw.SpcLinkType retVal = Raw.SpcLink.GetType(_inner); - return (SpcLinkType)retVal; + var result = Raw.SpcLink.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -84,16 +111,13 @@ public SpcLinkType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcLink"); } - Raw.VecU8* retVal = Raw.SpcLink.GetUrl(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.SpcLink.GetUrl(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } @@ -104,16 +128,13 @@ public SpcLinkType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcLink"); } - Raw.SpcSerializedObject* retVal = Raw.SpcLink.GetMoniker(_inner); - if (retVal == null) - { - return null; - } - return new SpcSerializedObject(retVal); + Raw.SpcSerializedObject* result = Raw.SpcLink.GetMoniker(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new SpcSerializedObject(result); } } @@ -124,25 +145,22 @@ public SpcLinkType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcLink"); } - Raw.SpcString* retVal = Raw.SpcLink.GetFile(_inner); - if (retVal == null) - { - return null; - } - return new SpcString(retVal); + Raw.SpcString* result = Raw.SpcLink.GetFile(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new SpcString(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SpcLink* AsFFI() + internal unsafe Raw.SpcLink* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -152,13 +170,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SpcLink.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -168,4 +187,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SpcLinkType.cs b/ffi/dotnet/Devolutions.Picky/Generated/SpcLinkType.cs index ffd8ea80..c745e639 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SpcLinkType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SpcLinkType.cs @@ -1,19 +1,8 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum SpcLinkType +public enum SpcLinkType : int { Url = 0, Moniker = 1, File = 2, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SpcSerializedObject.cs b/ffi/dotnet/Devolutions.Picky/Generated/SpcSerializedObject.cs index a8671a6b..49c747ef 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SpcSerializedObject.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SpcSerializedObject.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class SpcSerializedObject: IDisposable { - private unsafe Raw.SpcSerializedObject* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SpcSerializedObject.Destroy; public VecU8 ClassId { @@ -35,14 +40,38 @@ public VecU8 ObjectId /// Creates a managed SpcSerializedObject from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SpcSerializedObject(Raw.SpcSerializedObject* handle) + internal unsafe SpcSerializedObject(Raw.SpcSerializedObject* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SpcSerializedObject(Raw.SpcSerializedObject* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SpcSerializedObject(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -52,12 +81,13 @@ public VecU8 GetClassId() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcSerializedObject"); } - Raw.VecU8* retVal = Raw.SpcSerializedObject.GetClassId(_inner); - return new VecU8(retVal); + Raw.VecU8* result = Raw.SpcSerializedObject.GetClassId(AsFFI()); + GC.KeepAlive(this); + return new VecU8(result); } } @@ -68,21 +98,22 @@ public VecU8 GetObjectId() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcSerializedObject"); } - Raw.VecU8* retVal = Raw.SpcSerializedObject.GetObjectId(_inner); - return new VecU8(retVal); + Raw.VecU8* result = Raw.SpcSerializedObject.GetObjectId(AsFFI()); + GC.KeepAlive(this); + return new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SpcSerializedObject* AsFFI() + internal unsafe Raw.SpcSerializedObject* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -92,13 +123,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SpcSerializedObject.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -108,4 +140,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SpcSpOpusInfo.cs b/ffi/dotnet/Devolutions.Picky/Generated/SpcSpOpusInfo.cs index 21042cef..c4157c06 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SpcSpOpusInfo.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SpcSpOpusInfo.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class SpcSpOpusInfo: IDisposable { - private unsafe Raw.SpcSpOpusInfo* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SpcSpOpusInfo.Destroy; public SpcLink? MoreInfo { @@ -35,14 +40,38 @@ public SpcString? ProgramName /// Creates a managed SpcSpOpusInfo from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SpcSpOpusInfo(Raw.SpcSpOpusInfo* handle) + internal unsafe SpcSpOpusInfo(Raw.SpcSpOpusInfo* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SpcSpOpusInfo(Raw.SpcSpOpusInfo* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SpcSpOpusInfo(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -52,16 +81,13 @@ public unsafe SpcSpOpusInfo(Raw.SpcSpOpusInfo* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcSpOpusInfo"); } - Raw.SpcString* retVal = Raw.SpcSpOpusInfo.GetProgramName(_inner); - if (retVal == null) - { - return null; - } - return new SpcString(retVal); + Raw.SpcString* result = Raw.SpcSpOpusInfo.GetProgramName(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new SpcString(result); } } @@ -72,25 +98,22 @@ public unsafe SpcSpOpusInfo(Raw.SpcSpOpusInfo* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcSpOpusInfo"); } - Raw.SpcLink* retVal = Raw.SpcSpOpusInfo.GetMoreInfo(_inner); - if (retVal == null) - { - return null; - } - return new SpcLink(retVal); + Raw.SpcLink* result = Raw.SpcSpOpusInfo.GetMoreInfo(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new SpcLink(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SpcSpOpusInfo* AsFFI() + internal unsafe Raw.SpcSpOpusInfo* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -100,13 +123,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SpcSpOpusInfo.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -116,4 +140,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SpcSpOpusInfoIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/SpcSpOpusInfoIterator.cs index 82e2c75c..7fd9a56e 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SpcSpOpusInfoIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SpcSpOpusInfoIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class SpcSpOpusInfoIterator: IDisposable { - private unsafe Raw.SpcSpOpusInfoIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SpcSpOpusInfoIterator.Destroy; /// /// Creates a managed SpcSpOpusInfoIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SpcSpOpusInfoIterator(Raw.SpcSpOpusInfoIterator* handle) + internal unsafe SpcSpOpusInfoIterator(Raw.SpcSpOpusInfoIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SpcSpOpusInfoIterator(Raw.SpcSpOpusInfoIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SpcSpOpusInfoIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe SpcSpOpusInfoIterator(Raw.SpcSpOpusInfoIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcSpOpusInfoIterator"); } - Raw.SpcSpOpusInfo* retVal = Raw.SpcSpOpusInfoIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new SpcSpOpusInfo(retVal); + Raw.SpcSpOpusInfo* result = Raw.SpcSpOpusInfoIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new SpcSpOpusInfo(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SpcSpOpusInfoIterator* AsFFI() + internal unsafe Raw.SpcSpOpusInfoIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SpcSpOpusInfoIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SpcString.cs b/ffi/dotnet/Devolutions.Picky/Generated/SpcString.cs index cf12265e..300f53f2 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SpcString.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SpcString.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class SpcString: IDisposable { - private unsafe Raw.SpcString* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SpcString.Destroy; public VecU8 AsBytes { @@ -43,48 +48,51 @@ public SpcStringType Type /// Creates a managed SpcString from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SpcString(Raw.SpcString* handle) + internal unsafe SpcString(Raw.SpcString* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - /// A SpcStringType allocated on C# side. - /// - public SpcStringType GetType() + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SpcString(Raw.SpcString* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("SpcString"); - } - Raw.SpcStringType retVal = Raw.SpcString.GetType(_inner); - return (SpcStringType)retVal; - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } - /// - public void GetAsString(DiplomatWriteable writable) + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SpcString(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + + public SpcStringType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcString"); } - IntPtr resultPtr = Raw.SpcString.GetAsString(_inner, &writable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } + var result = Raw.SpcString.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -93,21 +101,25 @@ public string GetAsString() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcString"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.SpcString.GetAsString(_inner, &writeable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.SpcString.GetAsString(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -118,21 +130,22 @@ public VecU8 GetAsBytes() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SpcString"); } - Raw.VecU8* retVal = Raw.SpcString.GetAsBytes(_inner); - return new VecU8(retVal); + Raw.VecU8* result = Raw.SpcString.GetAsBytes(AsFFI()); + GC.KeepAlive(this); + return new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SpcString* AsFFI() + internal unsafe Raw.SpcString* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -142,13 +155,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SpcString.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -158,4 +172,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SpcStringType.cs b/ffi/dotnet/Devolutions.Picky/Generated/SpcStringType.cs index bb18798f..a665bf74 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SpcStringType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SpcStringType.cs @@ -1,18 +1,7 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum SpcStringType +public enum SpcStringType : int { Unicode = 0, Ancii = 1, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SshCert.cs b/ffi/dotnet/Devolutions.Picky/Generated/SshCert.cs index 9e398e8b..b03ae3b6 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SshCert.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SshCert.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class SshCert: IDisposable { - private unsafe Raw.SshCert* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SshCert.Destroy; public SshCertType CertType { @@ -83,14 +88,38 @@ public ulong ValidBefore /// Creates a managed SshCert from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SshCert(Raw.SshCert* handle) + internal unsafe SshCert(Raw.SshCert* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SshCert(Raw.SshCert* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SshCert(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -100,14 +129,11 @@ public static SshCertBuilder Builder() { unsafe { - Raw.SshCertBuilder* retVal = Raw.SshCert.Builder(); - return new SshCertBuilder(retVal); + Raw.SshCertBuilder* result = Raw.SshCert.Builder(); + return new SshCertBuilder(result); } } - /// - /// Parses string representation of a SSH Certificate. - /// /// /// /// A SshCert allocated on Rust side. @@ -116,68 +142,44 @@ public static SshCert Parse(string repr) { unsafe { - byte[] reprBuf = DiplomatUtils.StringToUtf8(repr); - nuint reprBufLength = (nuint)reprBuf.Length; - fixed (byte* reprBufPtr = reprBuf) + if (repr == null) throw new ArgumentNullException(nameof(repr)); + byte[] reprBytes = System.Text.Encoding.UTF8.GetBytes(repr); + fixed (byte* reprPtr = reprBytes) { - IntPtr resultPtr = Raw.SshCert.Parse(reprBufPtr, reprBufLength); - Raw.SshFfiResultBoxSshCertBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxSshCertBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SshCert.Parse(new DiplomatSliceU8 { Ptr = reprPtr, Len = (nuint)reprBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SshCert* retVal = result.Ok; - return new SshCert(retVal); + return new SshCert(result.Ok); } } } - /// - /// Returns the SSH Certificate string representation. - /// /// - public void ToRepr(DiplomatWriteable writeable) + public string ToRepr() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCert"); } - IntPtr resultPtr = Raw.SshCert.ToRepr(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - /// Returns the SSH Certificate string representation. - /// - /// - public string ToRepr() - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("SshCert"); + var result = Raw.SshCert.ToRepr(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.SshCert.ToRepr(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -188,44 +190,41 @@ public SshPublicKey GetPublicKey() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCert"); } - Raw.SshPublicKey* retVal = Raw.SshCert.GetPublicKey(_inner); - return new SshPublicKey(retVal); + Raw.SshPublicKey* result = Raw.SshCert.GetPublicKey(AsFFI()); + GC.KeepAlive(this); + return new SshPublicKey(result); } } - /// - /// A SshCertKeyType allocated on C# side. - /// public SshCertKeyType GetSshKeyType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCert"); } - Raw.SshCertKeyType retVal = Raw.SshCert.GetSshKeyType(_inner); - return (SshCertKeyType)retVal; + var result = Raw.SshCert.GetSshKeyType(AsFFI()); + GC.KeepAlive(this); + return result; } } - /// - /// A SshCertType allocated on C# side. - /// public SshCertType GetCertType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCert"); } - Raw.SshCertType retVal = Raw.SshCert.GetCertType(_inner); - return (SshCertType)retVal; + var result = Raw.SshCert.GetCertType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -233,12 +232,13 @@ public ulong GetValidAfter() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCert"); } - ulong retVal = Raw.SshCert.GetValidAfter(_inner); - return retVal; + var result = Raw.SshCert.GetValidAfter(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -246,12 +246,13 @@ public ulong GetValidBefore() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCert"); } - ulong retVal = Raw.SshCert.GetValidBefore(_inner); - return retVal; + var result = Raw.SshCert.GetValidBefore(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -262,31 +263,13 @@ public SshPublicKey GetSignatureKey() { unsafe { - if (_inner == null) - { - throw new ObjectDisposedException("SshCert"); - } - Raw.SshPublicKey* retVal = Raw.SshCert.GetSignatureKey(_inner); - return new SshPublicKey(retVal); - } - } - - /// - public void GetKeyId(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCert"); } - IntPtr resultPtr = Raw.SshCert.GetKeyId(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } + Raw.SshPublicKey* result = Raw.SshCert.GetSignatureKey(AsFFI()); + GC.KeepAlive(this); + return new SshPublicKey(result); } } @@ -295,39 +278,24 @@ public string GetKeyId() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCert"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.SshCert.GetKeyId(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - public void GetComment(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("SshCert"); + var result = Raw.SshCert.GetKeyId(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - IntPtr resultPtr = Raw.SshCert.GetComment(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } @@ -337,30 +305,34 @@ public string GetComment() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCert"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.SshCert.GetComment(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.SshCert.GetComment(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SshCert* AsFFI() + internal unsafe Raw.SshCert* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -370,13 +342,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SshCert.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -386,4 +359,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SshCertBuilder.cs b/ffi/dotnet/Devolutions.Picky/Generated/SshCertBuilder.cs index cbe4832e..3641aa7f 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SshCertBuilder.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SshCertBuilder.cs @@ -1,115 +1,61 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// SSH Certificate Builder. -/// public partial class SshCertBuilder: IDisposable { - private unsafe Raw.SshCertBuilder* _inner; - - public SshCertKeyType CertKeyType - { - set - { - SetCertKeyType(value); - } - } - - public SshCertType CertType - { - set - { - SetCertType(value); - } - } - - public string Comment - { - set - { - SetComment(value); - } - } - - public SshPublicKey Key - { - set - { - SetKey(value); - } - } - - public string KeyId - { - set - { - SetKeyId(value); - } - } - - public ulong Serial - { - set - { - SetSerial(value); - } - } - - public SignatureAlgorithm SignatureAlgo - { - set - { - SetSignatureAlgo(value); - } - } + private unsafe RustHandle _inner; - public SshPrivateKey SignatureKey - { - set - { - SetSignatureKey(value); - } - } - - public ulong ValidAfter - { - set - { - SetValidAfter(value); - } - } + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; - public ulong ValidBefore - { - set - { - SetValidBefore(value); - } - } + private static readonly unsafe RustDestructor _destroy = Raw.SshCertBuilder.Destroy; /// /// Creates a managed SshCertBuilder from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SshCertBuilder(Raw.SshCertBuilder* handle) + internal unsafe SshCertBuilder(Raw.SshCertBuilder* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SshCertBuilder(Raw.SshCertBuilder* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SshCertBuilder(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -119,189 +65,159 @@ public static SshCertBuilder Init() { unsafe { - Raw.SshCertBuilder* retVal = Raw.SshCertBuilder.Init(); - return new SshCertBuilder(retVal); + Raw.SshCertBuilder* result = Raw.SshCertBuilder.Init(); + return new SshCertBuilder(result); } } - /// - /// Required - /// public void SetCertKeyType(SshCertKeyType keyType) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - Raw.SshCertKeyType keyTypeRaw; - keyTypeRaw = (Raw.SshCertKeyType)keyType; - Raw.SshCertBuilder.SetCertKeyType(_inner, keyTypeRaw); + Raw.SshCertBuilder.SetCertKeyType(AsFFI(), keyType); + GC.KeepAlive(this); } } - /// - /// Required - /// public void SetKey(SshPublicKey key) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - Raw.SshPublicKey* keyRaw; - keyRaw = key.AsFFI(); - if (keyRaw == null) - { - throw new ObjectDisposedException("SshPublicKey"); - } - Raw.SshCertBuilder.SetKey(_inner, keyRaw); + if (key == null) throw new ArgumentNullException(nameof(key)); + Raw.SshPublicKey* keyRaw = key.AsFFI(); + if (keyRaw == null) throw new ObjectDisposedException(nameof(SshPublicKey)); + Raw.SshCertBuilder.SetKey(AsFFI(), keyRaw); + GC.KeepAlive(this); + GC.KeepAlive(key); } } - /// - /// Optional (set to 0 by default) - /// public void SetSerial(ulong serial) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - Raw.SshCertBuilder.SetSerial(_inner, serial); + Raw.SshCertBuilder.SetSerial(AsFFI(), serial); + GC.KeepAlive(this); } } - /// - /// Required - /// public void SetCertType(SshCertType certType) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - Raw.SshCertType certTypeRaw; - certTypeRaw = (Raw.SshCertType)certType; - Raw.SshCertBuilder.SetCertType(_inner, certTypeRaw); + Raw.SshCertBuilder.SetCertType(AsFFI(), certType); + GC.KeepAlive(this); } } - /// - /// Optional - /// public void SetKeyId(string keyId) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - byte[] keyIdBuf = DiplomatUtils.StringToUtf8(keyId); - nuint keyIdBufLength = (nuint)keyIdBuf.Length; - fixed (byte* keyIdBufPtr = keyIdBuf) + if (keyId == null) throw new ArgumentNullException(nameof(keyId)); + byte[] keyIdBytes = System.Text.Encoding.UTF8.GetBytes(keyId); + fixed (byte* keyIdPtr = keyIdBytes) { - Raw.SshCertBuilder.SetKeyId(_inner, keyIdBufPtr, keyIdBufLength); + Raw.SshCertBuilder.SetKeyId(AsFFI(), new DiplomatSliceU8 { Ptr = keyIdPtr, Len = (nuint)keyIdBytes.Length }); + GC.KeepAlive(this); } } } - /// - /// Required - /// public void SetValidBefore(ulong validBefore) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - Raw.SshCertBuilder.SetValidBefore(_inner, validBefore); + Raw.SshCertBuilder.SetValidBefore(AsFFI(), validBefore); + GC.KeepAlive(this); } } - /// - /// Required - /// public void SetValidAfter(ulong validAfter) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - Raw.SshCertBuilder.SetValidAfter(_inner, validAfter); + Raw.SshCertBuilder.SetValidAfter(AsFFI(), validAfter); + GC.KeepAlive(this); } } - /// - /// Required - /// public void SetSignatureKey(SshPrivateKey signatureKey) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - Raw.SshPrivateKey* signatureKeyRaw; - signatureKeyRaw = signatureKey.AsFFI(); - if (signatureKeyRaw == null) - { - throw new ObjectDisposedException("SshPrivateKey"); - } - Raw.SshCertBuilder.SetSignatureKey(_inner, signatureKeyRaw); + if (signatureKey == null) throw new ArgumentNullException(nameof(signatureKey)); + Raw.SshPrivateKey* signatureKeyRaw = signatureKey.AsFFI(); + if (signatureKeyRaw == null) throw new ObjectDisposedException(nameof(SshPrivateKey)); + Raw.SshCertBuilder.SetSignatureKey(AsFFI(), signatureKeyRaw); + GC.KeepAlive(this); + GC.KeepAlive(signatureKey); } } - /// - /// Optional. RsaPkcs1v15 with SHA256 is used by default. - /// public void SetSignatureAlgo(SignatureAlgorithm signatureAlgo) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - Raw.SignatureAlgorithm* signatureAlgoRaw; - signatureAlgoRaw = signatureAlgo.AsFFI(); - if (signatureAlgoRaw == null) - { - throw new ObjectDisposedException("SignatureAlgorithm"); - } - Raw.SshCertBuilder.SetSignatureAlgo(_inner, signatureAlgoRaw); + if (signatureAlgo == null) throw new ArgumentNullException(nameof(signatureAlgo)); + Raw.SignatureAlgorithm* signatureAlgoRaw = signatureAlgo.AsFFI(); + if (signatureAlgoRaw == null) throw new ObjectDisposedException(nameof(SignatureAlgorithm)); + Raw.SshCertBuilder.SetSignatureAlgo(AsFFI(), signatureAlgoRaw); + GC.KeepAlive(this); + GC.KeepAlive(signatureAlgo); } } - /// - /// Optional - /// public void SetComment(string comment) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - byte[] commentBuf = DiplomatUtils.StringToUtf8(comment); - nuint commentBufLength = (nuint)commentBuf.Length; - fixed (byte* commentBufPtr = commentBuf) + if (comment == null) throw new ArgumentNullException(nameof(comment)); + byte[] commentBytes = System.Text.Encoding.UTF8.GetBytes(comment); + fixed (byte* commentPtr = commentBytes) { - Raw.SshCertBuilder.SetComment(_inner, commentBufPtr, commentBufLength); + Raw.SshCertBuilder.SetComment(AsFFI(), new DiplomatSliceU8 { Ptr = commentPtr, Len = (nuint)commentBytes.Length }); + GC.KeepAlive(this); } } } @@ -314,28 +230,26 @@ public SshCert Build() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshCertBuilder"); } - IntPtr resultPtr = Raw.SshCertBuilder.Build(_inner); - Raw.SshFfiResultBoxSshCertBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxSshCertBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SshCertBuilder.Build(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SshCert* retVal = result.Ok; - return new SshCert(retVal); + return new SshCert(result.Ok); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SshCertBuilder* AsFFI() + internal unsafe Raw.SshCertBuilder* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -345,13 +259,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SshCertBuilder.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -361,4 +276,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SshCertKeyType.cs b/ffi/dotnet/Devolutions.Picky/Generated/SshCertKeyType.cs index c52821eb..ca2b3a1a 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SshCertKeyType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SshCertKeyType.cs @@ -1,29 +1,15 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// SSH key type. -/// -public enum SshCertKeyType +public enum SshCertKeyType : int { SshRsaV01 = 0, SshDssV01 = 1, - RsaSha2_256V01 = 2, - RsaSha2_512v01 = 3, + RsaSha2256v01 = 2, + RsaSha2512v01 = 3, EcdsaSha2Nistp256V01 = 4, EcdsaSha2Nistp384V01 = 5, EcdsaSha2Nistp521V01 = 6, SshEd25519V01 = 7, SkSshSha2Nistp256V01 = 8, SkSshEd25519V01 = 9, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SshCertType.cs b/ffi/dotnet/Devolutions.Picky/Generated/SshCertType.cs index e1c7c10e..cd6508f7 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SshCertType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SshCertType.cs @@ -1,21 +1,7 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// SSH certificate type. -/// -public enum SshCertType +public enum SshCertType : int { Client = 0, Host = 1, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SshPrivateKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/SshPrivateKey.cs index de80f7f9..d49d49a3 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SshPrivateKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SshPrivateKey.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// SSH Private Key. -/// public partial class SshPrivateKey: IDisposable { - private unsafe Raw.SshPrivateKey* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SshPrivateKey.Destroy; public string CipherName { @@ -38,26 +40,40 @@ public string Comment /// Creates a managed SshPrivateKey from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SshPrivateKey(Raw.SshPrivateKey* handle) + internal unsafe SshPrivateKey(Raw.SshPrivateKey* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - /// Generates a new SSH RSA Private Key. - /// /// - /// No passphrase is set if `passphrase` is empty. - ///
- /// No comment is set if `comment` is empty. - ///
- /// This is slow in debug builds. + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. ///
+ internal unsafe SshPrivateKey(Raw.SshPrivateKey* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe SshPrivateKey(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A SshPrivateKey allocated on Rust side. @@ -66,36 +82,23 @@ public static SshPrivateKey GenerateRsa(nuint bits, string passphrase, string co { unsafe { - byte[] passphraseBuf = DiplomatUtils.StringToUtf8(passphrase); - byte[] commentBuf = DiplomatUtils.StringToUtf8(comment); - nuint passphraseBufLength = (nuint)passphraseBuf.Length; - nuint commentBufLength = (nuint)commentBuf.Length; - fixed (byte* passphraseBufPtr = passphraseBuf) + if (passphrase == null) throw new ArgumentNullException(nameof(passphrase)); + if (comment == null) throw new ArgumentNullException(nameof(comment)); + byte[] passphraseBytes = System.Text.Encoding.UTF8.GetBytes(passphrase); + byte[] commentBytes = System.Text.Encoding.UTF8.GetBytes(comment); + fixed (byte* passphrasePtr = passphraseBytes) + fixed (byte* commentPtr = commentBytes) { - fixed (byte* commentBufPtr = commentBuf) + var result = Raw.SshPrivateKey.GenerateRsa(bits, new DiplomatSliceU8 { Ptr = passphrasePtr, Len = (nuint)passphraseBytes.Length }, new DiplomatSliceU8 { Ptr = commentPtr, Len = (nuint)commentBytes.Length }); + if (!result.IsOk) { - IntPtr resultPtr = Raw.SshPrivateKey.GenerateRsa(bits, passphraseBufPtr, passphraseBufLength, commentBufPtr, commentBufLength); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - Raw.SshPrivateKey* retVal = result.Ok; - return new SshPrivateKey(retVal); + throw new PickyException(new PickyError(result.Err)); } + return new SshPrivateKey(result.Ok); } } } - /// - /// Generates a new SSH EC Private Key. - /// - /// - /// No passphrase is set if `passphrase` is empty. - ///
- /// No comment is set if `comment` is empty. - ///
/// /// /// A SshPrivateKey allocated on Rust side. @@ -104,38 +107,23 @@ public static SshPrivateKey GenerateEc(EcCurve curve, string passphrase, string { unsafe { - byte[] passphraseBuf = DiplomatUtils.StringToUtf8(passphrase); - byte[] commentBuf = DiplomatUtils.StringToUtf8(comment); - nuint passphraseBufLength = (nuint)passphraseBuf.Length; - nuint commentBufLength = (nuint)commentBuf.Length; - Raw.EcCurve curveRaw; - curveRaw = (Raw.EcCurve)curve; - fixed (byte* passphraseBufPtr = passphraseBuf) + if (passphrase == null) throw new ArgumentNullException(nameof(passphrase)); + if (comment == null) throw new ArgumentNullException(nameof(comment)); + byte[] passphraseBytes = System.Text.Encoding.UTF8.GetBytes(passphrase); + byte[] commentBytes = System.Text.Encoding.UTF8.GetBytes(comment); + fixed (byte* passphrasePtr = passphraseBytes) + fixed (byte* commentPtr = commentBytes) { - fixed (byte* commentBufPtr = commentBuf) + var result = Raw.SshPrivateKey.GenerateEc(curve, new DiplomatSliceU8 { Ptr = passphrasePtr, Len = (nuint)passphraseBytes.Length }, new DiplomatSliceU8 { Ptr = commentPtr, Len = (nuint)commentBytes.Length }); + if (!result.IsOk) { - IntPtr resultPtr = Raw.SshPrivateKey.GenerateEc(curveRaw, passphraseBufPtr, passphraseBufLength, commentBufPtr, commentBufLength); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - Raw.SshPrivateKey* retVal = result.Ok; - return new SshPrivateKey(retVal); + throw new PickyException(new PickyError(result.Err)); } + return new SshPrivateKey(result.Ok); } } } - /// - /// Generates a new SSH ed25519 Private Key. - /// - /// - /// No passphrase is set if `passphrase` is empty. - ///
- /// No comment is set if `comment` is empty. - ///
/// /// /// A SshPrivateKey allocated on Rust side. @@ -144,34 +132,23 @@ public static SshPrivateKey GenerateEd25519(string passphrase, string comment) { unsafe { - byte[] passphraseBuf = DiplomatUtils.StringToUtf8(passphrase); - byte[] commentBuf = DiplomatUtils.StringToUtf8(comment); - nuint passphraseBufLength = (nuint)passphraseBuf.Length; - nuint commentBufLength = (nuint)commentBuf.Length; - fixed (byte* passphraseBufPtr = passphraseBuf) + if (passphrase == null) throw new ArgumentNullException(nameof(passphrase)); + if (comment == null) throw new ArgumentNullException(nameof(comment)); + byte[] passphraseBytes = System.Text.Encoding.UTF8.GetBytes(passphrase); + byte[] commentBytes = System.Text.Encoding.UTF8.GetBytes(comment); + fixed (byte* passphrasePtr = passphraseBytes) + fixed (byte* commentPtr = commentBytes) { - fixed (byte* commentBufPtr = commentBuf) + var result = Raw.SshPrivateKey.GenerateEd25519(new DiplomatSliceU8 { Ptr = passphrasePtr, Len = (nuint)passphraseBytes.Length }, new DiplomatSliceU8 { Ptr = commentPtr, Len = (nuint)commentBytes.Length }); + if (!result.IsOk) { - IntPtr resultPtr = Raw.SshPrivateKey.GenerateEd25519(passphraseBufPtr, passphraseBufLength, commentBufPtr, commentBufLength); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - Raw.SshPrivateKey* retVal = result.Ok; - return new SshPrivateKey(retVal); + throw new PickyException(new PickyError(result.Err)); } + return new SshPrivateKey(result.Ok); } } } - /// - /// Extracts SSH Private Key from PEM object. - /// - /// - /// No passphrase is set if `passphrase` is empty. - /// /// /// /// A SshPrivateKey allocated on Rust side. @@ -180,25 +157,20 @@ public static SshPrivateKey FromPem(Pem pem, string passphrase) { unsafe { - byte[] passphraseBuf = DiplomatUtils.StringToUtf8(passphrase); - nuint passphraseBufLength = (nuint)passphraseBuf.Length; - Raw.Pem* pemRaw; - pemRaw = pem.AsFFI(); - if (pemRaw == null) + if (pem == null) throw new ArgumentNullException(nameof(pem)); + Raw.Pem* pemRaw = pem.AsFFI(); + if (pemRaw == null) throw new ObjectDisposedException(nameof(Pem)); + if (passphrase == null) throw new ArgumentNullException(nameof(passphrase)); + byte[] passphraseBytes = System.Text.Encoding.UTF8.GetBytes(passphrase); + fixed (byte* passphrasePtr = passphraseBytes) { - throw new ObjectDisposedException("Pem"); - } - fixed (byte* passphraseBufPtr = passphraseBuf) - { - IntPtr resultPtr = Raw.SshPrivateKey.FromPem(pemRaw, passphraseBufPtr, passphraseBufLength); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SshPrivateKey.FromPem(pemRaw, new DiplomatSliceU8 { Ptr = passphrasePtr, Len = (nuint)passphraseBytes.Length }); + GC.KeepAlive(pem); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SshPrivateKey* retVal = result.Ok; - return new SshPrivateKey(retVal); + return new SshPrivateKey(result.Ok); } } } @@ -211,21 +183,16 @@ public static SshPrivateKey FromKey(PrivateKey key) { unsafe { - Raw.PrivateKey* keyRaw; - keyRaw = key.AsFFI(); - if (keyRaw == null) - { - throw new ObjectDisposedException("PrivateKey"); - } - IntPtr resultPtr = Raw.SshPrivateKey.FromKey(keyRaw); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxSshPrivateKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + if (key == null) throw new ArgumentNullException(nameof(key)); + Raw.PrivateKey* keyRaw = key.AsFFI(); + if (keyRaw == null) throw new ObjectDisposedException(nameof(PrivateKey)); + var result = Raw.SshPrivateKey.FromKey(keyRaw); + GC.KeepAlive(key); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SshPrivateKey* retVal = result.Ok; - return new SshPrivateKey(retVal); + return new SshPrivateKey(result.Ok); } } @@ -236,22 +203,16 @@ public static SshPrivateKey FromKey(PrivateKey key) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPrivateKey"); } - Raw.PrivateKey* retVal = Raw.SshPrivateKey.InnerKey(_inner); - if (retVal == null) - { - return null; - } - return new PrivateKey(retVal); + Raw.PrivateKey* result = Raw.SshPrivateKey.InnerKey(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new PrivateKey(result); } } - /// - /// Exports the SSH Private Key into a PEM object - /// /// /// /// A Pem allocated on Rust side. @@ -260,85 +221,43 @@ public Pem ToPem() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPrivateKey"); } - IntPtr resultPtr = Raw.SshPrivateKey.ToPem(_inner); - Raw.SshFfiResultBoxPemBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxPemBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SshPrivateKey.ToPem(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.Pem* retVal = result.Ok; - return new Pem(retVal); + return new Pem(result.Ok); } } - /// - /// Returns the SSH Private Key string representation. - /// - /// - public void ToRepr(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("SshPrivateKey"); - } - IntPtr resultPtr = Raw.SshPrivateKey.ToRepr(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - /// Returns the SSH Private Key string representation. - /// /// public string ToRepr() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPrivateKey"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.SshPrivateKey.ToRepr(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - public void GetCipherName(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("SshPrivateKey"); + var result = Raw.SshPrivateKey.ToRepr(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - IntPtr resultPtr = Raw.SshPrivateKey.GetCipherName(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } @@ -348,39 +267,24 @@ public string GetCipherName() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPrivateKey"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.SshPrivateKey.GetCipherName(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - public void GetComment(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new ObjectDisposedException("SshPrivateKey"); + var result = Raw.SshPrivateKey.GetCipherName(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - IntPtr resultPtr = Raw.SshPrivateKey.GetComment(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } @@ -390,27 +294,28 @@ public string GetComment() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPrivateKey"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.SshPrivateKey.GetComment(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); + var result = Raw.SshPrivateKey.GetComment(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally + { + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } - /// - /// Extracts the public part of this private key - /// /// /// A SshPublicKey allocated on Rust side. /// @@ -418,21 +323,22 @@ public SshPublicKey ToPublicKey() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPrivateKey"); } - Raw.SshPublicKey* retVal = Raw.SshPrivateKey.ToPublicKey(_inner); - return new SshPublicKey(retVal); + Raw.SshPublicKey* result = Raw.SshPrivateKey.ToPublicKey(AsFFI()); + GC.KeepAlive(this); + return new SshPublicKey(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SshPrivateKey* AsFFI() + internal unsafe Raw.SshPrivateKey* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -442,13 +348,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SshPrivateKey.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -458,4 +365,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/SshPublicKey.cs b/ffi/dotnet/Devolutions.Picky/Generated/SshPublicKey.cs index 5e097f2a..db56d6c3 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/SshPublicKey.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/SshPublicKey.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// SSH Public Key. -/// public partial class SshPublicKey: IDisposable { - private unsafe Raw.SshPublicKey* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.SshPublicKey.Destroy; public string Comment { @@ -30,19 +32,40 @@ public string Comment /// Creates a managed SshPublicKey from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe SshPublicKey(Raw.SshPublicKey* handle) + internal unsafe SshPublicKey(Raw.SshPublicKey* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe SshPublicKey(Raw.SshPublicKey* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; } /// - /// Parses string representation of a SSH Public Key. + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. /// + internal unsafe SshPublicKey(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; + } + /// /// /// A SshPublicKey allocated on Rust side. @@ -51,96 +74,43 @@ public static SshPublicKey Parse(string repr) { unsafe { - byte[] reprBuf = DiplomatUtils.StringToUtf8(repr); - nuint reprBufLength = (nuint)reprBuf.Length; - fixed (byte* reprBufPtr = reprBuf) + if (repr == null) throw new ArgumentNullException(nameof(repr)); + byte[] reprBytes = System.Text.Encoding.UTF8.GetBytes(repr); + fixed (byte* reprPtr = reprBytes) { - IntPtr resultPtr = Raw.SshPublicKey.Parse(reprBufPtr, reprBufLength); - Raw.SshFfiResultBoxSshPublicKeyBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxSshPublicKeyBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SshPublicKey.Parse(new DiplomatSliceU8 { Ptr = reprPtr, Len = (nuint)reprBytes.Length }); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.SshPublicKey* retVal = result.Ok; - return new SshPublicKey(retVal); + return new SshPublicKey(result.Ok); } } } - /// - /// Returns the SSH Public Key string representation. - /// - /// - /// It is generally represented as: - /// "(algorithm) (der for the key) (comment)" - /// where (comment) is usually an email address. - /// - /// - public void ToRepr(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("SshPublicKey"); - } - IntPtr resultPtr = Raw.SshPublicKey.ToRepr(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } - } - - /// - /// Returns the SSH Public Key string representation. - /// - /// - /// It is generally represented as: - /// "(algorithm) (der for the key) (comment)" - /// where (comment) is usually an email address. - /// /// public string ToRepr() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPublicKey"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.SshPublicKey.ToRepr(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; - } - } - - /// - public void GetComment(DiplomatWriteable writeable) - { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("SshPublicKey"); + var result = Raw.SshPublicKey.ToRepr(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - IntPtr resultPtr = Raw.SshPublicKey.GetComment(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } } } @@ -150,21 +120,25 @@ public string GetComment() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPublicKey"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.SshPublicKey.GetComment(_inner, &writeable); - Raw.SshFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); + var result = Raw.SshPublicKey.GetComment(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally + { + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -176,19 +150,17 @@ public VecU8 FingerprintMd5() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPublicKey"); } - IntPtr resultPtr = Raw.SshPublicKey.FingerprintMd5(_inner); - Raw.SshFfiResultBoxVecU8BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxVecU8BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SshPublicKey.FingerprintMd5(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.VecU8* retVal = result.Ok; - return new VecU8(retVal); + return new VecU8(result.Ok); } } @@ -200,19 +172,17 @@ public VecU8 FingerprintSha1() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPublicKey"); } - IntPtr resultPtr = Raw.SshPublicKey.FingerprintSha1(_inner); - Raw.SshFfiResultBoxVecU8BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxVecU8BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SshPublicKey.FingerprintSha1(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.VecU8* retVal = result.Ok; - return new VecU8(retVal); + return new VecU8(result.Ok); } } @@ -224,28 +194,26 @@ public VecU8 FingerprintSha256() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("SshPublicKey"); } - IntPtr resultPtr = Raw.SshPublicKey.FingerprintSha256(_inner); - Raw.SshFfiResultBoxVecU8BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.SshFfiResultBoxVecU8BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.SshPublicKey.FingerprintSha256(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.VecU8* retVal = result.Ok; - return new VecU8(retVal); + return new VecU8(result.Ok); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.SshPublicKey* AsFFI() + internal unsafe Raw.SshPublicKey* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -255,13 +223,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.SshPublicKey.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -271,4 +240,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/StringIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/StringIterator.cs index 120da13e..86ac4c72 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/StringIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/StringIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,39 +10,52 @@ namespace Devolutions.Picky; public partial class StringIterator: IDisposable { - private unsafe Raw.StringIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.StringIterator.Destroy; /// /// Creates a managed StringIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe StringIterator(Raw.StringIterator* handle) + internal unsafe StringIterator(Raw.StringIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void Next(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe StringIterator(Raw.StringIterator* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("StringIterator"); - } - IntPtr resultPtr = Raw.StringIterator.Next(_inner, &writable); - Raw.UtilsFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.UtilsFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe StringIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -53,30 +63,34 @@ public string Next() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("StringIterator"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.StringIterator.Next(_inner, &writeable); - Raw.UtilsFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.UtilsFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.StringIterator.Next(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.StringIterator* AsFFI() + internal unsafe Raw.StringIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -86,13 +100,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.StringIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -102,4 +117,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/StringNestedIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/StringNestedIterator.cs index 6b5d67fe..2379d643 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/StringNestedIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/StringNestedIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class StringNestedIterator: IDisposable { - private unsafe Raw.StringNestedIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.StringNestedIterator.Destroy; /// /// Creates a managed StringNestedIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe StringNestedIterator(Raw.StringNestedIterator* handle) + internal unsafe StringNestedIterator(Raw.StringNestedIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe StringNestedIterator(Raw.StringNestedIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe StringNestedIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe StringNestedIterator(Raw.StringNestedIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("StringNestedIterator"); } - Raw.StringIterator* retVal = Raw.StringNestedIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new StringIterator(retVal); + Raw.StringIterator* result = Raw.StringNestedIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new StringIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.StringNestedIterator* AsFFI() + internal unsafe Raw.StringNestedIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.StringNestedIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/TbsCertList.cs b/ffi/dotnet/Devolutions.Picky/Generated/TbsCertList.cs index 8c7db40b..438369bd 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/TbsCertList.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/TbsCertList.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class TbsCertList: IDisposable { - private unsafe Raw.TbsCertList* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.TbsCertList.Destroy; public ExtensionIterator? Extenstions { @@ -75,29 +80,51 @@ public Version Version /// Creates a managed TbsCertList from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe TbsCertList(Raw.TbsCertList* handle) + internal unsafe TbsCertList(Raw.TbsCertList* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe TbsCertList(Raw.TbsCertList* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe TbsCertList(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A Version allocated on C# side. - /// public Version GetVersion() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("TbsCertList"); } - Raw.Version retVal = Raw.TbsCertList.GetVersion(_inner); - return (Version)retVal; + var result = Raw.TbsCertList.GetVersion(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -108,54 +135,40 @@ public AlgorithmIdentifier GetSignatureAlgorithm() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("TbsCertList"); } - Raw.AlgorithmIdentifier* retVal = Raw.TbsCertList.GetSignatureAlgorithm(_inner); - return new AlgorithmIdentifier(retVal); + Raw.AlgorithmIdentifier* result = Raw.TbsCertList.GetSignatureAlgorithm(AsFFI()); + GC.KeepAlive(this); + return new AlgorithmIdentifier(result); } } /// - public void GetIssuer(DiplomatWriteable writable) + public string GetIssuer() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("TbsCertList"); } - IntPtr resultPtr = Raw.TbsCertList.GetIssuer(_inner, &writable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try { - throw new PickyException(new PickyError(result.Err)); + var result = Raw.TbsCertList.GetIssuer(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); } - } - } - - /// - public string GetIssuer() - { - unsafe - { - if (_inner == null) + finally { - throw new ObjectDisposedException("TbsCertList"); + writeable.Dispose(); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.TbsCertList.GetIssuer(_inner, &writeable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -166,12 +179,13 @@ public Time GetThisUpate() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("TbsCertList"); } - Raw.Time* retVal = Raw.TbsCertList.GetThisUpate(_inner); - return new Time(retVal); + Raw.Time* result = Raw.TbsCertList.GetThisUpate(AsFFI()); + GC.KeepAlive(this); + return new Time(result); } } @@ -182,16 +196,13 @@ public Time GetThisUpate() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("TbsCertList"); } - Raw.Time* retVal = Raw.TbsCertList.GetNextUpdate(_inner); - if (retVal == null) - { - return null; - } - return new Time(retVal); + Raw.Time* result = Raw.TbsCertList.GetNextUpdate(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new Time(result); } } @@ -202,16 +213,13 @@ public Time GetThisUpate() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("TbsCertList"); } - Raw.RevokedCertificateIterator* retVal = Raw.TbsCertList.GetRevokedCertificates(_inner); - if (retVal == null) - { - return null; - } - return new RevokedCertificateIterator(retVal); + Raw.RevokedCertificateIterator* result = Raw.TbsCertList.GetRevokedCertificates(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new RevokedCertificateIterator(result); } } @@ -222,25 +230,22 @@ public Time GetThisUpate() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("TbsCertList"); } - Raw.ExtensionIterator* retVal = Raw.TbsCertList.GetExtenstions(_inner); - if (retVal == null) - { - return null; - } - return new ExtensionIterator(retVal); + Raw.ExtensionIterator* result = Raw.TbsCertList.GetExtenstions(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new ExtensionIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.TbsCertList* AsFFI() + internal unsafe Raw.TbsCertList* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -250,13 +255,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.TbsCertList.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -266,4 +272,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Time.cs b/ffi/dotnet/Devolutions.Picky/Generated/Time.cs index 613e55c0..9832e524 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Time.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Time.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class Time: IDisposable { - private unsafe Raw.Time* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.Time.Destroy; public byte Day { @@ -67,26 +72,51 @@ public ushort Year /// Creates a managed Time from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe Time(Raw.Time* handle) + internal unsafe Time(Raw.Time* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe Time(Raw.Time* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe Time(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } public ushort GetYear() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Time"); } - ushort retVal = Raw.Time.GetYear(_inner); - return retVal; + var result = Raw.Time.GetYear(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -94,12 +124,13 @@ public byte GetMonth() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Time"); } - byte retVal = Raw.Time.GetMonth(_inner); - return retVal; + var result = Raw.Time.GetMonth(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -107,12 +138,13 @@ public byte GetDay() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Time"); } - byte retVal = Raw.Time.GetDay(_inner); - return retVal; + var result = Raw.Time.GetDay(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -120,12 +152,13 @@ public byte GetHour() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Time"); } - byte retVal = Raw.Time.GetHour(_inner); - return retVal; + var result = Raw.Time.GetHour(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -133,12 +166,13 @@ public byte GetMinute() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Time"); } - byte retVal = Raw.Time.GetMinute(_inner); - return retVal; + var result = Raw.Time.GetMinute(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -146,12 +180,13 @@ public byte GetSecond() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Time"); } - byte retVal = Raw.Time.GetSecond(_inner); - return retVal; + var result = Raw.Time.GetSecond(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -159,12 +194,13 @@ public bool IsUtc() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Time"); } - bool retVal = Raw.Time.IsUtc(_inner); - return retVal; + var result = Raw.Time.IsUtc(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -172,21 +208,22 @@ public bool IsGeneralized() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Time"); } - bool retVal = Raw.Time.IsGeneralized(_inner); - return retVal; + var result = Raw.Time.IsGeneralized(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.Time* AsFFI() + internal unsafe Raw.Time* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -196,13 +233,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.Time.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -212,4 +250,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/U8.cs b/ffi/dotnet/Devolutions.Picky/Generated/U8.cs index ff6c965c..18fe3aae 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/U8.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/U8.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// TODO: this could be fixed with future diplomat-tool Diplomat disallow Opion where T is a primitive type, so we need to wrap it in a pointer -/// public partial class U8: IDisposable { - private unsafe Raw.U8* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.U8.Destroy; public byte Value { @@ -30,35 +32,60 @@ public byte Value /// Creates a managed U8 from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe U8(Raw.U8* handle) + internal unsafe U8(Raw.U8* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe U8(Raw.U8* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe U8(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } public byte GetValue() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("U8"); } - byte retVal = Raw.U8.GetValue(_inner); - return retVal; + var result = Raw.U8.GetValue(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.U8* AsFFI() + internal unsafe Raw.U8* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -68,13 +95,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.U8.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -84,4 +112,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/UTCTime.cs b/ffi/dotnet/Devolutions.Picky/Generated/UTCTime.cs index 429bc8fd..3583bde6 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/UTCTime.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/UTCTime.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class UTCTime: IDisposable { - private unsafe Raw.UTCTime* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.UTCTime.Destroy; public byte Day { @@ -67,26 +72,51 @@ public ushort Year /// Creates a managed UTCTime from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe UTCTime(Raw.UTCTime* handle) + internal unsafe UTCTime(Raw.UTCTime* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe UTCTime(Raw.UTCTime* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe UTCTime(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } public ushort GetYear() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UTCTime"); } - ushort retVal = Raw.UTCTime.GetYear(_inner); - return retVal; + var result = Raw.UTCTime.GetYear(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -94,12 +124,13 @@ public byte GetMonth() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UTCTime"); } - byte retVal = Raw.UTCTime.GetMonth(_inner); - return retVal; + var result = Raw.UTCTime.GetMonth(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -107,12 +138,13 @@ public byte GetDay() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UTCTime"); } - byte retVal = Raw.UTCTime.GetDay(_inner); - return retVal; + var result = Raw.UTCTime.GetDay(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -120,12 +152,13 @@ public byte GetHour() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UTCTime"); } - byte retVal = Raw.UTCTime.GetHour(_inner); - return retVal; + var result = Raw.UTCTime.GetHour(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -133,12 +166,13 @@ public byte GetMinute() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UTCTime"); } - byte retVal = Raw.UTCTime.GetMinute(_inner); - return retVal; + var result = Raw.UTCTime.GetMinute(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -146,21 +180,22 @@ public byte GetSecond() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UTCTime"); } - byte retVal = Raw.UTCTime.GetSecond(_inner); - return retVal; + var result = Raw.UTCTime.GetSecond(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.UTCTime* AsFFI() + internal unsafe Raw.UTCTime* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -170,13 +205,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.UTCTime.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -186,4 +222,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/UTCTimeIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/UTCTimeIterator.cs index daae7ff1..d9c2a675 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/UTCTimeIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/UTCTimeIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class UTCTimeIterator: IDisposable { - private unsafe Raw.UTCTimeIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.UTCTimeIterator.Destroy; /// /// Creates a managed UTCTimeIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe UTCTimeIterator(Raw.UTCTimeIterator* handle) + internal unsafe UTCTimeIterator(Raw.UTCTimeIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe UTCTimeIterator(Raw.UTCTimeIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe UTCTimeIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe UTCTimeIterator(Raw.UTCTimeIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UTCTimeIterator"); } - Raw.UTCTime* retVal = Raw.UTCTimeIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new UTCTime(retVal); + Raw.UTCTime* result = Raw.UTCTimeIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new UTCTime(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.UTCTimeIterator* AsFFI() + internal unsafe Raw.UTCTimeIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.UTCTimeIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttribute.cs b/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttribute.cs index 326d1835..bd169366 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttribute.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttribute.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class UnsignedAttribute: IDisposable { - private unsafe Raw.UnsignedAttribute* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.UnsignedAttribute.Destroy; public string Type { @@ -35,33 +40,38 @@ public UnsignedAttributeValue Values /// Creates a managed UnsignedAttribute from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe UnsignedAttribute(Raw.UnsignedAttribute* handle) + internal unsafe UnsignedAttribute(Raw.UnsignedAttribute* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); } - /// - public void GetType(DiplomatWriteable writable) + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe UnsignedAttribute(Raw.UnsignedAttribute* handle, object[] edges) { - unsafe - { - if (_inner == null) - { - throw new ObjectDisposedException("UnsignedAttribute"); - } - IntPtr resultPtr = Raw.UnsignedAttribute.GetType(_inner, &writable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) - { - throw new PickyException(new PickyError(result.Err)); - } - } + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe UnsignedAttribute(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -69,21 +79,25 @@ public string GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UnsignedAttribute"); } - DiplomatWriteable writeable = new DiplomatWriteable(); - IntPtr resultPtr = Raw.UnsignedAttribute.GetType(_inner, &writeable); - Raw.X509AttributeFfiResultVoidBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.X509AttributeFfiResultVoidBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + DiplomatWrite writeable = new DiplomatWrite(); + try + { + var result = Raw.UnsignedAttribute.GetType(AsFFI(), &writeable); + GC.KeepAlive(this); + if (!result.IsOk) + { + throw new PickyException(new PickyError(result.Err)); + } + return writeable.ToUnicode(); + } + finally { - throw new PickyException(new PickyError(result.Err)); + writeable.Dispose(); } - string retVal = writeable.ToUnicode(); - writeable.Dispose(); - return retVal; } } @@ -94,21 +108,22 @@ public UnsignedAttributeValue GetValues() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UnsignedAttribute"); } - Raw.UnsignedAttributeValue* retVal = Raw.UnsignedAttribute.GetValues(_inner); - return new UnsignedAttributeValue(retVal); + Raw.UnsignedAttributeValue* result = Raw.UnsignedAttribute.GetValues(AsFFI()); + GC.KeepAlive(this); + return new UnsignedAttributeValue(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.UnsignedAttribute* AsFFI() + internal unsafe Raw.UnsignedAttribute* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -118,13 +133,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.UnsignedAttribute.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -134,4 +150,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeIterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeIterator.cs index 3f743ab6..97eacb53 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeIterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeIterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class UnsignedAttributeIterator: IDisposable { - private unsafe Raw.UnsignedAttributeIterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.UnsignedAttributeIterator.Destroy; /// /// Creates a managed UnsignedAttributeIterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe UnsignedAttributeIterator(Raw.UnsignedAttributeIterator* handle) + internal unsafe UnsignedAttributeIterator(Raw.UnsignedAttributeIterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe UnsignedAttributeIterator(Raw.UnsignedAttributeIterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe UnsignedAttributeIterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe UnsignedAttributeIterator(Raw.UnsignedAttributeIterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UnsignedAttributeIterator"); } - Raw.UnsignedAttribute* retVal = Raw.UnsignedAttributeIterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new UnsignedAttribute(retVal); + Raw.UnsignedAttribute* result = Raw.UnsignedAttributeIterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new UnsignedAttribute(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.UnsignedAttributeIterator* AsFFI() + internal unsafe Raw.UnsignedAttributeIterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.UnsignedAttributeIterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeValue.cs b/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeValue.cs index ee0e8f83..81e0dbdd 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeValue.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeValue.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class UnsignedAttributeValue: IDisposable { - private unsafe Raw.UnsignedAttributeValue* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.UnsignedAttributeValue.Destroy; public UnsignedAttributeValueType Type { @@ -27,29 +32,51 @@ public UnsignedAttributeValueType Type /// Creates a managed UnsignedAttributeValue from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe UnsignedAttributeValue(Raw.UnsignedAttributeValue* handle) + internal unsafe UnsignedAttributeValue(Raw.UnsignedAttributeValue* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe UnsignedAttributeValue(Raw.UnsignedAttributeValue* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe UnsignedAttributeValue(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } - /// - /// A UnsignedAttributeValueType allocated on C# side. - /// public UnsignedAttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UnsignedAttributeValue"); } - Raw.UnsignedAttributeValueType retVal = Raw.UnsignedAttributeValue.GetType(_inner); - return (UnsignedAttributeValueType)retVal; + var result = Raw.UnsignedAttributeValue.GetType(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -60,16 +87,13 @@ public UnsignedAttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UnsignedAttributeValue"); } - Raw.MsCounterSignIterator* retVal = Raw.UnsignedAttributeValue.ToMsCounterSign(_inner); - if (retVal == null) - { - return null; - } - return new MsCounterSignIterator(retVal); + Raw.MsCounterSignIterator* result = Raw.UnsignedAttributeValue.ToMsCounterSign(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new MsCounterSignIterator(result); } } @@ -80,25 +104,22 @@ public UnsignedAttributeValueType GetType() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UnsignedAttributeValue"); } - Raw.SignerInfoIterator* retVal = Raw.UnsignedAttributeValue.ToCounterSign(_inner); - if (retVal == null) - { - return null; - } - return new SignerInfoIterator(retVal); + Raw.SignerInfoIterator* result = Raw.UnsignedAttributeValue.ToCounterSign(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new SignerInfoIterator(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.UnsignedAttributeValue* AsFFI() + internal unsafe Raw.UnsignedAttributeValue* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -108,13 +129,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.UnsignedAttributeValue.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -124,4 +146,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeValueType.cs b/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeValueType.cs index aaf8ea62..2e6b6e4b 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeValueType.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/UnsignedAttributeValueType.cs @@ -1,18 +1,7 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -public enum UnsignedAttributeValueType +public enum UnsignedAttributeValueType : int { MsCounterSign = 0, CounterSign = 1, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/UtcDate.cs b/ffi/dotnet/Devolutions.Picky/Generated/UtcDate.cs index 2af743d3..291e5ca7 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/UtcDate.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/UtcDate.cs @@ -1,22 +1,24 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; #nullable enable -/// -/// UTC date and time. -/// public partial class UtcDate: IDisposable { - private unsafe Raw.UtcDate* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.UtcDate.Destroy; public byte Day { @@ -78,14 +80,38 @@ public ushort Year /// Creates a managed UtcDate from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe UtcDate(Raw.UtcDate* handle) + internal unsafe UtcDate(Raw.UtcDate* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe UtcDate(Raw.UtcDate* handle, object[] edges) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe UtcDate(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -95,12 +121,8 @@ public unsafe UtcDate(Raw.UtcDate* handle) { unsafe { - Raw.UtcDate* retVal = Raw.UtcDate.New(year, month, day, hour, minute, second); - if (retVal == null) - { - return null; - } - return new UtcDate(retVal); + Raw.UtcDate* result = Raw.UtcDate.New(year, month, day, hour, minute, second); + return result == null ? null : new UtcDate(result); } } @@ -111,12 +133,8 @@ public unsafe UtcDate(Raw.UtcDate* handle) { unsafe { - Raw.UtcDate* retVal = Raw.UtcDate.Ymd(year, month, day); - if (retVal == null) - { - return null; - } - return new UtcDate(retVal); + Raw.UtcDate* result = Raw.UtcDate.Ymd(year, month, day); + return result == null ? null : new UtcDate(result); } } @@ -127,8 +145,8 @@ public static UtcDate Now() { unsafe { - Raw.UtcDate* retVal = Raw.UtcDate.Now(); - return new UtcDate(retVal); + Raw.UtcDate* result = Raw.UtcDate.Now(); + return new UtcDate(result); } } @@ -140,15 +158,12 @@ public static UtcDate FromTimestamp(long timestamp) { unsafe { - IntPtr resultPtr = Raw.UtcDate.FromTimestamp(timestamp); - Raw.DateFfiResultBoxUtcDateBoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.DateFfiResultBoxUtcDateBoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.UtcDate.FromTimestamp(timestamp); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - Raw.UtcDate* retVal = result.Ok; - return new UtcDate(retVal); + return new UtcDate(result.Ok); } } @@ -157,19 +172,17 @@ public long GetTimestamp() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UtcDate"); } - IntPtr resultPtr = Raw.UtcDate.GetTimestamp(_inner); - Raw.DateFfiResultI64BoxPickyError result = Marshal.PtrToStructure(resultPtr); - Raw.DateFfiResultI64BoxPickyError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.UtcDate.GetTimestamp(AsFFI()); + GC.KeepAlive(this); + if (!result.IsOk) { throw new PickyException(new PickyError(result.Err)); } - long retVal = result.Ok; - return retVal; + return result.Ok; } } @@ -177,12 +190,13 @@ public byte GetMonth() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UtcDate"); } - byte retVal = Raw.UtcDate.GetMonth(_inner); - return retVal; + var result = Raw.UtcDate.GetMonth(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -190,12 +204,13 @@ public byte GetDay() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UtcDate"); } - byte retVal = Raw.UtcDate.GetDay(_inner); - return retVal; + var result = Raw.UtcDate.GetDay(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -203,12 +218,13 @@ public byte GetHour() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UtcDate"); } - byte retVal = Raw.UtcDate.GetHour(_inner); - return retVal; + var result = Raw.UtcDate.GetHour(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -216,12 +232,13 @@ public byte GetMinute() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UtcDate"); } - byte retVal = Raw.UtcDate.GetMinute(_inner); - return retVal; + var result = Raw.UtcDate.GetMinute(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -229,12 +246,13 @@ public byte GetSecond() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UtcDate"); } - byte retVal = Raw.UtcDate.GetSecond(_inner); - return retVal; + var result = Raw.UtcDate.GetSecond(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -242,21 +260,22 @@ public ushort GetYear() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("UtcDate"); } - ushort retVal = Raw.UtcDate.GetYear(_inner); - return retVal; + var result = Raw.UtcDate.GetYear(AsFFI()); + GC.KeepAlive(this); + return result; } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.UtcDate* AsFFI() + internal unsafe Raw.UtcDate* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -266,13 +285,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.UtcDate.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -282,4 +302,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/VecU8.cs b/ffi/dotnet/Devolutions.Picky/Generated/VecU8.cs index 650f3189..39106e5c 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/VecU8.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/VecU8.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,7 +10,15 @@ namespace Devolutions.Picky; public partial class VecU8: IDisposable { - private unsafe Raw.VecU8* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.VecU8.Destroy; public nuint Length { @@ -27,14 +32,38 @@ public nuint Length /// Creates a managed VecU8 from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe VecU8(Raw.VecU8* handle) + internal unsafe VecU8(Raw.VecU8* handle) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe VecU8(Raw.VecU8* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe VecU8(RustHandle inner, object[] edges) { - _inner = handle; + _inner = inner; + _edges = edges; } /// @@ -44,11 +73,11 @@ public static VecU8 FromBytes(byte[] bytes) { unsafe { - nuint bytesLength = (nuint)bytes.Length; + if (bytes == null) throw new ArgumentNullException(nameof(bytes)); fixed (byte* bytesPtr = bytes) { - Raw.VecU8* retVal = Raw.VecU8.FromBytes(bytesPtr, bytesLength); - return new VecU8(retVal); + Raw.VecU8* result = Raw.VecU8.FromBytes(new DiplomatSliceU8 { Ptr = bytesPtr, Len = (nuint)bytes.Length }); + return new VecU8(result); } } } @@ -57,12 +86,13 @@ public nuint GetLength() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("VecU8"); } - nuint retVal = Raw.VecU8.GetLength(_inner); - return retVal; + var result = Raw.VecU8.GetLength(AsFFI()); + GC.KeepAlive(this); + return result; } } @@ -71,20 +101,20 @@ public void Fill(byte[] buffer) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("VecU8"); } - nuint bufferLength = (nuint)buffer.Length; + if (buffer == null) throw new ArgumentNullException(nameof(buffer)); fixed (byte* bufferPtr = buffer) { - IntPtr resultPtr = Raw.VecU8.Fill(_inner, bufferPtr, bufferLength); - Raw.UtilsFfiResultVoidBoxBufferTooSmallError result = Marshal.PtrToStructure(resultPtr); - Raw.UtilsFfiResultVoidBoxBufferTooSmallError.Destroy(resultPtr); - if (!result.isOk) + var result = Raw.VecU8.Fill(AsFFI(), new DiplomatSliceMutU8 { Ptr = bufferPtr, Len = (nuint)buffer.Length }); + GC.KeepAlive(this); + if (!result.IsOk) { throw new BufferTooSmallException(new BufferTooSmallError(result.Err)); } + return; } } } @@ -92,9 +122,9 @@ public void Fill(byte[] buffer) /// /// Returns the underlying raw handle. /// - public unsafe Raw.VecU8* AsFFI() + internal unsafe Raw.VecU8* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -104,13 +134,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.VecU8.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -120,4 +151,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/VecU8Iterator.cs b/ffi/dotnet/Devolutions.Picky/Generated/VecU8Iterator.cs index a4edc7d0..eb85c4c5 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/VecU8Iterator.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/VecU8Iterator.cs @@ -1,11 +1,8 @@ // by Diplomat -#pragma warning disable 0105 using System; using System.Runtime.InteropServices; - using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 namespace Devolutions.Picky; @@ -13,20 +10,52 @@ namespace Devolutions.Picky; public partial class VecU8Iterator: IDisposable { - private unsafe Raw.VecU8Iterator* _inner; + private unsafe RustHandle _inner; + + /// + /// Roots the wrappers this value borrows from so the GC cannot finalize + /// a borrowed-from parent while this value is alive. + /// + private object[] _edges; + + private static readonly unsafe RustDestructor _destroy = Raw.VecU8Iterator.Destroy; /// /// Creates a managed VecU8Iterator from a raw handle. /// /// - /// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). + /// Safety: you should not build two managed objects using the same raw handle (may cause use-after-free and double-free). ///
/// This constructor assumes the raw struct is allocated on Rust side. /// If implemented, the custom Drop implementation on Rust side WILL run on destruction. ///
- public unsafe VecU8Iterator(Raw.VecU8Iterator* handle) + internal unsafe VecU8Iterator(Raw.VecU8Iterator* handle) { - _inner = handle; + _inner = RustHandle.Owned(handle, _destroy); + _edges = System.Array.Empty(); + } + + /// + /// Edges only keep the borrowed-from objects GC-reachable. Explicitly + /// Dispose-ing a parent while a borrowing child is in use is still a + /// use-after-free and remains the caller's responsibility. + /// + internal unsafe VecU8Iterator(Raw.VecU8Iterator* handle, object[] edges) + { + _inner = RustHandle.Owned(handle, _destroy); + _edges = edges; + } + + /// + /// Wraps a handle that already knows whether it owns the pointer. A + /// borrowed return passes a non-owning handle, so Dispose and the finalizer + /// leave Rust's pointer alone; the edges keep the borrowed-from owners alive + /// while this view is in use. + /// + internal unsafe VecU8Iterator(RustHandle inner, object[] edges) + { + _inner = inner; + _edges = edges; } /// @@ -36,25 +65,22 @@ public unsafe VecU8Iterator(Raw.VecU8Iterator* handle) { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("VecU8Iterator"); } - Raw.VecU8* retVal = Raw.VecU8Iterator.Next(_inner); - if (retVal == null) - { - return null; - } - return new VecU8(retVal); + Raw.VecU8* result = Raw.VecU8Iterator.Next(AsFFI()); + GC.KeepAlive(this); + return result == null ? null : new VecU8(result); } } /// /// Returns the underlying raw handle. /// - public unsafe Raw.VecU8Iterator* AsFFI() + internal unsafe Raw.VecU8Iterator* AsFFI() { - return _inner; + return _inner.Ptr; } /// @@ -64,13 +90,14 @@ public void Dispose() { unsafe { - if (_inner == null) + if (_inner.IsNull) { return; } - Raw.VecU8Iterator.Destroy(_inner); - _inner = null; + _inner.Release(); + _inner = default; + _edges = System.Array.Empty(); // release refs so borrowed-from owners can be GC'd GC.SuppressFinalize(this); } @@ -80,4 +107,4 @@ public void Dispose() { Dispose(); } -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/Generated/Version.cs b/ffi/dotnet/Devolutions.Picky/Generated/Version.cs index a49ace07..99e655c7 100644 --- a/ffi/dotnet/Devolutions.Picky/Generated/Version.cs +++ b/ffi/dotnet/Devolutions.Picky/Generated/Version.cs @@ -1,23 +1,9 @@ -// by Diplomat - -#pragma warning disable 0105 -using System; -using System.Runtime.InteropServices; - -using Devolutions.Picky.Diplomat; -#pragma warning restore 0105 - namespace Devolutions.Picky; -#nullable enable - -/// -/// TODO: this could be lifted in future diplomat-tool, Diplomat does not allow Option wrapped enums, so we have to use a None variant -/// -public enum Version +public enum Version : int { None = 0, V1 = 1, V2 = 2, V3 = 3, -} +} \ No newline at end of file diff --git a/ffi/dotnet/Devolutions.Picky/src/Pem.Addons.cs b/ffi/dotnet/Devolutions.Picky/src/Pem.Addons.cs index e863b03a..56f8a95e 100644 --- a/ffi/dotnet/Devolutions.Picky/src/Pem.Addons.cs +++ b/ffi/dotnet/Devolutions.Picky/src/Pem.Addons.cs @@ -22,13 +22,13 @@ public byte[] ToData() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pem"); } nuint dataLen; - IntPtr dataPtr = PeekData(_inner, out dataLen); + IntPtr dataPtr = PeekData(_inner.Ptr, out dataLen); byte[] retVal = new byte[dataLen]; Marshal.Copy(dataPtr, retVal, 0, (int)dataLen); diff --git a/ffi/dotnet/Devolutions.Picky/src/Pfx.Addons.cs b/ffi/dotnet/Devolutions.Picky/src/Pfx.Addons.cs index 8178e08e..59276801 100644 --- a/ffi/dotnet/Devolutions.Picky/src/Pfx.Addons.cs +++ b/ffi/dotnet/Devolutions.Picky/src/Pfx.Addons.cs @@ -39,19 +39,19 @@ public byte[] ToDer() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("Pfx"); } - nuint count = Pfx_der_encoded_len(_inner); + nuint count = Pfx_der_encoded_len(_inner.Ptr); byte[] der = new byte[count]; Raw.PickyError* error; fixed (byte* derPtr = der) { - error = Pfx_to_der(_inner, derPtr, count); + error = Pfx_to_der(_inner.Ptr, derPtr, count); } if (error != null) diff --git a/ffi/dotnet/Devolutions.Picky/src/PublicKey.Addons.cs b/ffi/dotnet/Devolutions.Picky/src/PublicKey.Addons.cs index 76a38198..8546a059 100644 --- a/ffi/dotnet/Devolutions.Picky/src/PublicKey.Addons.cs +++ b/ffi/dotnet/Devolutions.Picky/src/PublicKey.Addons.cs @@ -39,19 +39,19 @@ public byte[] ToPkcs1() { unsafe { - if (_inner == null) + if (_inner.IsNull) { throw new ObjectDisposedException("PublicKey"); } - nuint count = PublicKey_pkcs1_encoded_len(_inner); + nuint count = PublicKey_pkcs1_encoded_len(_inner.Ptr); byte[] pkcs1 = new byte[count]; Raw.PickyError* error; fixed (byte* pkcs1Ptr = pkcs1) { - error = PublicKey_to_pkcs1(_inner, pkcs1Ptr, count); + error = PublicKey_to_pkcs1(_inner.Ptr, pkcs1Ptr, count); } if (error != null) diff --git a/ffi/justfile b/ffi/justfile index 3efe69ae..877bb463 100755 --- a/ffi/justfile +++ b/ffi/justfile @@ -13,16 +13,15 @@ default: bindings ## Diplomat installation ## -# For now, we need to use a custom diplomat revision -# supporting dotnet framework 4.7. -# Indeed, in older frameworks a few important types -# are not blittables, causing Result types to not be -# correctly send at the FFI boundary. -diplomat_repo := "https://github.com/CBenoit/diplomat.git" -diplomat_rev := "f4d93d57e93025c57e75e9711d2418faa9311a42" +# Pinned to the .NET blittable-bool fix (rust-diplomat/diplomat#1226) so Result +# and Option marshal on .NET Framework. Points at the fork until it lands +# upstream; switch back to a plain rust-diplomat rev once it's merged. +diplomat_repo := "https://github.com/irvingoujAtDevolution/diplomat.git" +diplomat_rev := "68bccfd8d61e146673ccdb2b24bd9f89dc25431c" +# diplomat-tool's `hir` codegen uses `if let` guards, which are still nightly-only. diplomat-install: - cargo install --git {{diplomat_repo}} --rev {{diplomat_rev}} diplomat-tool -f + cargo +nightly install --git {{diplomat_repo}} --rev {{diplomat_rev}} diplomat-tool -f diplomat-sanity: @echo ">> Check Diplomat revision" @@ -100,7 +99,7 @@ bindings: dotnet-bindings dotnet-bindings: -rm {{dotnet_generated_path}}*.cs - diplomat-tool dotnet {{dotnet_generated_path}} -l {{dotnet_diplomat_config}} + diplomat-tool dotnet {{dotnet_generated_path}} -e src/lib.rs -c {{dotnet_diplomat_config}} @echo ">> .NET wrapper generated at {{dotnet_generated_path}}" # FIXME: js bindings not yet ready diff --git a/ffi/src/argon2.rs b/ffi/src/argon2.rs index 14063d68..080e7745 100644 --- a/ffi/src/argon2.rs +++ b/ffi/src/argon2.rs @@ -1,9 +1,9 @@ #[diplomat::bridge] pub mod ffi { use crate::error::ffi::PickyError; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct Argon2Params { m_cost: u32, t_cost: u32, @@ -43,7 +43,6 @@ pub mod ffi { } } - #[derive(Clone, Copy)] pub enum Argon2Algorithm { Argon2d, Argon2i, @@ -73,7 +72,7 @@ pub mod ffi { Ok(Box::new(Self(argon2))) } - pub fn hash_password(&self, password: &str, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn hash_password(&self, password: &str, writeable: &mut DiplomatWrite) -> Result<(), Box> { use argon2::PasswordHasher as _; use argon2::password_hash::phc::Salt; use rand::rngs::{StdRng, SysRng}; diff --git a/ffi/src/error.rs b/ffi/src/error.rs index f8948687..ad6aa3b9 100644 --- a/ffi/src/error.rs +++ b/ffi/src/error.rs @@ -210,11 +210,10 @@ struct PickyErrorInner { #[diplomat::bridge] pub mod ffi { - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use std::fmt::Write as _; /// Kind associated to a Picky Error - #[derive(Clone, Copy)] pub enum PickyErrorKind { /// Generic Picky error Generic, @@ -234,7 +233,7 @@ pub mod ffi { impl PickyError { /// Returns the error as a string. - pub fn to_display(&self, writeable: &mut DiplomatWriteable) { + pub fn to_display(&self, writeable: &mut DiplomatWrite) { let _ = write!(writeable, "{}", self.0.repr); writeable.flush(); } diff --git a/ffi/src/jwt.rs b/ffi/src/jwt.rs index 851c9369..b5b755e2 100644 --- a/ffi/src/jwt.rs +++ b/ffi/src/jwt.rs @@ -57,12 +57,11 @@ pub(crate) struct SigBuilderInner { pub mod ffi { use crate::error::ffi::PickyError; use crate::key::ffi::{PrivateKey, PublicKey}; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use picky::jose::jwt; use std::fmt::Write as _; /// `alg` header parameter values for JWS - #[derive(Clone, Copy)] pub enum JwsAlg { /// RSASSA-PKCS-v1_5 using SHA-256 RS256, @@ -111,7 +110,7 @@ pub mod ffi { /// Returns the content type. // TODO: support for optional string in return position - pub fn get_content_type(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_content_type(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { write!(writeable, "{}", self.0.header.cty.as_deref().unwrap_or(""))?; writeable.flush(); Ok(()) @@ -119,14 +118,14 @@ pub mod ffi { /// Returns the key ID. // TODO: support for optional string in return position - pub fn get_kid(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_kid(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { write!(writeable, "{}", self.0.header.kid.as_deref().unwrap_or(""))?; writeable.flush(); Ok(()) } /// Returns the header as a JSON encoded payload. - pub fn get_header(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_header(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { let header = serde_json::to_string(&self.0.header)?; write!(writeable, "{header}")?; writeable.flush(); @@ -134,7 +133,7 @@ pub mod ffi { } /// Returns the claims as a JSON encoded payload. - pub fn get_claims(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_claims(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { let claims = serde_json::to_string(&self.0.state.claims)?; write!(writeable, "{claims}")?; writeable.flush(); @@ -161,7 +160,7 @@ pub mod ffi { } /// Encode using the given private key and returns the compact representation of this token. - pub fn encode(&self, key: &PrivateKey, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn encode(&self, key: &PrivateKey, writeable: &mut DiplomatWrite) -> Result<(), Box> { let encoded = self.0.clone().encode(&key.0)?; write!(writeable, "{encoded}")?; writeable.flush(); @@ -169,7 +168,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct JwtSigBuilder(pub(crate) super::SigBuilderInner); impl JwtSigBuilder { diff --git a/ffi/src/key.rs b/ffi/src/key.rs index 5aa2a9a7..630b5b47 100644 --- a/ffi/src/key.rs +++ b/ffi/src/key.rs @@ -68,7 +68,6 @@ pub mod ffi { use crate::pem::ffi::Pem; /// Known elliptic curve name used for ECDSA arithmetic operations - #[derive(Clone, Copy)] pub enum EcCurve { /// NIST P-256 NistP256, @@ -79,7 +78,6 @@ pub mod ffi { } /// Known Edwards curve-based algorithm name - #[derive(Clone, Copy)] pub enum EdAlgorithm { /// Ed25519 signing algorithm Ed25519, @@ -88,7 +86,6 @@ pub mod ffi { } /// Known key kinds - #[derive(Clone, Copy)] pub enum KeyKind { /// RSA (Rivest–Shamir–Adleman) Rsa, diff --git a/ffi/src/pem.rs b/ffi/src/pem.rs index e03c3451..c9fa666b 100644 --- a/ffi/src/pem.rs +++ b/ffi/src/pem.rs @@ -1,7 +1,7 @@ #[diplomat::bridge] pub mod ffi { use crate::error::ffi::PickyError; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use std::fmt::Write as _; use std::io::Write as _; @@ -48,14 +48,14 @@ pub mod ffi { } /// Returns the label of this PEM object. - pub fn get_label(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_label(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { write!(writeable, "{}", self.0.label())?; writeable.flush(); Ok(()) } /// Returns the string representation of this PEM object. - pub fn to_repr(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_repr(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { write!(writeable, "{}", self.0)?; writeable.flush(); Ok(()) diff --git a/ffi/src/pkcs12.rs b/ffi/src/pkcs12.rs index ff6776ae..7a7f8298 100644 --- a/ffi/src/pkcs12.rs +++ b/ffi/src/pkcs12.rs @@ -6,9 +6,8 @@ pub mod ffi { use crate::error::ffi::PickyError; use crate::key::ffi::PrivateKey; use crate::x509::ffi::Cert; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use picky::pkcs12; - use picky::pkcs12::Pkcs12Error; use picky_asn1::restricted_string::BmpString; use std::str::FromStr; use std::sync::{Arc, Mutex}; @@ -81,7 +80,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct Pkcs12ParsingParams(pub(crate) pkcs12::Pkcs12ParsingParams); impl Pkcs12ParsingParams { @@ -115,13 +114,13 @@ pub mod ffi { pub struct Pkcs12CryptoContext(pub(crate) Arc>); impl Pkcs12CryptoContext { - pub fn with_password(password: &str) -> Result, Pkcs12Error> { + pub fn with_password(password: &str) -> Result, Box> { Ok(Box::new(Self(Arc::new(Mutex::new( pkcs12::Pkcs12CryptoContext::new_with_password(password)?, ))))) } - pub fn no_password() -> Result, Pkcs12Error> { + pub fn no_password() -> Result, Box> { Ok(Box::new(Self(Arc::new(Mutex::new( pkcs12::Pkcs12CryptoContext::new_without_password()?, ))))) @@ -160,7 +159,7 @@ pub mod ffi { } } - pub fn get_friendly_name(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_friendly_name(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { use std::fmt::Write as _; if let pkcs12::Pkcs12AttributeKind::FriendlyName(name) = self.0.kind() { @@ -174,7 +173,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct Pkcs12AttributeIterator(pub(crate) Box>); impl Pkcs12AttributeIterator { @@ -191,7 +190,7 @@ pub mod ffi { } /// PFX safe bag, the polymorphic container for all the data in a PKCS12 archive. - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct SafeBag(pub(crate) pkcs12::SafeBag); impl SafeBag { @@ -294,7 +293,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct SafeBagIterator(pub(crate) Box>); impl SafeBagIterator { @@ -304,7 +303,7 @@ pub mod ffi { } /// PFX (PKCS12 archive) builder. - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct PfxBuilder { safe_bags_acc: Vec, safe_contents: Vec, diff --git a/ffi/src/putty.rs b/ffi/src/putty.rs index 0c3c60ce..cdea41f4 100644 --- a/ffi/src/putty.rs +++ b/ffi/src/putty.rs @@ -70,7 +70,7 @@ pub mod ffi { use crate::key::ffi::{EcCurve, PrivateKey, PublicKey}; use crate::ssh::ffi::{SshPrivateKey, SshPublicKey}; use crate::utils::ffi::VecU8; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use std::fmt::Write; /// PuTTY Private Key (PPK) version. @@ -137,7 +137,7 @@ pub mod ffi { } /// Encode PPK key file to a string. - pub fn to_repr(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_repr(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { writeable.write_str(&self.0.to_string()?)?; writeable.flush(); Ok(()) @@ -198,7 +198,7 @@ pub mod ffi { } /// Get the PPK key file comment. - pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_comment(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { writeable.write_str(self.0.comment())?; writeable.flush(); Ok(()) @@ -272,7 +272,7 @@ pub mod ffi { } /// Get the comment of the public key. - pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_comment(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { writeable.write_str(self.0.comment())?; writeable.flush(); Ok(()) @@ -285,7 +285,7 @@ pub mod ffi { } /// Converts the public key to a string (PuTTY format). - pub fn to_repr(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_repr(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { writeable.write_str(&self.0.to_string())?; writeable.flush(); Ok(()) @@ -347,7 +347,7 @@ pub mod ffi { /// PPK encryption configuration builder. /// /// Could be constructed via `PuttyPpkEncryptionConfig::builder()`. - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct PuttyPpkEncryptionConfigBuilder(picky::putty::PpkEncryptionConfigBuilder); impl PuttyPpkEncryptionConfigBuilder { diff --git a/ffi/src/ssh.rs b/ffi/src/ssh.rs index f06e0089..ba317696 100644 --- a/ffi/src/ssh.rs +++ b/ffi/src/ssh.rs @@ -59,7 +59,7 @@ pub mod ffi { use crate::pem::ffi::Pem; use crate::signature::ffi::SignatureAlgorithm; use crate::utils::ffi::VecU8; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use picky::ssh; use std::borrow::ToOwned; use std::fmt::Write as _; @@ -81,14 +81,14 @@ pub mod ffi { /// It is generally represented as: /// "(algorithm) (der for the key) (comment)" /// where (comment) is usually an email address. - pub fn to_repr(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_repr(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { let repr = self.0.to_string()?; writeable.write_str(&repr)?; writeable.flush(); Ok(()) } - pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_comment(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { writeable.write_str(&self.0.comment)?; writeable.flush(); Ok(()) @@ -221,20 +221,20 @@ pub mod ffi { } /// Returns the SSH Private Key string representation. - pub fn to_repr(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_repr(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { let repr = self.0.to_string()?; writeable.write_str(&repr)?; writeable.flush(); Ok(()) } - pub fn get_cipher_name(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_cipher_name(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { writeable.write_str(&self.0.cipher_name)?; writeable.flush(); Ok(()) } - pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_comment(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { writeable.write_str(&self.0.comment)?; writeable.flush(); Ok(()) @@ -346,7 +346,7 @@ pub mod ffi { } /// Returns the SSH Certificate string representation. - pub fn to_repr(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_repr(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { let repr = self.0.to_string()?; writeable.write_str(&repr)?; writeable.flush(); @@ -377,13 +377,13 @@ pub mod ffi { Box::new(SshPublicKey(self.0.signature_key.clone())) } - pub fn get_key_id(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_key_id(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { writeable.write_str(&self.0.key_id)?; writeable.flush(); Ok(()) } - pub fn get_comment(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_comment(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { writeable.write_str(&self.0.comment)?; writeable.flush(); Ok(()) diff --git a/ffi/src/utils.rs b/ffi/src/utils.rs index a565a267..d29f5d9c 100644 --- a/ffi/src/utils.rs +++ b/ffi/src/utils.rs @@ -2,7 +2,7 @@ use self::ffi::VecU8; #[diplomat::bridge] pub mod ffi { - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use crate::error::ffi::PickyError; use std::fmt::Write; @@ -33,13 +33,13 @@ pub mod ffi { pub struct BufferTooSmallError; impl BufferTooSmallError { - pub fn to_display(&self, writeable: &mut DiplomatWriteable) { + pub fn to_display(&self, writeable: &mut DiplomatWrite) { let _ = write!(writeable, "Buffer too small"); writeable.flush(); } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct VecU8Iterator(pub Vec); impl VecU8Iterator { @@ -48,11 +48,11 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct StringIterator(pub Box>); impl StringIterator { - pub fn next(&mut self, writable: &mut diplomat_runtime::DiplomatWriteable) -> Result<(), Box> { + pub fn next(&mut self, writable: &mut diplomat_runtime::DiplomatWrite) -> Result<(), Box> { let next = self.0.next(); if let Some(next) = next { let _ = write!(writable, "{next}"); @@ -64,7 +64,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct StringNestedIterator(pub Vec); impl StringNestedIterator { diff --git a/ffi/src/x509/algorithm_identifier.rs b/ffi/src/x509/algorithm_identifier.rs index dea870ae..d8567416 100644 --- a/ffi/src/x509/algorithm_identifier.rs +++ b/ffi/src/x509/algorithm_identifier.rs @@ -3,7 +3,7 @@ #[diplomat::bridge] pub mod ffi { use crate::error::ffi::PickyError; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use std::fmt::Write; #[diplomat::opaque] @@ -16,7 +16,7 @@ pub mod ffi { .is_a(picky::oid::ObjectIdentifier::try_from(other).map_err(|_| "invalid OID")?)) } - pub fn get_oid(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_oid(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let string: String = self.0.oid().into(); write!(writable, "{string}")?; Ok(()) @@ -39,7 +39,7 @@ pub mod ffi { RsassaPss, } - impl AlgorithmIdentifierParameters<'_> { + impl<'a> AlgorithmIdentifierParameters<'a> { pub fn get_type(&self) -> AlgorithmIdentifierParametersType { match self.0 { picky_asn1_x509::AlgorithmIdentifierParameters::None => AlgorithmIdentifierParametersType::None, @@ -126,7 +126,7 @@ pub mod ffi { #[diplomat::opaque] pub struct AesAuthEncParams(pub picky_asn1_x509::AesAuthEncParams); - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct AlgorithmIdentifierIterator(pub Vec); impl AlgorithmIdentifierIterator { diff --git a/ffi/src/x509/attribute.rs b/ffi/src/x509/attribute.rs index 9d1190cf..6b6e2948 100644 --- a/ffi/src/x509/attribute.rs +++ b/ffi/src/x509/attribute.rs @@ -7,14 +7,14 @@ pub mod ffi { use crate::x509::singer_info::ffi::{CmsVersion, SignerInfo, SignerInfoIterator}; use crate::x509::string::ffi::DirectoryString; use crate::x509::time::ffi::{Time, UTCTime, UTCTimeIterator}; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use std::fmt::Write; #[diplomat::opaque] pub struct Attribute(pub picky_asn1_x509::Attribute); impl Attribute { - pub fn get_type(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_type(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let oid: String = self.0.ty.0.clone().into(); write!(writable, "{oid}")?; Ok(()) @@ -25,7 +25,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct AttributeIterator(pub Vec); impl AttributeIterator { @@ -173,7 +173,7 @@ pub mod ffi { } } - pub fn get_as_string(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_as_string(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { match &self.0 { picky_asn1_x509::pkcs7::content_info::SpcString::Unicode(unicode) => { write!(writable, "{}", unicode.0.0.0)?; @@ -258,7 +258,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct SpcSpOpusInfoIterator(pub Vec); impl SpcSpOpusInfoIterator { @@ -270,7 +270,7 @@ pub mod ffi { //==================================================================== // AttributeTypeAndValue - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct AttributeTypeAndValueIterator(pub Vec); impl AttributeTypeAndValueIterator { @@ -279,7 +279,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct AttributeTypeAndValueNestedIterator(pub Vec); impl AttributeTypeAndValueNestedIterator { @@ -292,7 +292,7 @@ pub mod ffi { pub struct AttributeTypeAndValue(pub picky_asn1_x509::attribute_type_and_value::AttributeTypeAndValue); impl AttributeTypeAndValue { - pub fn get_type_id(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_type_id(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let oid: String = self.0.ty.0.clone().into(); write!(writable, "{oid}")?; Ok(()) @@ -494,7 +494,7 @@ pub mod ffi { pub struct UnsignedAttribute(pub picky_asn1_x509::signer_info::UnsignedAttribute); impl UnsignedAttribute { - pub fn get_type(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_type(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let oid: String = self.0.ty.0.clone().into(); write!(writable, "{oid}")?; Ok(()) @@ -505,7 +505,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct UnsignedAttributeIterator(pub Vec); impl UnsignedAttributeIterator { @@ -554,7 +554,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct MsCounterSignIterator(pub Vec); impl MsCounterSignIterator { @@ -567,7 +567,7 @@ pub mod ffi { pub struct MsCounterSign(picky_asn1_x509::Pkcs7Certificate); impl MsCounterSign { - pub fn get_oid(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_oid(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let oid_string: String = self.0.oid.0.clone().into(); write!(writable, "{oid_string}")?; Ok(()) @@ -578,7 +578,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct SignedData(pub picky_asn1_x509::pkcs7::signed_data::SignedData); impl SignedData { @@ -617,14 +617,14 @@ pub mod ffi { pub struct EncapsulatedContentInfo(pub picky_asn1_x509::content_info::EncapsulatedContentInfo); impl EncapsulatedContentInfo { - pub fn content_type(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn content_type(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let oid: String = self.0.content_type.0.clone().into(); write!(writable, "{oid}")?; Ok(()) } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct CertificateChoicesIterator(pub picky_asn1_x509::signed_data::CertificateSet); impl CertificateChoicesIterator { @@ -661,7 +661,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct RevocationInfoChoiceIterator(pub picky_asn1_x509::crls::RevocationInfoChoices); impl RevocationInfoChoiceIterator { @@ -717,7 +717,7 @@ pub mod ffi { Box::new(AlgorithmIdentifier(self.0.signature.clone())) } - pub fn get_issuer(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_issuer(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let name_string = format!("{}", self.0.issuer); write!(writable, "{name_string}")?; Ok(()) @@ -788,7 +788,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct RevokedCertificateIterator(pub Vec); impl RevokedCertificateIterator { diff --git a/ffi/src/x509/authenticode.rs b/ffi/src/x509/authenticode.rs index 2ae830e2..4e8de293 100644 --- a/ffi/src/x509/authenticode.rs +++ b/ffi/src/x509/authenticode.rs @@ -15,7 +15,7 @@ pub mod ffi { use crate::x509::ffi::{Cert, CertIterator}; use crate::x509::name::ffi::DirectoryNameIterator; - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct AuthenticodeSignature(pub picky::x509::pkcs7::authenticode::AuthenticodeSignature); #[diplomat::enum_convert(picky_asn1_x509::ShaVariant)] @@ -42,7 +42,7 @@ pub mod ffi { file_hash: &VecU8, hash_algorithm: ShaVariant, private_key: &PrivateKey, - program_name: Option>, + program_name: Option<&RsString>, ) -> Result, Box> { let inner = picky::x509::pkcs7::authenticode::AuthenticodeSignature::new( &pkcs7.0, @@ -97,7 +97,7 @@ pub mod ffi { Ok(Box::new(Cert(cert.clone()))) } - pub fn authenticode_verifier(&self) -> Box> { + pub fn authenticode_verifier<'a>(&'a self) -> Box> { let verifier = self.0.authenticode_verifier(); Box::new(AuthenticodeValidator::new(verifier)) } @@ -127,7 +127,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct AuthenticodeValidator<'a> { pub inner: picky::x509::pkcs7::authenticode::AuthenticodeValidator<'a>, //'exclude_cert_authorities' method down there a few lines takes a reference to a Vec, @@ -197,7 +197,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct AuthenticodeTimestamper(pub picky::x509::pkcs7::timestamp::http_timestamp::AuthenticodeTimestamper); impl AuthenticodeTimestamper { diff --git a/ffi/src/x509/extension.rs b/ffi/src/x509/extension.rs index 851beba9..525856e9 100644 --- a/ffi/src/x509/extension.rs +++ b/ffi/src/x509/extension.rs @@ -6,14 +6,14 @@ pub mod ffi { use crate::error::ffi::PickyError; use crate::utils::ffi::VecU8; use crate::x509::name::ffi::{GeneralName, GeneralNameIterator}; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use std::fmt::Write; #[diplomat::opaque] pub struct Extension(pub picky_asn1_x509::extension::Extension); impl Extension { - pub fn get_extn_id(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_extn_id(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let oid: String = self.0.extn_id().0.clone().into(); write!(writable, "{oid}")?; Ok(()) @@ -29,7 +29,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct ExtensionIterator(pub Vec); impl ExtensionIterator { @@ -155,11 +155,11 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct OidIterator(pub Vec); impl OidIterator { - pub fn next(&mut self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn next(&mut self, writable: &mut DiplomatWrite) -> Result<(), Box> { let oid = self.0.pop().ok_or("no more OIDs")?; write!(writable, "{oid}")?; Ok(()) diff --git a/ffi/src/x509/mod.rs b/ffi/src/x509/mod.rs index a6f40556..ec6f97f0 100644 --- a/ffi/src/x509/mod.rs +++ b/ffi/src/x509/mod.rs @@ -47,7 +47,7 @@ pub mod ffi { use std::cell::RefCell; use std::fmt::Write; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use picky::x509::certificate; use crate::date::ffi::UtcDate; @@ -104,7 +104,7 @@ pub mod ffi { Box::new(UtcDate(self.0.valid_not_after())) } - pub fn get_subject_key_id_hex(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_subject_key_id_hex(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { let ski = self.0.subject_key_identifier()?; let ski = hex::encode(ski); writeable.write_str(&ski)?; @@ -112,13 +112,13 @@ pub mod ffi { Ok(()) } - pub fn get_subject_name(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_subject_name(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { write!(writeable, "{}", self.0.subject_name())?; writeable.flush(); Ok(()) } - pub fn get_issuer_name(&self, writeable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_issuer_name(&self, writeable: &mut DiplomatWrite) -> Result<(), Box> { write!(writeable, "{}", self.0.issuer_name())?; writeable.flush(); Ok(()) @@ -225,7 +225,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct CertIterator(pub Vec); impl CertIterator { diff --git a/ffi/src/x509/name.rs b/ffi/src/x509/name.rs index 04a41471..7c632ebd 100644 --- a/ffi/src/x509/name.rs +++ b/ffi/src/x509/name.rs @@ -6,11 +6,11 @@ pub mod ffi { AttributeTypeAndValue, AttributeTypeAndValueIterator, AttributeTypeAndValueNestedIterator, }; use crate::x509::string::ffi::DirectoryString; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use std::fmt::Write; use std::str::FromStr; - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct GeneralNameIterator(pub Vec); impl GeneralNameIterator { @@ -56,7 +56,7 @@ pub mod ffi { } } - pub fn to_rfc822_name(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_rfc822_name(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { match &self.0 { picky_asn1_x509::name::GeneralName::Rfc822Name(rfc822_name) => { write!(writable, "{}", rfc822_name.0)?; @@ -66,7 +66,7 @@ pub mod ffi { } } - pub fn to_dns_name(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_dns_name(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { match &self.0 { picky_asn1_x509::name::GeneralName::DnsName(dns_name) => { write!(writable, "{}", dns_name.0)?; @@ -101,7 +101,7 @@ pub mod ffi { } } - pub fn to_uri(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_uri(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { match &self.0 { picky_asn1_x509::name::GeneralName::Uri(uri) => { write!(writable, "{}", uri.0)?; @@ -120,7 +120,7 @@ pub mod ffi { } } - pub fn to_registered_id(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn to_registered_id(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { match &self.0 { picky_asn1_x509::name::GeneralName::RegisteredId(registered_id) => { let oid: String = registered_id.0.clone().into(); @@ -152,7 +152,7 @@ pub mod ffi { pub struct OtherName(pub picky_asn1_x509::name::OtherName); impl OtherName { - pub fn get_type_id(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_type_id(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let oid: String = self.0.type_id.0.clone().into(); write!(writable, "{oid}")?; Ok(()) @@ -178,7 +178,7 @@ pub mod ffi { Phone, } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct DirectoryName(pub picky::x509::name::DirectoryName); #[diplomat::opaque] diff --git a/ffi/src/x509/singer_info.rs b/ffi/src/x509/singer_info.rs index af935276..0f0024b7 100644 --- a/ffi/src/x509/singer_info.rs +++ b/ffi/src/x509/singer_info.rs @@ -3,7 +3,7 @@ pub mod ffi { use crate::error::ffi::PickyError; use crate::x509::algorithm_identifier::ffi::AlgorithmIdentifier; use crate::x509::attribute::ffi::{Attribute, AttributeIterator, UnsignedAttribute, UnsignedAttributeIterator}; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use std::fmt::Write; #[diplomat::opaque] @@ -87,14 +87,14 @@ pub mod ffi { pub struct IssuerAndSerialNumber(pub picky_asn1_x509::signer_info::IssuerAndSerialNumber); impl IssuerAndSerialNumber { - pub fn get_issuer(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_issuer(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let name_string = format!("{}", self.0.issuer); write!(writable, "{name_string}")?; Ok(()) } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct SignerInfoIterator(pub Vec); impl SignerInfoIterator { diff --git a/ffi/src/x509/string.rs b/ffi/src/x509/string.rs index e458efa9..067b9aec 100644 --- a/ffi/src/x509/string.rs +++ b/ffi/src/x509/string.rs @@ -2,7 +2,7 @@ pub mod ffi { use crate::error::ffi::PickyError; use crate::utils::ffi::VecU8; - use diplomat_runtime::DiplomatWriteable; + use diplomat_runtime::DiplomatWrite; use std::fmt::Write; #[diplomat::opaque] @@ -25,7 +25,7 @@ pub mod ffi { } } - pub fn get_as_string(&self, writable: &mut DiplomatWriteable) -> Result<(), Box> { + pub fn get_as_string(&self, writable: &mut DiplomatWrite) -> Result<(), Box> { let string: String = self.0.clone().into(); write!(writable, "{string}")?; Ok(()) diff --git a/ffi/src/x509/time.rs b/ffi/src/x509/time.rs index 63044267..53be7e37 100644 --- a/ffi/src/x509/time.rs +++ b/ffi/src/x509/time.rs @@ -30,7 +30,7 @@ pub mod ffi { } } - #[diplomat::opaque] + #[diplomat::opaque_mut] pub struct UTCTimeIterator(pub Vec); impl UTCTimeIterator {