7 namespace org { namespace ldk { namespace structs {
11 /** An implementation of EntropySource */
12 public interface EntropySourceInterface {
13 /**Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
14 * different value each time it is called.
16 byte[] get_secure_random_bytes();
20 * A trait that describes a source of entropy.
22 public class EntropySource : CommonBase {
23 internal bindings.LDKEntropySource bindings_instance;
24 internal long instance_idx;
26 internal EntropySource(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
28 if (ptr != 0) { bindings.EntropySource_free(ptr); }
31 private class LDKEntropySourceHolder { internal EntropySource held; }
32 private class LDKEntropySourceImpl : bindings.LDKEntropySource {
33 internal LDKEntropySourceImpl(EntropySourceInterface arg, LDKEntropySourceHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
34 private EntropySourceInterface arg;
35 private LDKEntropySourceHolder impl_holder;
36 public long get_secure_random_bytes() {
37 byte[] ret = arg.get_secure_random_bytes();
39 long result = InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(ret, 32));
44 /** Creates a new instance of EntropySource from a given implementation */
45 public static EntropySource new_impl(EntropySourceInterface arg) {
46 LDKEntropySourceHolder impl_holder = new LDKEntropySourceHolder();
47 LDKEntropySourceImpl impl = new LDKEntropySourceImpl(arg, impl_holder);
48 long[] ptr_idx = bindings.LDKEntropySource_new(impl);
50 impl_holder.held = new EntropySource(null, ptr_idx[0]);
51 impl_holder.held.instance_idx = ptr_idx[1];
52 impl_holder.held.bindings_instance = impl;
53 return impl_holder.held;
57 * Gets a unique, cryptographically-secure, random 32-byte value. This method must return a
58 * different value each time it is called.
60 public byte[] get_secure_random_bytes() {
61 long ret = bindings.EntropySource_get_secure_random_bytes(this.ptr);
63 if (ret >= 0 && ret <= 4096) { return null; }
64 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);