6 namespace org { namespace ldk { namespace structs {
9 * A trait that describes a source of entropy.
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;
19 if (ptr != 0) { bindings.EntropySource_free(ptr); }
22 public interface EntropySourceInterface {
24 * Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
25 * different value each time it is called.
27 byte[] get_secure_random_bytes();
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();
37 byte[] result = InternalUtils.check_arr_len(ret, 32);
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;
47 * Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
48 * different value each time it is called.
50 public byte[] get_secure_random_bytes() {
51 byte[] ret = bindings.EntropySource_get_secure_random_bytes(this.ptr);