Merge pull request #139 from TheBlueMatt/main
[ldk-java] / c_sharp / src / org / ldk / structs / EntropySource.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * A trait that describes a source of entropy.
10  */
11 public class EntropySource : CommonBase {
12         internal readonly bindings.LDKEntropySource bindings_instance;
13         internal EntropySource(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
14         private EntropySource(bindings.LDKEntropySource arg) : base(bindings.LDKEntropySource_new(arg)) {
15                 this.ptrs_to.AddLast(arg);
16                 this.bindings_instance = arg;
17         }
18         ~EntropySource() {
19                 if (ptr != 0) { bindings.EntropySource_free(ptr); }
20         }
21
22         public interface EntropySourceInterface {
23                 /**
24                  * Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
25                  * different value each time it is called.
26                  */
27                 byte[] get_secure_random_bytes();
28         }
29         private class LDKEntropySourceHolder { internal EntropySource held; }
30         private class LDKEntropySourceImpl : bindings.LDKEntropySource {
31                 internal LDKEntropySourceImpl(EntropySourceInterface arg, LDKEntropySourceHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
32                 private EntropySourceInterface arg;
33                 private LDKEntropySourceHolder impl_holder;
34                 public byte[] get_secure_random_bytes() {
35                         byte[] ret = arg.get_secure_random_bytes();
36                                 GC.KeepAlive(arg);
37                         byte[] result = InternalUtils.check_arr_len(ret, 32);
38                         return result;
39                 }
40         }
41         public static EntropySource new_impl(EntropySourceInterface arg) {
42                 LDKEntropySourceHolder impl_holder = new LDKEntropySourceHolder();
43                 impl_holder.held = new EntropySource(new LDKEntropySourceImpl(arg, impl_holder));
44                 return impl_holder.held;
45         }
46         /**
47          * Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
48          * different value each time it is called.
49          */
50         public byte[] get_secure_random_bytes() {
51                 byte[] ret = bindings.EntropySource_get_secure_random_bytes(this.ptr);
52                 GC.KeepAlive(this);
53                 return ret;
54         }
55
56 }
57 } } }