1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * An implementation of [`EntropySource`] using ChaCha20.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class RandomBytes extends CommonBase {
16 RandomBytes(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.RandomBytes_free(ptr); }
24 * Creates a new instance using the given seed.
26 public static RandomBytes of(byte[] seed) {
27 long ret = bindings.RandomBytes_new(InternalUtils.check_arr_len(seed, 32));
28 Reference.reachabilityFence(seed);
29 if (ret >= 0 && ret <= 4096) { return null; }
30 org.ldk.structs.RandomBytes ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RandomBytes(null, ret); }
31 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
36 * Constructs a new EntropySource which calls the relevant methods on this_arg.
37 * This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
39 public EntropySource as_EntropySource() {
40 long ret = bindings.RandomBytes_as_EntropySource(this.ptr);
41 Reference.reachabilityFence(this);
42 if (ret >= 0 && ret <= 4096) { return null; }
43 EntropySource ret_hu_conv = new EntropySource(null, ret);
44 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };