X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FSha256.java;h=58497f1d44f8413c37bb248785adef558c2c513e;hb=1854b5cebef22ace9e9e4dd191f609818df9ce08;hp=76c110a7372691e2cf37777bdd9c8900dc4a99fc;hpb=ba1af51214a8ea2de62b84cd23b6145173c71752;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Sha256.java b/src/main/java/org/ldk/structs/Sha256.java index 76c110a7..58497f1d 100644 --- a/src/main/java/org/ldk/structs/Sha256.java +++ b/src/main/java/org/ldk/structs/Sha256.java @@ -4,6 +4,7 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; import javax.annotation.Nullable; @@ -19,14 +20,9 @@ public class Sha256 extends CommonBase { if (ptr != 0) { bindings.Sha256_free(ptr); } } - /** - * Checks if two Sha256s contain equal inner contents. - * This ignores pointers and is_owned flags and looks at the values in fields. - * Two objects with NULL inner values will be considered "equal" here. - */ - public boolean eq(Sha256 b) { - boolean ret = bindings.Sha256_eq(this.ptr, b == null ? 0 : b.ptr & ~1); - this.ptrs_to.add(b); + long clone_ptr() { + long ret = bindings.Sha256_clone_ptr(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -35,10 +31,40 @@ public class Sha256 extends CommonBase { */ public Sha256 clone() { long ret = bindings.Sha256_clone(this.ptr); - if (ret < 1024) { return null; } - Sha256 ret_hu_conv = new Sha256(null, ret); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + Sha256 ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Sha256(null, ret); } ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; } + /** + * Checks if two Sha256s contain equal inner contents. + */ + public long hash() { + long ret = bindings.Sha256_hash(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + @Override public int hashCode() { + return (int)this.hash(); + } + /** + * Checks if two Sha256s contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + * Two objects with NULL inner values will be considered "equal" here. + */ + public boolean eq(Sha256 b) { + boolean ret = bindings.Sha256_eq(this.ptr, b == null ? 0 : b.ptr & ~1); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + this.ptrs_to.add(b); + return ret; + } + + @Override public boolean equals(Object o) { + if (!(o instanceof Sha256)) return false; + return this.eq((Sha256)o); + } }